From 0a0699f272a53a09aaff8f7d1c0371c1a4077f70 Mon Sep 17 00:00:00 2001 From: Nadia Holmquist Pedersen Date: Mon, 20 May 2024 23:39:33 +0200 Subject: [PATCH] Linux: Force SDL2 video driver selection to X11 (#197) Co-authored-by: Anghelo Carvajal --- src/main/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/main.cpp b/src/main/main.cpp index 826533e..42b382f 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -51,6 +51,11 @@ ultramodern::gfx_callbacks_t::gfx_data_t create_gfx() { SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); + +#if defined(__linux__) + SDL_SetHint(SDL_HINT_VIDEODRIVER, "x11"); +#endif + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) > 0) { exit_error("Failed to initialize SDL2: %s\n", SDL_GetError()); } @@ -133,6 +138,10 @@ ultramodern::WindowHandle create_window(ultramodern::gfx_callbacks_t::gfx_data_t #elif defined(__ANDROID__) static_assert(false && "Unimplemented"); #elif defined(__linux__) + if (wmInfo.subsystem != SDL_SYSWM_X11) { + exit_error("Unsupported SDL2 video driver \"%s\". Only X11 is supported on Linux.\n", SDL_GetCurrentVideoDriver()); + } + return ultramodern::WindowHandle{ wmInfo.info.x11.display, wmInfo.info.x11.window }; #else static_assert(false && "Unimplemented");