diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index 00b88ecd8..4abace78b 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 d830123bf..61854feff 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 d0cd1b558..7d1d2fab6 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