From 917309e99c3784c18029db1da78de0f5e88e8a04 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sat, 20 Sep 2025 15:28:08 +0200 Subject: [PATCH] Prefer SDL X11 video driver on Linux for ImGui viewport support. --- private/raid/SModule | 2 +- private/raid/application.cpp | 33 +++++++++++++++++++++++++++++++-- public/raid/raid.hpp | 1 + 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/private/raid/SModule b/private/raid/SModule index 3f09d28..b0efdda 100644 --- a/private/raid/SModule +++ b/private/raid/SModule @@ -4,7 +4,7 @@ import json Import('env') if not hasattr(env, 'Jinja'): - env.Error('RAID requires the Jinja tool.') + env.Error('RAID requires Jinja.') src_files = Split(""" application.cpp diff --git a/private/raid/application.cpp b/private/raid/application.cpp index 32fb999..cdc27e5 100644 --- a/private/raid/application.cpp +++ b/private/raid/application.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -289,6 +290,11 @@ void Application::handleSDLEvent(const SDL_Event& event) } } +void Application::handleSDLError(const char* message) +{ + msgError("SDL: {}", message); +} + bool Application::init() { auto addConfigDir = [&](const fs::path& path) @@ -419,12 +425,19 @@ void Application::cleanup() bool Application::initSDL() { - if (!SDL_Init(0)) +#if MIJIN_TARGET_OS == MIJIN_OS_LINUX + // prefer x11 over wayland, as ImGui viewports don't work with wayland + // TODO: this still doesn't work all the time, maybe there will be an update to ImGui in the future? + SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "x11,wayland"); +#endif + if (!SDL_Init(SDL_INIT_VIDEO)) { msgError("Error initializing SDL: {}.", SDL_GetError()); return false; } + msgInfo("SDL video driver: {}", SDL_GetCurrentVideoDriver()); + // GL attributes must be set before window creation SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); @@ -475,12 +488,18 @@ bool Application::initImGui() { IMGUI_CHECKVERSION(); // not exactly useful when using static libs, but won't hurt - if (ImGui::CreateContext() == nullptr) + ImGuiContext* imguiContext = ImGui::CreateContext(); + if (imguiContext == nullptr) { msgError("Error initializing ImGui context."); return false; } + imguiContext->ErrorCallbackUserData = this; + imguiContext->ErrorCallback = [](ImGuiContext* /* ctx */, void* userData, const char* msg) { + static_cast(userData)->handleSDLError(msg); + }; + loadImGuiConfig(); configureImgui(); @@ -503,6 +522,16 @@ bool Application::initImGui() return false; } + if (imguiIO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + if (!(imguiIO.BackendFlags & ImGuiBackendFlags_PlatformHasViewports)) { + msgWarning("ImGUI viewports enabled, but platform doesn't support them."); + } + if (!(imguiIO.BackendFlags & ImGuiBackendFlags_RendererHasViewports)) { + msgWarning("ImGUI viewports enabled, but renderer doesn't support them."); + } + } + // init font if (imguiIO.Fonts->Fonts.empty()) { diff --git a/public/raid/raid.hpp b/public/raid/raid.hpp index 8fcd33a..5a1f54b 100644 --- a/public/raid/raid.hpp +++ b/public/raid/raid.hpp @@ -138,6 +138,7 @@ protected: virtual void initMemoryFS(); virtual void handleMessage(const Message& message); virtual void handleSDLEvent(const SDL_Event& event); + virtual void handleSDLError(const char* message); void msgInfo(const char* text) {