Skip to content

Commit e2e8f86

Browse files
committed
Check for wine_get_version() to detect Wine/Proton
If this application is being run under Wine but Steam doesn't know that, Steam won't set STEAM_COMPAT_PROTON. So we'll use wine_get_version() to detect that we're running under Wine instead.
1 parent 493bc62 commit e2e8f86

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/core/windows/SDL_windows.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,24 @@ static BOOL IsWindowsBuildVersionAtLeast(DWORD dwBuildNumber)
325325
return result;
326326
#endif
327327

328+
BOOL WIN_IsWine(void)
329+
{
330+
static bool checked;
331+
static bool is_wine;
332+
333+
if (!checked) {
334+
HMODULE ntdll = LoadLibrary(TEXT("ntdll.dll"));
335+
if (ntdll) {
336+
if (GetProcAddress(ntdll, "wine_get_version") != NULL) {
337+
is_wine = true;
338+
}
339+
FreeLibrary(ntdll);
340+
}
341+
checked = true;
342+
}
343+
return is_wine;
344+
}
345+
328346
// this is the oldest thing we run on (and we may lose support for this in SDL3 at any time!),
329347
// so there's no "OrGreater" as that would always be TRUE. The other functions are here to
330348
// ask "can we support a specific feature?" but this function is here to ask "do we need to do

src/core/windows/SDL_windows.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ extern void WIN_CoUninitialize(void);
168168
extern HRESULT WIN_RoInitialize(void);
169169
extern void WIN_RoUninitialize(void);
170170

171+
// Returns true if we're running on Wine
172+
extern BOOL WIN_IsWine(void);
173+
171174
// Returns true if we're running on Windows XP (any service pack). DOES NOT CHECK XP "OR GREATER"!
172175
extern BOOL WIN_IsWindowsXP(void);
173176

src/joystick/SDL_gamepad.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
#include "hidapi/SDL_hidapi_sinput.h"
3535
#include "../events/SDL_events_c.h"
3636

37-
38-
#ifdef SDL_PLATFORM_ANDROID
37+
#ifdef SDL_PLATFORM_WIN32
38+
#include "../core/windows/SDL_windows.h"
3939
#endif
4040

41+
4142
// Many gamepads turn the center button into an instantaneous button press
4243
#define SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS 250
4344

@@ -3262,10 +3263,10 @@ bool SDL_ShouldIgnoreGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version
32623263

32633264
#ifdef SDL_PLATFORM_WIN32
32643265
if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", false) &&
3265-
SDL_GetHintBoolean("STEAM_COMPAT_PROTON", false)) {
3266-
// We are launched by Steam and running under Proton
3266+
WIN_IsWine()) {
3267+
// We are launched by Steam and running under Proton or Wine
32673268
// We can't tell whether this controller is a Steam Virtual Gamepad,
3268-
// so assume that Proton is doing the appropriate filtering of controllers
3269+
// so assume that is doing the appropriate filtering of controllers
32693270
// and anything we see here is fine to use.
32703271
return false;
32713272
}

0 commit comments

Comments
 (0)