From 175f28f59f0fe1e5e2f6dee2039b0bb20b52021a Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 3 Aug 2024 09:47:57 -0700
Subject: [PATCH] Added SDL_HINT_VIDEO_X11_NODIRECTCOLOR
---
include/SDL3/SDL_hints.h | 14 ++++++++++++++
src/video/x11/SDL_x11video.c | 5 ++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index 4abace78b3359..9f5123c12ac3b 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -3300,6 +3300,20 @@ extern "C" {
*/
#define SDL_HINT_VIDEO_X11_NET_WM_PING "SDL_VIDEO_X11_NET_WM_PING"
+/**
+ * A variable controlling whether SDL uses DirectColor visuals.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "0": Disable DirectColor visuals.
+ * - "1": Enable DirectColor visuals. (default)
+ *
+ * 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_NODIRECTCOLOR "SDL_VIDEO_X11_NODIRECTCOLOR"
+
/**
* A variable forcing the content scaling factor for X11 displays.
*
diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index 5024450a9d3a9..e255f3ce4d7fe 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -491,7 +491,10 @@ void X11_VideoQuit(SDL_VideoDevice *_this)
SDL_bool X11_UseDirectColorVisuals(void)
{
- return (SDL_getenv("SDL_VIDEO_X11_NODIRECTCOLOR") == NULL);
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_NODIRECTCOLOR, SDL_FALSE)) {
+ return SDL_FALSE;
+ }
+ return SDL_TRUE;
}
#endif /* SDL_VIDEO_DRIVER_X11 */