1From b197b1946a849d34917ae62e1dfed97cbfb33b54 Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Thu, 4 May 2023 18:09:19 +0800
4Subject: [PATCH 20/20] gl: x11: Allow disabling decorations for toplevel
5 window
6
7Tested on RK3588 evb with:
8GST_GL_X11_NO_DECORATIONS=1 \
9gst-launch-1.0 videotestsrc ! glimagesink render-rectangle='<100,200,300,400>'
10
11Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
12---
13 gst-libs/gst/gl/x11/gstglwindow_x11.c | 27 +++++++++++++++++++++++++++
14 1 file changed, 27 insertions(+)
15
16diff --git a/gst-libs/gst/gl/x11/gstglwindow_x11.c b/gst-libs/gst/gl/x11/gstglwindow_x11.c
17index 6d2293e..381565c 100644
18--- a/gst-libs/gst/gl/x11/gstglwindow_x11.c
19+++ b/gst-libs/gst/gl/x11/gstglwindow_x11.c
20@@ -69,6 +69,18 @@ struct _GstGLWindowX11Private
21 G_DEFINE_TYPE_WITH_PRIVATE (GstGLWindowX11, gst_gl_window_x11,
22     GST_TYPE_GL_WINDOW);
23
24+typedef struct
25+{
26+  unsigned long flags;
27+  unsigned long functions;
28+  unsigned long decorations;
29+  long input_mode;
30+  unsigned long status;
31+}
32+MotifWmHints, MwmHints;
33+
34+#define MWM_HINTS_DECORATIONS   (1L << 1)
35+
36 static guintptr gst_gl_window_x11_get_display (GstGLWindow * window);
37 guintptr gst_gl_window_x11_get_gl_context (GstGLWindow * window);
38 gboolean gst_gl_window_x11_activate (GstGLWindow * window, gboolean activate);
39@@ -236,6 +248,21 @@ gst_gl_window_x11_create_window (GstGLWindowX11 * window_x11)
40     XSetWMNormalHints (window_x11->device, window_x11->internal_win_id, &hints);
41   }
42
43+  /* Set decoration for toplevel window */
44+  Atom atom = XInternAtom (window_x11->device, "_MOTIF_WM_HINTS", True);
45+  if (!window_x11->parent_win && atom != None) {
46+    MotifWmHints hints;
47+    gboolean decorations = !g_getenv ("GST_GL_X11_NO_DECORATIONS");
48+    hints.flags |= MWM_HINTS_DECORATIONS;
49+    hints.decorations = decorations ? 1 << 0 : 0;
50+
51+    XChangeProperty (window_x11->device, window_x11->internal_win_id,
52+                     atom, atom, 32, PropModeReplace,
53+                     (guchar *) &hints, sizeof (MotifWmHints) / sizeof (long));
54+
55+    XSync (window_x11->device, FALSE);
56+  }
57+
58   gst_gl_window_x11_handle_events (GST_GL_WINDOW (window_x11),
59       window_x11->priv->handle_events);
60
61--
622.20.1
63
64