GTK with libdispatch (GCD) on Linux and X11



I have been investigating using GTK windows and widgets in a program
whose main loop is controlled by libdispatch.  The target is X11 on
Linux.  GTK is used only for the GUI.  (Other glib event sources are
not used in this application.  Networking is done using libdispatch.)

I've read through the gtk source and the mainloop and believe that
updating the GUI may be as simple as registering the following block
callback for the main queue, where the file descriptor watched is the
X11 socket.

I am wondering if someone that is more familiar with the intracies of
the glib main loop could comment on this technique.  What have I
missed? 


    // and create a dispatch source for it
    dispatch_source_t dsource = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ,
                                                       fd,
                                                       0,
                                                       dispatch_get_main_queue());
    dispatch_source_set_event_handler(dsource, ^{

        while (g_main_context_pending(gtkgcd_context)) {
          g_main_context_iteration(gtkgcd_context, FALSE);
        }

    });

To illustrate the ideas, I've created an example program on put it on
github.  In it, a logging window is created.  It has a "clear"
button.  Two async timers write to the window.  Pressing the "clear"
button erases its contents. 

https://github.com/integratron/gtkgcd1

The guts of the GTK/GCD integration is in this file

https://github.com/integratron/gtkgcd1/blob/master/gtkgcd.c

It combines GTK with libdispatch using Objc2 and clang on Linux.

Will this be safe going forward?  Is there a better way to find the
X11 file descriptor?

Thanks for any insights!


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