x11: add a hint to force the VisualID used when creating a window.
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/Android.mk b/Android.mk
old mode 100644
new mode 100755
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 8fa0dd6..9f75189 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -198,6 +198,12 @@ extern "C" {
#define SDL_HINT_VIDEO_X11_XRANDR "SDL_VIDEO_X11_XRANDR"
/**
+ * \brief A variable forcing the visual ID chosen for new X11 windows
+ *
+ */
+#define SDL_HINT_VIDEO_X11_WINDOW_VISUALID "SDL_VIDEO_X11_WINDOW_VISUALID"
+
+/**
* \brief A variable controlling whether the X11 _NET_WM_PING protocol should be supported.
*
* This variable can be set to the following values:
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index 798e8bc..c5bb1dc 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -393,7 +393,27 @@ X11_CreateWindow(_THIS, SDL_Window * window)
long fevent = 0;
#if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_EGL
- if ((window->flags & SDL_WINDOW_OPENGL) &&
+ const char *forced_visual_id = SDL_GetHint(SDL_HINT_VIDEO_X11_WINDOW_VISUALID);
+
+ if (forced_visual_id != NULL && forced_visual_id[0] != '\0')
+ {
+ XVisualInfo *vi, template;
+ int nvis;
+
+ SDL_zero(template);
+ template.visualid = SDL_strtol(forced_visual_id, NULL, 0);
+ vi = X11_XGetVisualInfo(display, VisualIDMask, &template, &nvis);
+ if (vi) {
+ visual = vi->visual;
+ depth = vi->depth;
+ X11_XFree(vi);
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ else if ((window->flags & SDL_WINDOW_OPENGL) &&
!SDL_getenv("SDL_VIDEO_X11_VISUALID")) {
XVisualInfo *vinfo = NULL;