sdl2-compat: Make some modifications to the PR as asked by SDL devs

From 1e08d586e97960dd426bfb17df11290b4b7a266b Mon Sep 17 00:00:00 2001
From: vanfanel <[EMAIL REDACTED]>
Date: Sun, 12 Oct 2025 17:59:22 +0200
Subject: [PATCH] Make some modifications to the PR as asked by SDL devs

---
 CMakeLists.txt                 | 21 ++++++++++-----------
 include/SDL2/SDL_config_unix.h |  4 ++--
 src/sdl2_compat.h              |  4 ++--
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c11eee7..589bf35 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -87,7 +87,7 @@ cmake_dependent_option(SDL2COMPAT_INSTALL_SDL3 "Install SDL3 next to SDL2" OFF "
 option(SDL2COMPAT_ASAN "Use AddressSanitizer to detect memory errors" OFF)
 option(SDL2COMPAT_STATIC "Enable building static SDL2 link library" OFF)
 option(SDL2COMPAT_WERROR "Treat warnings as errors" OFF)
-option(SDL2COMPAT_DISABLE_X11 "Disable legacy X11 support" OFF)
+option(SDL2COMPAT_DISABLE_X11 "Disable X11 support" OFF)
 set(SDL2COMPAT_VENDOR_INFO "" CACHE STRING "Vendor name and/or version to add to SDL_REVISION")
 set(SDL2COMPAT_FRAMEWORK FALSE)
 #FIXME: should SDL2-compat modify vendor_info/revision information?
@@ -225,16 +225,6 @@ set(SDL2COMPAT_SRCS
   src/dynapi/SDL_dynapi.c
 )
 
-if(UNIX AND NOT ANDROID)
-  if(NOT SDL2COMPAT_DISABLE_X11)
-    find_package(X11 REQUIRED)
-    target_compile_definitions(SDL2 PRIVATE SDL2COMPAT_HAVE_X11)
-    include_directories(${X11_INCLUDE_DIR})
-  else()
-    message(STATUS "X11 support disabled")
-  endif()
-endif()
-
 if(APPLE)
   list(APPEND SDL2COMPAT_SRCS
     "src/sdl2_compat_objc.m"
@@ -336,7 +326,16 @@ string(STRIP "${CMAKE_C_FLAGS}" CMAKE_C_FLAGS)
 if(UNIX AND NOT APPLE)
   target_compile_definitions(SDL2 PRIVATE "_REENTRANT")
   target_link_libraries(SDL2 PRIVATE ${CMAKE_DL_LIBS})
+  if(NOT SDL2COMPAT_DISABLE_X11)
+    find_package(X11 REQUIRED)
+    target_compile_definitions(SDL2 PRIVATE SDL2COMPAT_HAVE_X11)
+    include_directories(${X11_INCLUDE_DIR})
+  else()
+    target_compile_definitions(SDL2 PRIVATE SDL2COMPAT_DISABLE_X11)
+    message(STATUS "X11 support disabled")
+  endif()
 endif()
+
 if(ANDROID)
   target_link_libraries(SDL2 PRIVATE log)
 endif()
diff --git a/include/SDL2/SDL_config_unix.h b/include/SDL2/SDL_config_unix.h
index 6948b45..d5a48e9 100644
--- a/include/SDL2/SDL_config_unix.h
+++ b/include/SDL2/SDL_config_unix.h
@@ -220,8 +220,8 @@
 #define SDL_LOADSO_DLOPEN 1
 #define SDL_THREAD_PTHREAD 1
 #define SDL_TIMER_UNIX 1
-/* ...But modern GNU/Linux can be Wayland-only */
-#if defined SDL2COMPAT_HAVE_X11
+/* Allow building without X11 support */
+#ifndef SDL2COMPAT_DISABLE_X11
 #define SDL_VIDEO_DRIVER_X11 1
 #endif
 
diff --git a/src/sdl2_compat.h b/src/sdl2_compat.h
index e11c83c..233a102 100644
--- a/src/sdl2_compat.h
+++ b/src/sdl2_compat.h
@@ -1288,7 +1288,7 @@ typedef struct _NSWindow NSWindow;
 typedef struct _UIWindow UIWindow;
 #endif
 
-#if defined(SDL_PLATFORM_UNIX) && !defined(SDL_PLATFORM_ANDROID) && defined(SDL2COMPAT_HAVE_X11)
+#ifdef SDL2COMPAT_HAVE_X11
 #include <X11/Xlib.h>
 #endif
 
@@ -1306,7 +1306,7 @@ typedef struct SDL2_SysWMmsg
             LPARAM lParam;              /**< LONG message parameter */
         } win;
 #endif
-#if defined(SDL_PLATFORM_UNIX) && !defined(SDL_PLATFORM_ANDROID) && defined(SDL2COMPAT_HAVE_X11)
+#ifdef SDL2COMPAT_HAVE_X11
         struct {
             XEvent event;
         } x11;