Handling Qt/KDE widgets within Gtk+ message loop



Hello gtk-list.
I'm hacking on Gparts library, the aim at the moment is to embed KDE's
KParts components (such as khtml and kpdf) into Gtk+ programs. I've got
some results so far, though have problems with stability which were
likely to raise when you are trying to mix two message loops.

I use XEmbed widgets to mix Gtk+ and Qt i. e. GtkSocket and
QtXEmbedClient. At the moment I simply get X connection file descriptor
from, say, Gtk+ and insert it as an additional file descriptor into Qt's
message loop. (or I take Qt's X connection fd and add as a GSource into
gtk+ message loop - both works). When 'foreign' fd is selected, the
following code does its job:
        while (gtk_events_pending ())
                gtk_main_iteration ();

There is a sample tarball with gparts and two examples - khtml and kpdf
embedding at http://erdizz.narod.ru/gparts_example.tar.gz

The first impression is that everything works just fine. But in some
cases mixed programs hang.

One case is if I create a KParts::MainWindow, merge KParts UI (menus and
toolbars) into it and embed it all into a GtkSocket. Then if I click on
a menubar and then move mouse onto a submenu item, program hangs. Even
more, the whole X becomes locked, only mouse moves and the only way to
get out is pressing ctrl+alt+f1 and killing my application. One time,
though, X kept responsiveness and I could Ctrl+C my program and get a
backtrace from gdb, it said that execution was somewhere in KDE's
tooltip handling code and I think it is somehow related to timeouts
which are likely to be broken with my message loop mixing technique.

The other case when it hangs is if I open kpdf's part settings dialog,
press on some icon at the left of it and the press the 'OK' button. This
dialog differs form others only in that it saves configuration on close,
but maybe I miss something.

There should be other cases, probably even more weird than these. And
things look surprisingly similar with Qt main loop as a 'master', glib
'slave', and with glib main loop as a 'master', Qt 'slave'.

Given that I'd like to ask:
1) Should I deeply mix Qt and Gtk+ main loops so that all of the
functionality is implemented? e.g. gtk's 'init' and 'quit' functions
that are queued and executed in gtk_main etc. Are things such as timeout
handling and ability to insert additional GSources critical for plain
Gtk+ programs?
2) If the whole X Window freezes, couldn't it be an XEmbed
implementation issue?
3) I saw strange 'Bad Window' errors in X console at one moment (then
they disappeared and I cannot reproduce it). So could it be some
synchronization isuue? Could Xlib be confused if I use two different
toolkits from the same process/thread?
4) It is theoretically possible to make things work, is it?

I've briefly described the reasons why I'm trying to do this in a
dedicated blog at http://gparts.blogspot.com, going to ask what people
think about it at desktop-devel-list, though I don't feel I can speak
loud until I get a working prototype (at least the one that doesn't
hang).

Best regards, Dmitry




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]