Frage

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.

War es hilfreich?

Lösung

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);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top