From 8cde570ad964e434782f53e2466cd4d582ccd573 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 3 Aug 2024 09:42:51 -0700
Subject: [PATCH] Added SDL_HINT_VIDEO_X11_VISUALID
---
include/SDL3/SDL_hints.h | 9 +++++++++
src/video/x11/SDL_x11modes.c | 4 ++--
src/video/x11/SDL_x11window.c | 5 +++--
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index 00b88ecd8eb72..4abace78b3359 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -3311,6 +3311,15 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_X11_SCALING_FACTOR "SDL_VIDEO_X11_SCALING_FACTOR"
+/**
+ * A variable forcing the visual ID used for X11 display modes.
+ *
+ * This hint should be set before initializing the video subsystem.
+ *
+ * \since This hint is available since SDL 3.0.0.
+ */
+#define SDL_HINT_VIDEO_X11_VISUALID "SDL_VIDEO_X11_VISUALID"
+
/**
* A variable forcing the visual ID chosen for new X11 windows.
*
diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c
index d830123bf1099..61854feff708a 100644
--- a/src/video/x11/SDL_x11modes.c
+++ b/src/video/x11/SDL_x11modes.c
@@ -265,11 +265,11 @@ static float GetGlobalContentScale(SDL_VideoDevice *_this)
static int get_visualinfo(Display *display, int screen, XVisualInfo *vinfo)
{
- const char *visual_id = SDL_getenv("SDL_VIDEO_X11_VISUALID");
+ const char *visual_id = SDL_GetHint(SDL_HINT_VIDEO_X11_VISUALID);
int depth;
/* Look for an exact visual, if requested */
- if (visual_id) {
+ if (visual_id && *visual_id) {
XVisualInfo *vi, template;
int nvis;
diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c
index d0cd1b558d789..7d1d2fab677e7 100644
--- a/src/video/x11/SDL_x11window.c
+++ b/src/video/x11/SDL_x11window.c
@@ -531,8 +531,9 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI
#if defined(SDL_VIDEO_OPENGL_GLX) || defined(SDL_VIDEO_OPENGL_EGL)
const int transparent = (window->flags & SDL_WINDOW_TRANSPARENT) ? SDL_TRUE : SDL_FALSE;
const char *forced_visual_id = SDL_GetHint(SDL_HINT_VIDEO_X11_WINDOW_VISUALID);
+ const char *display_visual_id = SDL_GetHint(SDL_HINT_VIDEO_X11_VISUALID);
- if (forced_visual_id && forced_visual_id[0] != '\0') {
+ if (forced_visual_id && *forced_visual_id) {
XVisualInfo *vi, template;
int nvis;
@@ -547,7 +548,7 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI
return -1;
}
} else if ((window->flags & SDL_WINDOW_OPENGL) &&
- !SDL_getenv("SDL_VIDEO_X11_VISUALID")) {
+ (!display_visual_id || !*display_visual_id)) {
XVisualInfo *vinfo = NULL;
#ifdef SDL_VIDEO_OPENGL_EGL