diff --git a/gst-libs/gst/vaapi/gstvaapiwindow_x11.c b/gst-libs/gst/vaapi/gstvaapiwindow_x11.c index 865b11babe..217815cdaf 100644 --- a/gst-libs/gst/vaapi/gstvaapiwindow_x11.c +++ b/gst-libs/gst/vaapi/gstvaapiwindow_x11.c @@ -226,7 +226,7 @@ gst_vaapi_window_x11_create (GstVaapiWindow * window, guint * width, const GstVaapiDisplayClass *display_class; const GstVaapiWindowClass *window_class; XWindowAttributes wattr; - Atom atoms[2]; + Atom wm_delete, atoms[2]; gboolean ok; static const char *atom_names[2] = { @@ -269,8 +269,16 @@ gst_vaapi_window_x11_create (GstVaapiWindow * window, guint * width, priv->atom_NET_WM_STATE_FULLSCREEN = atoms[1]; xid = x11_create_window (dpy, *width, *height, vid, cmap); - if (xid) + if (xid) { + /* Tell the window manager we'd like delete client messages instead of + * being killed */ + wm_delete = XInternAtom (dpy, "WM_DELETE_WINDOW", True); + if (wm_delete != None) { + (void) XSetWMProtocols (dpy, xid, &wm_delete, 1); + } + XRaiseWindow (dpy, xid); + } GST_VAAPI_WINDOW_UNLOCK_DISPLAY (window); GST_DEBUG ("xid %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (xid)); diff --git a/gst/vaapi/gstvaapisink.c b/gst/vaapi/gstvaapisink.c index c19658332e..158ade9e03 100644 --- a/gst/vaapi/gstvaapisink.c +++ b/gst/vaapi/gstvaapisink.c @@ -439,6 +439,35 @@ gst_vaapisink_x11_handle_events (GstVaapiSink * sink) } if (do_expose) gst_vaapisink_video_overlay_expose (GST_VIDEO_OVERLAY (sink)); + + /* Handle Display events */ + for (;;) { + gst_vaapi_display_lock (display); + if (XPending (x11_dpy) == 0) { + gst_vaapi_display_unlock (display); + break; + } + XNextEvent (x11_dpy, &e); + gst_vaapi_display_unlock (display); + + switch (e.type) { + case ClientMessage:{ + Atom wm_delete; + + wm_delete = XInternAtom (x11_dpy, "WM_DELETE_WINDOW", False); + if (wm_delete == (Atom) e.xclient.data.l[0]) { + /* Handle window deletion by posting an error on the bus */ + GST_ELEMENT_ERROR (sink, RESOURCE, NOT_FOUND, + ("Output window was closed"), (NULL)); + return FALSE; + } + break; + } + default: + break; + } + } + } return TRUE; }