From a190e3b5149e736919715264502fba6574ed9720 Mon Sep 17 00:00:00 2001
From: Kyle Sylvestre <[EMAIL REDACTED]>
Date: Sat, 12 Jul 2025 00:42:17 -0400
Subject: [PATCH] move SDL_HelperWindow outside of video
move to SDL_window.c to prevent relying on SDL_VIDEO
---
src/core/windows/SDL_windows.c | 72 +++++++++++++++++++++++++++
src/video/windows/SDL_windowswindow.c | 72 ---------------------------
2 files changed, 72 insertions(+), 72 deletions(-)
diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c
index d96d8e0bbadcf..cc8c8327cebdb 100644
--- a/src/core/windows/SDL_windows.c
+++ b/src/core/windows/SDL_windows.c
@@ -53,6 +53,78 @@ typedef enum RO_INIT_TYPE
#define WC_ERR_INVALID_CHARS 0x00000080
#endif
+// Fake window to help with DirectInput events.
+HWND SDL_HelperWindow = NULL;
+static const TCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
+static const TCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
+static ATOM SDL_HelperWindowClass = 0;
+
+/*
+ * Creates a HelperWindow used for DirectInput.
+ */
+bool SDL_HelperWindowCreate(void)
+{
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+ WNDCLASS wce;
+
+ // Make sure window isn't created twice.
+ if (SDL_HelperWindow != NULL) {
+ return true;
+ }
+
+ // Create the class.
+ SDL_zero(wce);
+ wce.lpfnWndProc = DefWindowProc;
+ wce.lpszClassName = SDL_HelperWindowClassName;
+ wce.hInstance = hInstance;
+
+ // Register the class.
+ SDL_HelperWindowClass = RegisterClass(&wce);
+ if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
+ return WIN_SetError("Unable to create Helper Window Class");
+ }
+
+ // Create the window.
+ SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
+ SDL_HelperWindowName,
+ WS_OVERLAPPED, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, HWND_MESSAGE, NULL,
+ hInstance, NULL);
+ if (!SDL_HelperWindow) {
+ UnregisterClass(SDL_HelperWindowClassName, hInstance);
+ return WIN_SetError("Unable to create Helper Window");
+ }
+
+ return true;
+}
+
+/*
+ * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
+ */
+void SDL_HelperWindowDestroy(void)
+{
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+
+ // Destroy the window.
+ if (SDL_HelperWindow != NULL) {
+ if (DestroyWindow(SDL_HelperWindow) == 0) {
+ WIN_SetError("Unable to destroy Helper Window");
+ return;
+ }
+ SDL_HelperWindow = NULL;
+ }
+
+ // Unregister the class.
+ if (SDL_HelperWindowClass != 0) {
+ if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
+ WIN_SetError("Unable to destroy Helper Window Class");
+ return;
+ }
+ SDL_HelperWindowClass = 0;
+ }
+}
+
// Sets an error message based on an HRESULT
bool WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr)
{
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index fe61315acc286..a6435aa8ef87a 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -96,12 +96,6 @@ typedef void (NTAPI *RtlGetVersion_t)(NT_OSVERSIONINFOW *);
// #define HIGHDPI_DEBUG
-// Fake window to help with DirectInput events.
-HWND SDL_HelperWindow = NULL;
-static const TCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
-static const TCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
-static ATOM SDL_HelperWindowClass = 0;
-
/* For borderless Windows, still want the following flag:
- WS_MINIMIZEBOX: window will respond to Windows minimize commands sent to all windows, such as windows key + m, shaking title bar, etc.
Additionally, non-fullscreen windows can add:
@@ -1538,72 +1532,6 @@ void WIN_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
CleanupWindowData(_this, window);
}
-/*
- * Creates a HelperWindow used for DirectInput.
- */
-bool SDL_HelperWindowCreate(void)
-{
- HINSTANCE hInstance = GetModuleHandle(NULL);
- WNDCLASS wce;
-
- // Make sure window isn't created twice.
- if (SDL_HelperWindow != NULL) {
- return true;
- }
-
- // Create the class.
- SDL_zero(wce);
- wce.lpfnWndProc = DefWindowProc;
- wce.lpszClassName = SDL_HelperWindowClassName;
- wce.hInstance = hInstance;
-
- // Register the class.
- SDL_HelperWindowClass = RegisterClass(&wce);
- if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
- return WIN_SetError("Unable to create Helper Window Class");
- }
-
- // Create the window.
- SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
- SDL_HelperWindowName,
- WS_OVERLAPPED, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, HWND_MESSAGE, NULL,
- hInstance, NULL);
- if (!SDL_HelperWindow) {
- UnregisterClass(SDL_HelperWindowClassName, hInstance);
- return WIN_SetError("Unable to create Helper Window");
- }
-
- return true;
-}
-
-/*
- * Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
- */
-void SDL_HelperWindowDestroy(void)
-{
- HINSTANCE hInstance = GetModuleHandle(NULL);
-
- // Destroy the window.
- if (SDL_HelperWindow != NULL) {
- if (DestroyWindow(SDL_HelperWindow) == 0) {
- WIN_SetError("Unable to destroy Helper Window");
- return;
- }
- SDL_HelperWindow = NULL;
- }
-
- // Unregister the class.
- if (SDL_HelperWindowClass != 0) {
- if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
- WIN_SetError("Unable to destroy Helper Window Class");
- return;
- }
- SDL_HelperWindowClass = 0;
- }
-}
-
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
void WIN_OnWindowEnter(SDL_VideoDevice *_this, SDL_Window *window)
{