diff --git a/app/SDL_compat.h b/app/SDL_compat.h new file mode 100644 index 00000000..2bef3a63 --- /dev/null +++ b/app/SDL_compat.h @@ -0,0 +1,67 @@ +// +// Compatibility header for older version of SDL. +// Include this instead of SDL.h directly. +// + +#pragma once + +#include + +// SDL_FRect wasn't added until 2.0.10 +#if !SDL_VERSION_ATLEAST(2, 0, 10) +typedef struct SDL_FRect +{ + float x; + float y; + float w; + float h; +} SDL_FRect; +#endif + +#ifndef SDL_HINT_VIDEO_X11_FORCE_EGL +#define SDL_HINT_VIDEO_X11_FORCE_EGL "SDL_VIDEO_X11_FORCE_EGL" +#endif + +#ifndef SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER +#define SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER "SDL_KMSDRM_REQUIRE_DRM_MASTER" +#endif + +#ifndef SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED +#define SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED "SDL_ALLOW_ALT_TAB_WHILE_GRABBED" +#endif + +#ifndef SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE +#define SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE "SDL_JOYSTICK_HIDAPI_PS4_RUMBLE" +#endif + +#ifndef SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE +#define SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE "SDL_JOYSTICK_HIDAPI_PS5_RUMBLE" +#endif + +#ifndef SDL_HINT_WINDOWS_USE_D3D9EX +#define SDL_HINT_WINDOWS_USE_D3D9EX "SDL_WINDOWS_USE_D3D9EX" +#endif + +#ifndef SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS +#define SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS "SDL_GAMECONTROLLER_USE_BUTTON_LABELS" +#endif + +#ifndef SDL_HINT_MOUSE_RELATIVE_SCALING +#define SDL_HINT_MOUSE_RELATIVE_SCALING "SDL_MOUSE_RELATIVE_SCALING" +#endif + +#ifndef SDL_HINT_AUDIO_DEVICE_APP_NAME +#define SDL_HINT_AUDIO_DEVICE_APP_NAME "SDL_AUDIO_DEVICE_APP_NAME" +#endif + +#ifndef SDL_HINT_APP_NAME +#define SDL_HINT_APP_NAME "SDL_APP_NAME" +#endif + +#ifndef SDL_HINT_MOUSE_AUTO_CAPTURE +#define SDL_HINT_MOUSE_AUTO_CAPTURE "SDL_MOUSE_AUTO_CAPTURE" +#endif + +#ifndef SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP +#define SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP "SDL_VIDEO_WAYLAND_EMULATE_MOUSE_WARP" +#endif diff --git a/app/app.pro b/app/app.pro index cbdb9fbb..053882c1 100644 --- a/app/app.pro +++ b/app/app.pro @@ -214,6 +214,7 @@ SOURCES += \ wm.cpp HEADERS += \ + SDL_compat.h \ backend/nvaddress.h \ backend/nvapp.h \ cli/pair.h \ diff --git a/app/gui/sdlgamepadkeynavigation.h b/app/gui/sdlgamepadkeynavigation.h index 7c26526a..3d2feecd 100644 --- a/app/gui/sdlgamepadkeynavigation.h +++ b/app/gui/sdlgamepadkeynavigation.h @@ -3,7 +3,7 @@ #include #include -#include +#include "SDL_compat.h" #include "settings/streamingpreferences.h" diff --git a/app/main.cpp b/app/main.cpp index def1fc6b..c096dede 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -17,7 +17,7 @@ // doing the same thing. This needs to be before any headers // that might include SDL.h themselves. #define SDL_MAIN_HANDLED -#include +#include "SDL_compat.h" #ifdef HAVE_FFMPEG #include "streaming/video/ffmpeg.h" @@ -452,7 +452,7 @@ int main(int argc, char *argv[]) #endif } -#if !defined(Q_PROCESSOR_X86) && defined(SDL_HINT_VIDEO_X11_FORCE_EGL) +#ifndef Q_PROCESSOR_X86 // Some ARM and RISC-V embedded devices don't have working GLX which can cause // SDL to fail to find a working OpenGL implementation at all. Let's force EGL // on non-x86 platforms, since GLX is deprecated anyway. @@ -508,12 +508,12 @@ int main(int argc, char *argv[]) SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"); // We use MMAL to render on Raspberry Pi, so we do not require DRM master. - SDL_SetHint("SDL_KMSDRM_REQUIRE_DRM_MASTER", "0"); + SDL_SetHint(SDL_HINT_KMSDRM_REQUIRE_DRM_MASTER, "0"); // Use Direct3D 9Ex to avoid a deadlock caused by the D3D device being reset when // the user triggers a UAC prompt. This option controls the software/SDL renderer. // The DXVA2 renderer uses Direct3D 9Ex itself directly. - SDL_SetHint("SDL_WINDOWS_USE_D3D9EX", "1"); + SDL_SetHint(SDL_HINT_WINDOWS_USE_D3D9EX, "1"); if (SDL_InitSubSystem(SDL_INIT_TIMER) != 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, @@ -548,28 +548,28 @@ int main(int argc, char *argv[]) // SDL 2.0.12 changes the default behavior to use the button label rather than the button // position as most other software does. Set this back to 0 to stay consistent with prior // releases of Moonlight. - SDL_SetHint("SDL_GAMECONTROLLER_USE_BUTTON_LABELS", "0"); + SDL_SetHint(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0"); // Disable relative mouse scaling to renderer size or logical DPI. We want to send // the mouse motion exactly how it was given to us. - SDL_SetHint("SDL_MOUSE_RELATIVE_SCALING", "0"); + SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_SCALING, "0"); // Set our app name for SDL to use with PulseAudio and PipeWire. This matches what we // provide as our app name to libsoundio too. On SDL 2.0.18+, SDL_APP_NAME is also used // for screensaver inhibitor reporting. - SDL_SetHint("SDL_AUDIO_DEVICE_APP_NAME", "Moonlight"); - SDL_SetHint("SDL_APP_NAME", "Moonlight"); + SDL_SetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME, "Moonlight"); + SDL_SetHint(SDL_HINT_APP_NAME, "Moonlight"); // We handle capturing the mouse ourselves when it leaves the window, so we don't need // SDL doing it for us behind our backs. - SDL_SetHint("SDL_MOUSE_AUTO_CAPTURE", "0"); + SDL_SetHint(SDL_HINT_MOUSE_AUTO_CAPTURE, "0"); // SDL will try to lock the mouse cursor on Wayland if it's not visible in order to // support applications that assume they can warp the cursor (which isn't possible // on Wayland). We don't want this behavior because it interferes with seamless mouse // mode when toggling between windowed and fullscreen modes by unexpectedly locking // the mouse cursor. - SDL_SetHint("SDL_VIDEO_WAYLAND_EMULATE_MOUSE_WARP", "0"); + SDL_SetHint(SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP, "0"); #ifdef QT_DEBUG // Allow thread naming using exceptions on debug builds. SDL doesn't use SEH diff --git a/app/masterhook.c b/app/masterhook.c index 06c63a52..6b17380f 100644 --- a/app/masterhook.c +++ b/app/masterhook.c @@ -15,7 +15,7 @@ // redirection that happens when _FILE_OFFSET_BITS=64! // See masterhook_internal.c for details. -#include +#include "SDL_compat.h" #include #include #include diff --git a/app/masterhook_internal.c b/app/masterhook_internal.c index f284fd17..1c516f94 100644 --- a/app/masterhook_internal.c +++ b/app/masterhook_internal.c @@ -4,7 +4,7 @@ #define _GNU_SOURCE -#include +#include "SDL_compat.h" #include #include #include diff --git a/app/settings/mappingmanager.cpp b/app/settings/mappingmanager.cpp index be9a1a8d..ac2178b0 100644 --- a/app/settings/mappingmanager.cpp +++ b/app/settings/mappingmanager.cpp @@ -3,7 +3,7 @@ #include -#include +#include "SDL_compat.h" #define SER_GAMEPADMAPPING "gcmapping" diff --git a/app/streaming/audio/renderers/sdl.h b/app/streaming/audio/renderers/sdl.h index 44d55551..f35d1f94 100644 --- a/app/streaming/audio/renderers/sdl.h +++ b/app/streaming/audio/renderers/sdl.h @@ -1,7 +1,7 @@ #pragma once #include "renderer.h" -#include +#include "SDL_compat.h" class SdlAudioRenderer : public IAudioRenderer { diff --git a/app/streaming/audio/renderers/sdlaud.cpp b/app/streaming/audio/renderers/sdlaud.cpp index 9653ca97..16b90775 100644 --- a/app/streaming/audio/renderers/sdlaud.cpp +++ b/app/streaming/audio/renderers/sdlaud.cpp @@ -1,7 +1,6 @@ #include "sdl.h" #include -#include SdlAudioRenderer::SdlAudioRenderer() : m_AudioDevice(0), diff --git a/app/streaming/audio/renderers/slaud.cpp b/app/streaming/audio/renderers/slaud.cpp index 3a6e0304..fba7a434 100644 --- a/app/streaming/audio/renderers/slaud.cpp +++ b/app/streaming/audio/renderers/slaud.cpp @@ -1,6 +1,6 @@ #include "slaud.h" -#include +#include "SDL_compat.h" SLAudioRenderer::SLAudioRenderer() : m_AudioContext(nullptr), diff --git a/app/streaming/audio/renderers/soundioaudiorenderer.cpp b/app/streaming/audio/renderers/soundioaudiorenderer.cpp index 495a50ae..305322cc 100644 --- a/app/streaming/audio/renderers/soundioaudiorenderer.cpp +++ b/app/streaming/audio/renderers/soundioaudiorenderer.cpp @@ -1,6 +1,6 @@ #include "soundioaudiorenderer.h" -#include +#include "SDL_compat.h" #include diff --git a/app/streaming/input/abstouch.cpp b/app/streaming/input/abstouch.cpp index 04bacb52..28b33a4c 100644 --- a/app/streaming/input/abstouch.cpp +++ b/app/streaming/input/abstouch.cpp @@ -1,7 +1,7 @@ #include "input.h" #include -#include +#include "SDL_compat.h" #include #include "streaming/streamutils.h" diff --git a/app/streaming/input/gamepad.cpp b/app/streaming/input/gamepad.cpp index 131ec193..435c9d2f 100644 --- a/app/streaming/input/gamepad.cpp +++ b/app/streaming/input/gamepad.cpp @@ -1,7 +1,7 @@ #include "streaming/session.h" #include -#include +#include "SDL_compat.h" #include "settings/mappingmanager.h" #include diff --git a/app/streaming/input/input.cpp b/app/streaming/input/input.cpp index 95db06e0..243606f0 100644 --- a/app/streaming/input/input.cpp +++ b/app/streaming/input/input.cpp @@ -1,5 +1,5 @@ #include -#include +#include "SDL_compat.h" #include "streaming/session.h" #include "settings/mappingmanager.h" #include "path.h" @@ -50,7 +50,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i #endif // Opt-out of SDL's built-in Alt+Tab handling while keyboard grab is enabled - SDL_SetHint("SDL_ALLOW_ALT_TAB_WHILE_GRABBED", "0"); + SDL_SetHint(SDL_HINT_ALLOW_ALT_TAB_WHILE_GRABBED, "0"); // Allow clicks to pass through to us when focusing the window. If we're in // absolute mouse mode, this will avoid the user having to click twice to @@ -62,8 +62,8 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i // controllers, but breaks DirectInput applications. We will enable it because // it's likely that working rumble is what the user is expecting. If they don't // want this behavior, they can override it with the environment variable. - SDL_SetHint("SDL_JOYSTICK_HIDAPI_PS4_RUMBLE", "1"); - SDL_SetHint("SDL_JOYSTICK_HIDAPI_PS5_RUMBLE", "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); + SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); // Populate special key combo configuration m_SpecialKeyCombos[KeyComboQuit].keyCombo = KeyComboQuit; diff --git a/app/streaming/input/input.h b/app/streaming/input/input.h index ec24070a..701e19cf 100644 --- a/app/streaming/input/input.h +++ b/app/streaming/input/input.h @@ -3,7 +3,7 @@ #include "settings/streamingpreferences.h" #include "backend/computermanager.h" -#include +#include "SDL_compat.h" struct GamepadState { SDL_GameController* controller; diff --git a/app/streaming/input/keyboard.cpp b/app/streaming/input/keyboard.cpp index a501cdb6..b574caf9 100644 --- a/app/streaming/input/keyboard.cpp +++ b/app/streaming/input/keyboard.cpp @@ -1,7 +1,7 @@ #include "streaming/session.h" #include -#include +#include "SDL_compat.h" #define VK_0 0x30 #define VK_A 0x41 diff --git a/app/streaming/input/mouse.cpp b/app/streaming/input/mouse.cpp index b5ebcc0b..6b1cae79 100644 --- a/app/streaming/input/mouse.cpp +++ b/app/streaming/input/mouse.cpp @@ -1,7 +1,7 @@ #include "input.h" #include -#include +#include "SDL_compat.h" #include "streaming/streamutils.h" void SdlInputHandler::handleMouseButtonEvent(SDL_MouseButtonEvent* event) diff --git a/app/streaming/input/reltouch.cpp b/app/streaming/input/reltouch.cpp index 6125e636..0ddc778a 100644 --- a/app/streaming/input/reltouch.cpp +++ b/app/streaming/input/reltouch.cpp @@ -1,7 +1,7 @@ #include "input.h" #include -#include +#include "SDL_compat.h" #include diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index b6f1a025..6da51f16 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -4,7 +4,7 @@ #include "backend/richpresencemanager.h" #include -#include +#include "SDL_compat.h" #include "utils.h" #ifdef HAVE_FFMPEG diff --git a/app/streaming/streamutils.h b/app/streaming/streamutils.h index 3b93d952..671ce24c 100644 --- a/app/streaming/streamutils.h +++ b/app/streaming/streamutils.h @@ -1,17 +1,6 @@ #pragma once -#include - -// SDL_FRect wasn't added until 2.0.10 -#if !SDL_VERSION_ATLEAST(2, 0, 10) -typedef struct SDL_FRect -{ - float x; - float y; - float w; - float h; -} SDL_FRect; -#endif +#include "SDL_compat.h" class StreamUtils { diff --git a/app/streaming/video/decoder.h b/app/streaming/video/decoder.h index 24708d82..c7792823 100644 --- a/app/streaming/video/decoder.h +++ b/app/streaming/video/decoder.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include "SDL_compat.h" #include "settings/streamingpreferences.h" #define SDL_CODE_FRAME_READY 0 diff --git a/app/streaming/video/ffmpeg-renderers/eglvid.cpp b/app/streaming/video/ffmpeg-renderers/eglvid.cpp index 27f86c10..57a84942 100644 --- a/app/streaming/video/ffmpeg-renderers/eglvid.cpp +++ b/app/streaming/video/ffmpeg-renderers/eglvid.cpp @@ -647,14 +647,12 @@ bool EGLRenderer::initialize(PDECODER_PARAMETERS params) // Detach the context from this thread, so the render thread can attach it SDL_GL_MakeCurrent(m_Window, nullptr); -#ifdef SDL_HINT_VIDEO_X11_FORCE_EGL if (err == GL_NO_ERROR) { // If we got a working GL implementation via EGL, avoid using GLX from now on. // GLX will cause problems if we later want to use EGL again on this window. SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "EGL passed preflight checks. Using EGL for GL context creation."); SDL_SetHint(SDL_HINT_VIDEO_X11_FORCE_EGL, "1"); } -#endif return err == GL_NO_ERROR; } diff --git a/app/streaming/video/ffmpeg-renderers/renderer.h b/app/streaming/video/ffmpeg-renderers/renderer.h index 33fbcb2c..7e15e732 100644 --- a/app/streaming/video/ffmpeg-renderers/renderer.h +++ b/app/streaming/video/ffmpeg-renderers/renderer.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "SDL_compat.h" #include "streaming/video/decoder.h" #include "streaming/video/overlaymanager.h" diff --git a/app/streaming/video/overlaymanager.h b/app/streaming/video/overlaymanager.h index 59c808b9..5e7b486c 100644 --- a/app/streaming/video/overlaymanager.h +++ b/app/streaming/video/overlaymanager.h @@ -2,7 +2,7 @@ #include -#include +#include "SDL_compat.h" #include namespace Overlay { diff --git a/app/wm.cpp b/app/wm.cpp index 542d664e..68f26d0f 100644 --- a/app/wm.cpp +++ b/app/wm.cpp @@ -3,7 +3,7 @@ #include "utils.h" -#include +#include "SDL_compat.h" #ifdef HAS_X11 #include