x11: Let apps specify a custom _NET_WM_WINDOW_TYPE. Fixes #5185.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 1185f42..514580f 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -1824,6 +1824,27 @@ extern "C" {
*/
#define SDL_HINT_AUDIO_INCLUDE_MONITORS "SDL_AUDIO_INCLUDE_MONITORS"
+/**
+ * \brief A variable that forces X11 windows to create as a custom type.
+ *
+ * This is currently only used for X11 and ignored elsewhere.
+ *
+ * During SDL_CreateWindow, SDL uses the _NET_WM_WINDOW_TYPE X11 property
+ * to report to the window manager the type of window it wants to create.
+ * This might be set to various things if SDL_WINDOW_TOOLTIP or
+ * SDL_WINDOW_POPUP_MENU, etc, were specified. For "normal" windows that
+ * haven't set a specific type, this hint can be used to specify a custom
+ * type. For example, a dock window might set this to
+ * "_NET_WM_WINDOW_TYPE_DOCK".
+ *
+ * If not set or set to "", this hint is ignored. This hint must be set
+ * before the SDL_CreateWindow() call that it is intended to affect.
+ *
+ * This hint is available since SDL 2.0.22. Before then, virtual devices are
+ * always ignored.
+ */
+#define SDL_HINT_X11_WINDOW_TYPE "SDL_X11_WINDOW_TYPE"
+
/**
* \brief An enumeration of hint priorities
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 89e9ebb..709f813 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -392,6 +392,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
long compositor = 1;
Atom _NET_WM_PID;
long fevent = 0;
+ const char *hint = NULL;
#if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_EGL
const char *forced_visual_id = SDL_GetHint(SDL_HINT_VIDEO_X11_WINDOW_VISUALID);
@@ -591,6 +592,8 @@ X11_CreateWindow(_THIS, SDL_Window * window)
wintype_name = "_NET_WM_WINDOW_TYPE_TOOLTIP";
} else if (window->flags & SDL_WINDOW_POPUP_MENU) {
wintype_name = "_NET_WM_WINDOW_TYPE_POPUP_MENU";
+ } else if ( ((hint = SDL_GetHint(SDL_HINT_X11_WINDOW_TYPE)) != NULL) && *hint ) {
+ wintype_name = hint;
} else {
wintype_name = "_NET_WM_WINDOW_TYPE_NORMAL";
compositor = 1; /* disable compositing for "normal" windows */