Skip to content

Commit a190e3b

Browse files
kyle-sylvestreslouken
authored andcommitted
move SDL_HelperWindow outside of video
move to SDL_window.c to prevent relying on SDL_VIDEO
1 parent 5e78755 commit a190e3b

File tree

2 files changed

+72
-72
lines changed

2 files changed

+72
-72
lines changed

src/core/windows/SDL_windows.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,78 @@ typedef enum RO_INIT_TYPE
5353
#define WC_ERR_INVALID_CHARS 0x00000080
5454
#endif
5555

56+
// Fake window to help with DirectInput events.
57+
HWND SDL_HelperWindow = NULL;
58+
static const TCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
59+
static const TCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
60+
static ATOM SDL_HelperWindowClass = 0;
61+
62+
/*
63+
* Creates a HelperWindow used for DirectInput.
64+
*/
65+
bool SDL_HelperWindowCreate(void)
66+
{
67+
HINSTANCE hInstance = GetModuleHandle(NULL);
68+
WNDCLASS wce;
69+
70+
// Make sure window isn't created twice.
71+
if (SDL_HelperWindow != NULL) {
72+
return true;
73+
}
74+
75+
// Create the class.
76+
SDL_zero(wce);
77+
wce.lpfnWndProc = DefWindowProc;
78+
wce.lpszClassName = SDL_HelperWindowClassName;
79+
wce.hInstance = hInstance;
80+
81+
// Register the class.
82+
SDL_HelperWindowClass = RegisterClass(&wce);
83+
if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
84+
return WIN_SetError("Unable to create Helper Window Class");
85+
}
86+
87+
// Create the window.
88+
SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
89+
SDL_HelperWindowName,
90+
WS_OVERLAPPED, CW_USEDEFAULT,
91+
CW_USEDEFAULT, CW_USEDEFAULT,
92+
CW_USEDEFAULT, HWND_MESSAGE, NULL,
93+
hInstance, NULL);
94+
if (!SDL_HelperWindow) {
95+
UnregisterClass(SDL_HelperWindowClassName, hInstance);
96+
return WIN_SetError("Unable to create Helper Window");
97+
}
98+
99+
return true;
100+
}
101+
102+
/*
103+
* Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
104+
*/
105+
void SDL_HelperWindowDestroy(void)
106+
{
107+
HINSTANCE hInstance = GetModuleHandle(NULL);
108+
109+
// Destroy the window.
110+
if (SDL_HelperWindow != NULL) {
111+
if (DestroyWindow(SDL_HelperWindow) == 0) {
112+
WIN_SetError("Unable to destroy Helper Window");
113+
return;
114+
}
115+
SDL_HelperWindow = NULL;
116+
}
117+
118+
// Unregister the class.
119+
if (SDL_HelperWindowClass != 0) {
120+
if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
121+
WIN_SetError("Unable to destroy Helper Window Class");
122+
return;
123+
}
124+
SDL_HelperWindowClass = 0;
125+
}
126+
}
127+
56128
// Sets an error message based on an HRESULT
57129
bool WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr)
58130
{

src/video/windows/SDL_windowswindow.c

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ typedef void (NTAPI *RtlGetVersion_t)(NT_OSVERSIONINFOW *);
9696

9797
// #define HIGHDPI_DEBUG
9898

99-
// Fake window to help with DirectInput events.
100-
HWND SDL_HelperWindow = NULL;
101-
static const TCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher");
102-
static const TCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow");
103-
static ATOM SDL_HelperWindowClass = 0;
104-
10599
/* For borderless Windows, still want the following flag:
106100
- WS_MINIMIZEBOX: window will respond to Windows minimize commands sent to all windows, such as windows key + m, shaking title bar, etc.
107101
Additionally, non-fullscreen windows can add:
@@ -1538,72 +1532,6 @@ void WIN_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
15381532
CleanupWindowData(_this, window);
15391533
}
15401534

1541-
/*
1542-
* Creates a HelperWindow used for DirectInput.
1543-
*/
1544-
bool SDL_HelperWindowCreate(void)
1545-
{
1546-
HINSTANCE hInstance = GetModuleHandle(NULL);
1547-
WNDCLASS wce;
1548-
1549-
// Make sure window isn't created twice.
1550-
if (SDL_HelperWindow != NULL) {
1551-
return true;
1552-
}
1553-
1554-
// Create the class.
1555-
SDL_zero(wce);
1556-
wce.lpfnWndProc = DefWindowProc;
1557-
wce.lpszClassName = SDL_HelperWindowClassName;
1558-
wce.hInstance = hInstance;
1559-
1560-
// Register the class.
1561-
SDL_HelperWindowClass = RegisterClass(&wce);
1562-
if (SDL_HelperWindowClass == 0 && GetLastError() != ERROR_CLASS_ALREADY_EXISTS) {
1563-
return WIN_SetError("Unable to create Helper Window Class");
1564-
}
1565-
1566-
// Create the window.
1567-
SDL_HelperWindow = CreateWindowEx(0, SDL_HelperWindowClassName,
1568-
SDL_HelperWindowName,
1569-
WS_OVERLAPPED, CW_USEDEFAULT,
1570-
CW_USEDEFAULT, CW_USEDEFAULT,
1571-
CW_USEDEFAULT, HWND_MESSAGE, NULL,
1572-
hInstance, NULL);
1573-
if (!SDL_HelperWindow) {
1574-
UnregisterClass(SDL_HelperWindowClassName, hInstance);
1575-
return WIN_SetError("Unable to create Helper Window");
1576-
}
1577-
1578-
return true;
1579-
}
1580-
1581-
/*
1582-
* Destroys the HelperWindow previously created with SDL_HelperWindowCreate.
1583-
*/
1584-
void SDL_HelperWindowDestroy(void)
1585-
{
1586-
HINSTANCE hInstance = GetModuleHandle(NULL);
1587-
1588-
// Destroy the window.
1589-
if (SDL_HelperWindow != NULL) {
1590-
if (DestroyWindow(SDL_HelperWindow) == 0) {
1591-
WIN_SetError("Unable to destroy Helper Window");
1592-
return;
1593-
}
1594-
SDL_HelperWindow = NULL;
1595-
}
1596-
1597-
// Unregister the class.
1598-
if (SDL_HelperWindowClass != 0) {
1599-
if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) {
1600-
WIN_SetError("Unable to destroy Helper Window Class");
1601-
return;
1602-
}
1603-
SDL_HelperWindowClass = 0;
1604-
}
1605-
}
1606-
16071535
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
16081536
void WIN_OnWindowEnter(SDL_VideoDevice *_this, SDL_Window *window)
16091537
{

0 commit comments

Comments
 (0)