Re: Xwindow as GTK Widget




jlarsen@PIRL.LPL.Arizona.EDU (Jeffrey Larsen) writes:

> I'm trying to use GTK to wrap our project's real-time asteroid
> detection code.  One problem I can't solve though...
> 
> Our incoming pixel data is displayed on an X window using an
> astronomical graphics subroutine library I don't want to mess 
> with.  I would like the X window to be responsive to GTK events 
> (in particular mouse clicks).  I have the Xdisplay and Xwindow
> ID's for the X window but can't see how to turn this into a usable
> GTK widget.  How can one do this?
> 
> I've examined gdkx.h and I'm still in the dark.  Help?
> 
> Regards,
> 
> Jeff

It isn't an easy task, and probably can't be done exactly with
writing a small amount of fairly low-level code.

It, to some extent, depends on exactly what the graphics library
needs to do. If the graphics library only needs to draw into
an X window, and you can control which X window it draws into,
then the easy thing to do, is to have it draw into a 
GdkDrawingArea. (You can get the X window ID with 
GDK_WINDOW_XWINDOW (drawing_area->window), after the window
is realized)

If, however, library is doing more complicated interactions with
X, then it is probably best to give the library its on
separate connect to X. (Display *), either as Jay described, or
possibly in a separate process.

Then, here's how I would set things up:

 - I would create a new "Overlay" widget, which is a container
   with one child; this widget covers the child window with
   a InputOnly window so that it traps all user input to the
   child.

   This widget could be derived from GtkEventBox - it would
   just involve overriding the realize routine.

 - Then, as a child of this widget, I would use a Socket widget
   from the Plug/Socket widgets.

   ftp://ftp.gtk.org/pub/users/otaylor/plugsocket-0.3.tar.gz

   Then you can just call 

    gtk_socket_steal (GTK_SOCKET(socket), window_id);

The first step is probably a bit scary sounding, but actually
should be pretty straightforward. Let me know if you need some
help figuring it out.

Regards,
                                        Owen



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