From a3492e59eff91e6933cdc3c7784093ea755b3858 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 11 Feb 2026 23:28:44 +0100 Subject: [PATCH] Use `CreateWindow`/`GetBatteryInfo`/`GetUserLocaleName` from Windows instead of SDL for now #2800 --- Source/Engine/Platform/SDL/SDLPlatform.cpp | 17 +++++++++++++++++ Source/Engine/Platform/SDL/SDLPlatform.h | 7 +++++++ .../Engine/Platform/Windows/WindowsPlatform.cpp | 6 ++---- .../Engine/Platform/Windows/WindowsPlatform.h | 4 ++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Platform/SDL/SDLPlatform.cpp b/Source/Engine/Platform/SDL/SDLPlatform.cpp index 1c6232bf6..6645e106a 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.cpp @@ -32,7 +32,9 @@ namespace SDLImpl { int32 SystemDpi = 96; +#if PLATFORM_LINUX String UserLocale("en"); +#endif bool WindowDecorationsSupported = true; bool SupportsDecorationDragging = true; String WaylandDisplayEnv; @@ -107,6 +109,7 @@ bool SDLPlatform::Init() if (!SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) Platform::Fatal(String::Format(TEXT("Failed to initialize SDL: {0}."), String(SDL_GetError()))); +#if PLATFORM_LINUX int localesCount = 0; auto locales = SDL_GetPreferredLocales(&localesCount); for (int i = 0; i < localesCount; i++) @@ -123,6 +126,7 @@ bool SDLPlatform::Init() } } SDL_free(locales); +#endif if (InitInternal()) return true; @@ -214,6 +218,7 @@ bool SDLPlatform::SupportsNativeDecorationDragging() return SDLImpl::SupportsDecorationDragging; } +#if !PLATFORM_WINDOWS BatteryInfo SDLPlatform::GetBatteryInfo() { BatteryInfo info; @@ -241,16 +246,24 @@ BatteryInfo SDLPlatform::GetBatteryInfo() } return info; } +#endif int32 SDLPlatform::GetDpi() { return SDLImpl::SystemDpi; } +#if PLATFORM_LINUX String SDLPlatform::GetUserLocaleName() { return SDLImpl::UserLocale; } +#endif + +bool SDLPlatform::CanOpenUrl(const StringView& url) +{ + return true; +} void SDLPlatform::OpenUrl(const StringView& url) { @@ -318,6 +331,8 @@ Window* SDLPlatform::CreateWindow(const CreateWindowSettings& settings) return New(settings); } +#if !PLATFORM_WINDOWS + bool ReadStream(SDL_IOStream*& stream, char* buffer, int64 bufferLength, int64& bufferPosition, LogType logType, CreateProcessSettings& settings) { bool flushBuffer = false; @@ -480,3 +495,5 @@ int32 SDLPlatform::CreateProcess(CreateProcessSettings& settings) } #endif + +#endif diff --git a/Source/Engine/Platform/SDL/SDLPlatform.h b/Source/Engine/Platform/SDL/SDLPlatform.h index 0929e225f..cfb308677 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.h +++ b/Source/Engine/Platform/SDL/SDLPlatform.h @@ -77,9 +77,14 @@ public: static bool SupportsNativeDecorations(); static bool SupportsNativeDecorationDragging(); static void SetHighDpiAwarenessEnabled(bool enable); +#if !PLATFORM_WINDOWS static BatteryInfo GetBatteryInfo(); +#endif static int32 GetDpi(); +#if PLATFORM_LINUX static String GetUserLocaleName(); +#endif + static bool CanOpenUrl(const StringView& url); static void OpenUrl(const StringView& url); static Float2 GetMousePosition(); static void SetMousePosition(const Float2& pos); @@ -87,7 +92,9 @@ public: static Rectangle GetMonitorBounds(const Float2& screenPos); static Rectangle GetVirtualDesktopBounds(); static Window* CreateWindow(const CreateWindowSettings& settings); +#if !PLATFORM_WINDOWS static int32 CreateProcess(CreateProcessSettings& settings); +#endif }; #endif diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.cpp b/Source/Engine/Platform/Windows/WindowsPlatform.cpp index 69c7ad50c..cc339c9e9 100644 --- a/Source/Engine/Platform/Windows/WindowsPlatform.cpp +++ b/Source/Engine/Platform/Windows/WindowsPlatform.cpp @@ -775,13 +775,11 @@ bool WindowsPlatform::Init() DWORD tmp; Char buffer[256]; -#if !PLATFORM_SDL // Get user locale string if (GetUserDefaultLocaleName(buffer, LOCALE_NAME_MAX_LENGTH)) { UserLocale = String(buffer); } -#endif // Get computer name string if (GetComputerNameW(buffer, &tmp)) @@ -951,12 +949,12 @@ int32 WindowsPlatform::GetDpi() { return SystemDpi; } +#endif String WindowsPlatform::GetUserLocaleName() { return UserLocale; } -#endif String WindowsPlatform::GetComputerName() { @@ -1120,7 +1118,6 @@ bool IsProcRunning(HANDLE handle) return WaitForSingleObject(handle, 0) == WAIT_TIMEOUT; } -#if !PLATFORM_SDL void ReadPipe(HANDLE pipe, Array& rawData, Array& logData, LogType logType, CreateProcessSettings& settings) { // Check if any data is ready to read @@ -1329,6 +1326,7 @@ int32 WindowsPlatform::CreateProcess(CreateProcessSettings& settings) return result; } +#if !PLATFORM_SDL Window* WindowsPlatform::CreateWindow(const CreateWindowSettings& settings) { return New(settings); diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.h b/Source/Engine/Platform/Windows/WindowsPlatform.h index eb2d51c3f..a30e3e145 100644 --- a/Source/Engine/Platform/Windows/WindowsPlatform.h +++ b/Source/Engine/Platform/Windows/WindowsPlatform.h @@ -67,8 +67,8 @@ public: static BatteryInfo GetBatteryInfo(); #if !PLATFORM_SDL static int32 GetDpi(); - static String GetUserLocaleName(); #endif + static String GetUserLocaleName(); static String GetComputerName(); static bool GetHasFocus(); static bool CanOpenUrl(const StringView& url); @@ -81,8 +81,8 @@ public: static void GetEnvironmentVariables(Dictionary& result); static bool GetEnvironmentVariable(const String& name, String& value); static bool SetEnvironmentVariable(const String& name, const String& value); -#if !PLATFORM_SDL static int32 CreateProcess(CreateProcessSettings& settings); +#if !PLATFORM_SDL static Window* CreateWindow(const CreateWindowSettings& settings); #endif static void* LoadLibrary(const Char* filename);