SDL: unix: Factor out the check for GTK into an internal function

From 9e0b31b297e85c1a1d8f48c05231b3bcd3b2f80e Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Sun, 28 Dec 2025 13:41:06 +0000
Subject: [PATCH] unix: Factor out the check for GTK into an internal function

This will allow the same check to be done by the libdecor integration.

Helps: https://github.com/libsdl-org/sdl2-compat/issues/564
Signed-off-by: Simon McVittie <smcv@debian.org>
---
 src/core/unix/SDL_gtk.c | 11 ++++++++++-
 src/core/unix/SDL_gtk.h |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/core/unix/SDL_gtk.c b/src/core/unix/SDL_gtk.c
index 2d10aa180c369..5376cdf17d1a3 100644
--- a/src/core/unix/SDL_gtk.c
+++ b/src/core/unix/SDL_gtk.c
@@ -81,12 +81,21 @@ static bool IsGtkInit()
     return libgdk != NULL && libgtk != NULL;
 }
 
-static bool InitGtk(void)
+bool SDL_CanUseGtk(void)
 {
     if (!SDL_GetHintBoolean("SDL_ENABLE_GTK", true)) {
         return false;
     }
 
+    return true;
+}
+
+static bool InitGtk(void)
+{
+    if (!SDL_CanUseGtk()) {
+        return false;
+    }
+
     if (IsGtkInit()) {
         return true;
     }
diff --git a/src/core/unix/SDL_gtk.h b/src/core/unix/SDL_gtk.h
index 0287fe0b8f0ed..7318ee31cf66b 100644
--- a/src/core/unix/SDL_gtk.h
+++ b/src/core/unix/SDL_gtk.h
@@ -116,6 +116,7 @@ typedef struct SDL_GtkContext
 	} gtk;
 } SDL_GtkContext;
 
+extern bool SDL_CanUseGtk(void);
 extern bool SDL_Gtk_Init(void);
 extern void SDL_Gtk_Quit(void);
 extern SDL_GtkContext *SDL_Gtk_EnterContext(void);