Prefer SDL X11 video driver on Linux for ImGui viewport support.

This commit is contained in:
Patrick 2025-09-20 15:28:08 +02:00
parent 66668959d3
commit 917309e99c
3 changed files with 33 additions and 3 deletions

View File

@ -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

View File

@ -13,6 +13,7 @@
#include <mijin/virtual_filesystem/mapping.hpp>
#include <mijin/virtual_filesystem/relative.hpp>
#include <imgui.h>
#include <imgui_internal.h>
#include <backends/imgui_impl_opengl3.h>
#include <backends/imgui_impl_sdl3.h>
#include <stb_image.h>
@ -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<Application*>(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())
{

View File

@ -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)
{