From ad7add9becf8f18ca0293a2c2885cda921e1836a Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Thu, 11 Jun 2026 22:35:54 +0300 Subject: [PATCH] Compile SDL with wayland support --- CMakeLists.txt | 18 ++++++++++++++++-- conanfile.py | 9 --------- linuxinstall/com.infinipaint.infinipaint.yml | 20 ++------------------ src/GlobalConfig.cpp | 6 ++++++ src/GlobalConfig.hpp | 5 +++++ src/Toolbar.cpp | 3 +++ src/main.cpp | 4 ++++ 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index deea9d2..9ca5920 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(USE_MEMORYSAN "Enable Memory Sanitizer" OFF) option(NO_CONAN_BUILD "Not using conan to get packages" OFF) option(CONFIG_NEXT_TO_EXECUTABLE "Place configuration folder next to executable (portable executable)" OFF) option(MACOS_MAKE_BUNDLE "Package the application as a bundle" ON) +option(ADD_PREFER_X11_OPTION "Adds an internal Prefer X11 option" OFF) # Setting sources set(sources "src/main.cpp" @@ -213,7 +214,7 @@ else() endif() if(NOT EMSCRIPTEN) - if(NOT ANDROID) + if((NOT ANDROID) AND (NOT LINUX)) find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3-shared) endif() find_package(LibDataChannel REQUIRED) @@ -337,6 +338,10 @@ if(WIN32) target_compile_definitions(main PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) endif() +if(ADD_PREFER_X11_OPTION) + target_compile_definitions(main PRIVATE ADD_PREFER_X11_OPTION) +endif() + if(CONFIG_NEXT_TO_EXECUTABLE) target_compile_definitions(main PRIVATE CONFIG_NEXT_TO_EXECUTABLE) message("Place config next to executable") @@ -389,6 +394,15 @@ endif() if(ANDROID) add_subdirectory(deps/SDL EXCLUDE_FROM_ALL) +elseif(LINUX) + set(SDL_TEST_LIBRARY OFF CACHE BOOL "Compile SDL test library") + set(SDL_TESTS OFF CACHE BOOL "Compile SDL tests") + set(SDL_INSTALL_DOCS OFF CACHE BOOL "Install docs") + set(SDL_INSTALL_TESTS OFF CACHE BOOL "Install tests") + set(SDL_WAYLAND ON CACHE BOOL "Compile SDL for Wayland") + set(SDL_X11 ON CACHE BOOL "Compile SDL for X11") + set(SDL_AUDIO OFF CACHE BOOL "Compile SDL Audio") + add_subdirectory(deps/SDL EXCLUDE_FROM_ALL) endif() if(NO_CONAN_BUILD) @@ -397,7 +411,7 @@ if(NO_CONAN_BUILD) target_link_libraries(main SDL3::SDL3 ICU::uc Fontconfig::Fontconfig Freetype::Freetype PNG::PNG ZLIB::ZLIB) else() target_link_libraries(main skia-infinipaint::skia-infinipaint) - if(ANDROID) + if(ANDROID OR LINUX) target_link_libraries(main SDL3::SDL3) else() target_link_libraries(main sdl-infinipaint::sdl-infinipaint) diff --git a/conanfile.py b/conanfile.py index 909012a..8439fbe 100644 --- a/conanfile.py +++ b/conanfile.py @@ -92,15 +92,6 @@ class CompressorRecipe(ConanFile): if self.settings.os == "Linux": self.requires("fontconfig/2.17.1") self.requires("egl/system") - self.requires("sdl-infinipaint/3.4.8", options = { - "wayland": False, - "x11": True, - "pulseaudio": False, - "alsa": False, - "sndio": False, - "vulkan": False, - "opengles": False - }) elif self.settings.os == "Emscripten": self.requires("sdl-infinipaint/3.4.8", options = { "emscriptenPersistentPath": "/infinipaint" diff --git a/linuxinstall/com.infinipaint.infinipaint.yml b/linuxinstall/com.infinipaint.infinipaint.yml index 553dd46..d20bc88 100644 --- a/linuxinstall/com.infinipaint.infinipaint.yml +++ b/linuxinstall/com.infinipaint.infinipaint.yml @@ -46,23 +46,6 @@ modules: tag: v2022.0.0 commit: 0c0ff192a2304e114bc9e6557582dfba101360ff url: https://github.com/uxlfoundation/oneTBB.git - - name: SDL3 - buildsystem: cmake-ninja - config-opts: - - -DCMAKE_BUILD_TYPE=Release - - -DSDL_SHARED=ON - - -DSDL_STATIC=OFF - - -DSDL_TEST_LIBRARY=OFF - - -DSDL_TESTS=OFF - - -DSDL_DISABLE_INSTALL_DOCS=OFF - - -DSDL_INSTALL_TESTS=OFF - - -DSDL_WAYLAND=OFF - - -DSDL_X11=ON - sources: - - type: git - tag: release-3.4.8 - commit: d9d5536704d585616d4db3c8ba3c4ff6fc2757e1 - url: https://github.com/libsdl-org/SDL.git - name: Skia buildsystem: simple build-commands: @@ -149,7 +132,8 @@ cleanup: finish-args: - --share=ipc - - --socket=x11 + - --socket=wayland + - --socket=fallback-x11 - --device=all - --share=network - --filesystem=home diff --git a/src/GlobalConfig.cpp b/src/GlobalConfig.cpp index 9c7a841..063ce6f 100644 --- a/src/GlobalConfig.cpp +++ b/src/GlobalConfig.cpp @@ -55,6 +55,9 @@ nlohmann::json GlobalConfig::get_config_json(const InputManager& input) const { toRet["dragZoomSpeed"] = dragZoomSpeed; toRet["scrollZoomSpeed"] = scrollZoomSpeed; toRet["vsync"] = vsyncValue; +#ifdef ADD_PREFER_X11_OPTION + toRet["preferX11"] = preferX11; +#endif #ifndef __EMSCRIPTEN__ toRet["applyDisplayScale"] = applyDisplayScale; #endif @@ -126,6 +129,9 @@ void GlobalConfig::set_config_json(InputManager& input, const nlohmann::json& j, try{j.at("mainCallbackRateBackground").get_to(mainCallbackRateBackground);} catch(...) {} if(version >= VersionNumber(0, 6, 0)) try{j.at("vsync").get_to(vsyncValue);} catch(...) {} +#ifdef ADD_PREFER_X11_OPTION + try{j.at("preferX11").get_to(preferX11);} catch(...) {} +#endif #ifndef __EMSCRIPTEN__ try{j.at("applyDisplayScale").get_to(applyDisplayScale);} catch(...) {} #endif diff --git a/src/GlobalConfig.hpp b/src/GlobalConfig.hpp index 73ce541..6b195a5 100644 --- a/src/GlobalConfig.hpp +++ b/src/GlobalConfig.hpp @@ -119,6 +119,11 @@ class GlobalConfig { #ifndef __EMSCRIPTEN__ bool applyDisplayScale = true; #endif + + #ifdef ADD_PREFER_X11_OPTION + bool preferX11 = false; + #endif + private: void load_default_palette(); }; diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index 55749e8..4d58e79 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -1529,6 +1529,9 @@ void Toolbar::general_settings_inner_gui() { checkbox_boolean_field(gui, "real time eraser", "Eraser works in real time", &main.conf.realTimeEraser); checkbox_boolean_field(gui, "force extension on path", "Force extension on path when saving files", &main.conf.forceExtensionOnPath); + #ifdef ADD_PREFER_X11_OPTION + checkbox_boolean_field(gui, "prefer x11", "Prefer X11 over Wayland (Requires restart)", &main.conf.preferX11); + #endif }); break; } diff --git a/src/main.cpp b/src/main.cpp index 2330699..a8d4fe5 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -227,6 +227,10 @@ void initialize_sdl(MainStruct& mS) { SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0"); SDL_SetHint(SDL_HINT_ANDROID_TRAP_BACK_BUTTON, "1"); SDL_SetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT, "#canvas"); // Ensures that SDL only grabs input when browser is focused on canvas + #ifdef ADD_PREFER_X11_OPTION + if(mS.m->conf.preferX11) + SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "x11,wayland"); + #endif if(!SDL_Init(SDL_INIT_VIDEO)) throw std::runtime_error("[SDL_Init] " + std::string(SDL_GetError()));