Page 1 of 1

GtkWindow from wxWindow GetHandle

Posted: Tue Jan 11, 2011 11:23 pm
by tt3
I'm using ubuntu hardy with wxWidgets 2.8. I need to get XID from a window for image stream display, so I used the following:

wxWindow* window_;
...
GtkWidget* widget = window_->GetHandle();
XID xid = GDK_WINDOW_XWINDOW(widget->window);

This does not give any error, but no image gets shown. I tried using paint event to draw the images, and it worked. So I wonder, for the XID approach to work, is there some specific settings that I missed, or procedures to be taken for creating a window? And is wxWindow the right class?

The example codes I have (to use the XID) was in gtk, and it worked fine:

GtkWidget* drawing_area = gtk_drawing_area_new ();
...
XID xid = GDK_WINDOW_XWINDOW(drawing_area->window);

So I got another question that is there a way to get a GtkWidget pointer equivilant to the result of gtk_drawing_area_new(), out of either wxWindow or any other wxWidget class?

Thanks

Posted: Wed Jan 12, 2011 7:41 am
by upCASE
Hi!
I had the same problems when trying to tell VLC to use a wxWidgets control for video output.

Here's how I managed that for 2.8:

Code: Select all

GdkWindow* win = GTK_PIZZA(output->m_wxwindow)->bin_window;
vlc_media_player_set_xwindow (m_media_player_inst,GDK_WINDOW_XID(win));
For 2.9 I had to use a different way, as the internal window handling changed:

Code: Select all

GtkWidget* widget = output->GetHandle();
gtk_widget_realize( widget );   // Mandatory. Otherwise it segfaults.
Display* display = GDK_WINDOW_XDISPLAY( widget->window );
Window wid = GDK_WINDOW_XWINDOW( widget->window );   // Window is a typedef for XID, which is a typedef for unsigned int
vlc_media_player_set_xwindow (m_media_player_inst, wid);
In both cases "output" is the widget (in my case a panel) I use for displaying the video output.
I'm pretty sure that the 2.9 could be simplified, but I was tired of digging deeper into that, as this already took me some time to find out.

Hope this helps!

Posted: Wed Jan 12, 2011 11:23 pm
by tt3
Thanks very much. It worked.