我正在编写一个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

获得aGtkDrawingArea氧化物的正确方法是什么?任何帮助都将不胜感激。

最佳答案

发现了问题。我需要确保给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);

关于c - 如何获取Gtk2 GtkDrawingArea的XID嵌入Mplayer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10403316/

10-09 08:58