2

I'm writing a Gtk2 application that among other things needs to have Mplayer play a video into aGtkDrawingArea. From what I can tell, this is possible if one can find the XID of theGtkDrawingArea and pass this as a parameter to Mplayer. However, I'm using the code snippet below.

long videoID;                 
GtkWidget *videoWindow = NULL;


/* need be done only once on Namb2Client startup */
InitEGM( &egm );    

/* Init GTK+ */
gtk_init( &argc, &argv );

/* Create new GtkBuilder object */
builder = gtk_builder_new();

/* Load UI from file. If error occurs, report it and quit application. */
if( !gtk_builder_add_from_file( builder, "layout.xml", &error ) )
{
    g_warning( "%s", error->message );
    g_free( error );
    return( 1 );
}

/* Get main window pointer from UI */
window = GTK_WIDGET( gtk_builder_get_object( builder, "window1" ) );
gtk_window_position(GTK_WINDOW(window), (GtkWindowPosition)GTK_WIN_POS_CENTER);


MainWnd = GTK_WIDGET( gtk_builder_get_object( builder, "MainWnd" ) );

// Setup area for Mplayer video
videoWindow = gtk_drawing_area_new ();
gtk_widget_set_size_request (videoWindow, 640, 180);
gtk_fixed_put((GtkFixed *)MainWnd, videoWindow, 414, 24 );
gtk_widget_show( videoWindow );    
videoID = gdk_x11_drawable_get_xid( videoWindow );
g_printf("XID = %ld\n", videoID);

When I run the application I get the following error:

(egm:3872): Gdk-WARNING **: gdkdrawable-x11.c:952 drawable is not a pixmap or window
XID = 0

What is the proper method of obtaining the XID of a GtkDrawingArea? Any help would be greatly appreciated.

Chimera
  • 5,884
  • 7
  • 49
  • 81

1 Answers1

2

Found the problem. I needed to be sure to call gtk_widget_realize(). If this isn't done the widget is not fully created and not assigned an X11 XID.

// Setup area for Mplayer video
videoWindow = gtk_drawing_area_new ();
gtk_widget_set_size_request (videoWindow, 640, 180);
gtk_fixed_put((GtkFixed *)MainWnd, videoWindow, 414, 24 );
gtk_widget_realize( videoWindow );
gtk_widget_show( videoWindow );    
videoID = GDK_WINDOW_XWINDOW (GTK_WIDGET (videoWindow)->window);
g_printf("XID = %ld\n", videoID);
Chimera
  • 5,884
  • 7
  • 49
  • 81
  • 1
    Thanks for your answer, Chimera. Helped me. For Windows, `GDK_WINDOW_HWND(GTK_WIDGET(video_window)->window)` worked. – fapw Jan 27 '16 at 13:24
  • @fapw You are welcome. I'm glad I was able to provide something that was of help to others. – Chimera Jan 27 '16 at 16:22
  • Hello @Chimera. Could you tell me please, if it was successful to show video in gtk_drawing_area. I'm asking, because I have difficulties with that. Thanks. – fapw Jan 29 '16 at 07:38
  • @fapw Yes I was able to make it happen. I took the printed XID and supplied that as a command line parameter to mplayer and the video played inside the gtk_drawing_area. – Chimera Jan 29 '16 at 16:10
  • Thanks for your answer, @Chimera. It's good news for me. It seems my problem is something else. Continue digging. Have a nice day. – fapw Feb 01 '16 at 08:22
  • Could you guys please publish the working source code? I have a hard time reproducing it with the snippets only. :( – shevy Jan 30 '21 at 09:03
  • @shevy Sorry, I can't. I did this work for my employer whom I no longer work for. – Chimera Feb 01 '21 at 00:16