I was trying to port GUI integration tutorial of gstreamer(https://gstreamer.freedesktop.org/documentation/tutorials/basic/toolkit-integration.html?gi-language=c) from gtk3 to gtk4. I am hitting an issue with getting the X window belonging to GtkDrawingArea. In gtk3, to get the XID and to pass it to GstVideoOverlay following approach is used:
static void realize_cb (GtkWidget *widget, CustomData *data) {
GdkWindow *window = gtk_widget_get_window (widget);
guintptr window_handle;
if (!gdk_window_ensure_native (window))
g_error ("Couldn't create native window needed for GstVideoOverlay!");
/* Retrieve window handler from GDK */
window_handle = GDK_WINDOW_XID (window);
/* Pass it to playbin, which implements VideoOverlay and will forward it to the video sink */
gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (data->playbin), window_handle);
}
I'm not able to figure out how to do the same in Gtk4. Since Gtk4 is using Wayland terminology, the function in gdk to get XID is GDK_SURFACE_XID()
which takes a GdkSurface* as an argument and there is no direct function in GtkWidget to get the pointer to the GdkSurface similar to gtk_widget_get_window
in Gtk3.
I tried getting GtkNative using gtk_widget_get_native
of the GtkDrawingArea and getting GdkSurface attached to it but that is returning the surface of the GtkWindow.
I am looking for a way to get XID to pass to gst_video_overlay_set_window_handle
to be able to play video in the widget.
I am fairly new to both Gtk and Gstreamer so apologies for gaps in my understanding.