Re: Can I mix Xlib and Gtk+ in one app?

>I'm interested in this topic too. It would be nice to write some modules
>which aren't specified as gtk widgets or other gtk objects. Assume you
>write an application with a proprietary internet protocol. You surely want
>to open this protocol to any toolkit. So we need a mixed event handling,
>one for our module and one for lets say a gtk application.

>X isn't far away from such a network event handler since you can even
>select on the filedescriptor to the X-Server in Xlib.

you can do the exact same thing in GTK+. gtk_input_add(), which is an
easy to use wrapper around g_input_add(), does just what you want. you
just register a callback to handle i/o conditions on the fd you are

all toolkits allow this - its a basic requirement for an event-driven
programming model unless it requires you also use threads, which most
people would be very unhappy about.

>Aren't there functions in gtk which, like XNextEvent select exactly one event

sure, but gtk will (often) throw away events for windows it doesn't
know about.

>from the gtk event loop and dispatch it ? Of course we have to care about gtk
>not catching our events. Shouldn't that be easy to distinguish by opening the
>DISPLAY two times ? That may not be very, optimized but shouldn't it work ?

AFAIK, no toolkit in existence allows this. they all use globals for
the Xlib connection. its very hard to write them without a "toolkit_t"
pointer being passed around otherwise.

>So lets try it:
>	init gtk ... create some widgets ...
>	init Xlib Display ... create some windows ...
>	while ( !exit_application )
>	{
>		Try first event source ... handle and dispatch events
>		Try second event source ... and so on ...
>	}
>Why shouldn't this work ? The two parts don't hurt each other ?

you could try that but thats not really what you asked about, as i
read it. it might work, sure. but why bother?

i don't see *any* benefit from using xlib. gdk wraps almost every call
in xlib, and these days, makes them portable to non-X based systems as


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