我正在编写一个Gtk2应用程序,除其他外,需要Mplayer
将视频播放到GtkDrawingArea
。据我所知,如果可以找到GtkDrawingArea
的XID并将其作为参数传递给Mplayer,这是可能的。但是,我正在使用下面的代码段。
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);
运行应用程序时出现以下错误:
(egm:3872): Gdk-WARNING **: gdkdrawable-x11.c:952 drawable is not a pixmap or window
XID = 0
获取GtkDrawingArea
的XID的正确方法是什么?任何帮助将不胜感激。
答案 0 :(得分:2)
发现问题。我需要一定要打电话给gtk_widget_realize()
。如果不这样做,则不会完全创建窗口小部件,也不会为其分配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);