From 187ed4eceae525a2c9ed35375497320378f0d936 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 18 Aug 2022 16:07:03 -0400
Subject: [PATCH] SDL_GetVideoInfo: Attempt to correctly set wm_available.
This is an inexact science, but it's not like new window-based
desktop user interfaces pop up every day, so it's better than
the old code which just said everything had a window manager.
---
src/SDL12_compat.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 108ab9b9..5a523191 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -2131,6 +2131,41 @@ Init12VidModes(void)
#include "default_cursor.h"
DECLSPEC void SDLCALL SDL_FreeCursor(SDL12_Cursor *);
+static int
+HasWmAvailable(const char *driver)
+{
+ /* This is not perfect, but this emcompasses everything that SDL 2.22.0
+ offers. Most things are console or framebuffer targets, so it's
+ easier to list things that are actual GUI user interfaces here. */
+ static const char * const gui_targets[] = {
+ #ifdef _WIN32
+ "windows", "winrt",
+ #endif
+ #ifdef __APPLE__
+ "cocoa",
+ #endif
+ #ifdef __OS2__
+ "DIVE", "VMAN",
+ #endif
+ #ifdef __HAIKU__
+ "haiku",
+ #endif
+ #ifdef __QNX__
+ "qnx", /* I _think_ this has a window manager... */
+ #endif
+ "x11", "wayland" /* just assume anything can MAYBE have these, even if they wouldn't. */
+ };
+ int i;
+
+ for (i = 0; i < SDL_arraysize(gui_targets); i++) {
+ if (SDL20_strcasecmp(driver, gui_targets[i]) == 0) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static int
Init12Video(void)
{
@@ -2192,7 +2227,7 @@ Init12Video(void)
VideoInfo12.vfmt = PixelFormat20to12(&VideoInfoVfmt12, &VideoInfoPalette12, VideoInfoVfmt20);
VideoInfo12.current_w = mode.w;
VideoInfo12.current_h = mode.h;
- VideoInfo12.wm_available = 1; /* FIXME ? */
+ VideoInfo12.wm_available = HasWmAvailable(driver);
VideoInfo12.video_mem = 1024 * 256; /* good enough. */
}