From e88d068acc03c8bb110117e6b064854cd6c47901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 12 Sep 2026 00:51:33 -0300 Subject: [PATCH] window: use native SDL drivers for terminal runtime Use Cocoa, Windows, and Haiku native drivers for terminal-mode OpenGL context hosts instead of the unsupported offscreen driver. Keep hosts hidden and work around Haiku SDL2 showing hidden windows during creation. --- src/eepp/window/backend/SDL2/windowsdl2.cpp | 10 ++++++ src/eepp/window/engine.cpp | 34 ++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/eepp/window/backend/SDL2/windowsdl2.cpp b/src/eepp/window/backend/SDL2/windowsdl2.cpp index 9f4857f5d..ecdef306e 100644 --- a/src/eepp/window/backend/SDL2/windowsdl2.cpp +++ b/src/eepp/window/backend/SDL2/windowsdl2.cpp @@ -162,6 +162,16 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) { return false; } +#if EE_PLATFORM == EE_PLATFORM_HAIKU + // Haiku's SDL2 driver shows the window during creation even when SDL_WINDOW_HIDDEN was + // requested. Transition it through SDL's visible state so SDL_HideWindow can reach the native + // driver and restore the hidden context-host contract used by terminal mode and tests. + if ( mWindow.WindowConfig.Style & WindowStyle::Hidden ) { + SDL_ShowWindow( mSDLWindow ); + SDL_HideWindow( mSDLWindow ); + } +#endif + #if EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_IOS Log::notice( "Choosing GL Version from: %d", Context.Version ); diff --git a/src/eepp/window/engine.cpp b/src/eepp/window/engine.cpp index 47d7c5af8..a1eb1e5c1 100644 --- a/src/eepp/window/engine.cpp +++ b/src/eepp/window/engine.cpp @@ -73,10 +73,34 @@ Engine::WindowContext::WindowContext( WindowContext&& other ) noexcept : namespace { void configureRuntimeVideoDriver() { - if ( !Runtime::isOffscreen() ) + if ( Runtime::mode() == RuntimeMode::Headless ) { + Sys::setEnv( "SDL_VIDEODRIVER", "offscreen" ); + Sys::setEnv( "SDL_VIDEO_DRIVER", "offscreen" ); + return; + } + +#if EE_PLATFORM == EE_PLATFORM_MACOS || EE_PLATFORM == EE_PLATFORM_WIN || \ + EE_PLATFORM == EE_PLATFORM_HAIKU + if ( Runtime::mode() == RuntimeMode::Terminal ) { + // Terminal mode still needs a real OpenGL context host. These native SDL drivers are the + // supported OpenGL paths on their platforms, while the offscreen driver is unavailable or + // unusable there. +#if EE_PLATFORM == EE_PLATFORM_MACOS + constexpr char nativeVideoDriver[] = "cocoa"; +#elif EE_PLATFORM == EE_PLATFORM_WIN + constexpr char nativeVideoDriver[] = "windows"; +#else + constexpr char nativeVideoDriver[] = "haiku"; +#endif + Sys::setEnv( "SDL_VIDEODRIVER", nativeVideoDriver ); + Sys::setEnv( "SDL_VIDEO_DRIVER", nativeVideoDriver ); + } +#else + if ( Runtime::mode() != RuntimeMode::Terminal ) return; Sys::setEnv( "SDL_VIDEODRIVER", "offscreen" ); Sys::setEnv( "SDL_VIDEO_DRIVER", "offscreen" ); +#endif } } // namespace @@ -270,6 +294,14 @@ EE::Window::Window* Engine::createWindow( WindowSettings Settings, ContextSettin TerminalRuntime& terminal = TerminalRuntime::instance(); if ( !terminal.initialize() ) return nullptr; +#if EE_PLATFORM == EE_PLATFORM_MACOS || EE_PLATFORM == EE_PLATFORM_WIN || \ + EE_PLATFORM == EE_PLATFORM_HAIKU + // Terminal mode presents through Kitty, not through the native window manager. Keep the + // native context host hidden and avoid asking the native window manager to enter + // fullscreen. + Settings.Style |= WindowStyle::Hidden; + Settings.Style &= ~( WindowStyle::Fullscreen | WindowStyle::UseDesktopResolution ); +#endif const Sizei terminalSize = terminal.pixelSize(); if ( terminalSize.x > 0 && terminalSize.y > 0 ) { Settings.Width = terminalSize.x;