From c4d20f06ee4fea0079e71e02846d9d914ea62294 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Feb 2026 09:24:11 +0100 Subject: [PATCH] Move `GetDisplayServer` to `LinuxPlatform` (add support for custom platform scripting api) #2800 --- Source/Editor/Modules/UIModule.cs | 5 ++++- Source/Engine/Platform/Android/AndroidPlatform.h | 13 +++++++++---- Source/Engine/Platform/Base/PlatformBase.cpp | 5 ----- Source/Engine/Platform/Base/PlatformBase.h | 5 ----- Source/Engine/Platform/GDK/GDKPlatform.h | 12 ++++++++---- Source/Engine/Platform/Linux/LinuxPlatform.cpp | 5 +++++ Source/Engine/Platform/Linux/LinuxPlatform.h | 7 ++++++- Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp | 8 ++++++++ Source/Engine/Platform/SDL/SDLPlatform.cpp | 12 ------------ Source/Engine/Platform/SDL/SDLPlatform.h | 3 +-- Source/Tools/Flax.Build/Bindings/ApiTypeInfo.cs | 5 +++++ .../Flax.Build/Bindings/BindingsGenerator.Cpp.cs | 4 +++- 12 files changed, 49 insertions(+), 35 deletions(-) diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs index cb7c76b5b..f8abe6ee1 100644 --- a/Source/Editor/Modules/UIModule.cs +++ b/Source/Editor/Modules/UIModule.cs @@ -814,9 +814,12 @@ namespace FlaxEditor.Modules private void InitWindowDecorations(RootControl mainWindow) { ScriptsBuilder.GetBinariesConfiguration(out _, out _, out _, out var configuration); - var driver = Platform.DisplayServer; + string driver = string.Empty; +#if PLATFORM_LINUX + driver = LinuxPlatform.DisplayServer; if (!string.IsNullOrEmpty(driver)) driver = $" ({driver})"; +#endif WindowDecorations = new MainWindowDecorations(mainWindow, !Utilities.Utils.UseCustomWindowDecorations(isMainWindow: true)) { diff --git a/Source/Engine/Platform/Android/AndroidPlatform.h b/Source/Engine/Platform/Android/AndroidPlatform.h index 6153fa951..a1491fb06 100644 --- a/Source/Engine/Platform/Android/AndroidPlatform.h +++ b/Source/Engine/Platform/Android/AndroidPlatform.h @@ -12,15 +12,20 @@ struct android_app; /// /// The Android platform implementation and application management utilities. /// +API_CLASS(Static, Tag="NoTypeInitializer") class FLAXENGINE_API AndroidPlatform : public UnixPlatform { public: static android_app* GetApp(); - static String GetAppPackageName(); - static String GetDeviceManufacturer(); - static String GetDeviceModel(); - static String GetDeviceBuildNumber(); + // Gets 'getPackageName()' value. + API_PROPERTY() static String GetAppPackageName(); + // Gets 'android.os.Build.MANUFACTURER' value. + API_PROPERTY() static String GetDeviceManufacturer(); + // Gets 'android.os.Build.MODEL' value. + API_PROPERTY() static String GetDeviceModel(); + // Gets 'android.os.Build.DISPLAY' value. + API_PROPERTY() static String GetDeviceBuildNumber(); static void PreInit(android_app* app); public: diff --git a/Source/Engine/Platform/Base/PlatformBase.cpp b/Source/Engine/Platform/Base/PlatformBase.cpp index 07d78e46c..19e7ae11a 100644 --- a/Source/Engine/Platform/Base/PlatformBase.cpp +++ b/Source/Engine/Platform/Base/PlatformBase.cpp @@ -294,11 +294,6 @@ PlatformType PlatformBase::GetPlatformType() #if !PLATFORM_SDL -String PlatformBase::GetDisplayServer() -{ - return String::Empty; -} - bool PlatformBase::SupportsNativeDecorations() { return true; diff --git a/Source/Engine/Platform/Base/PlatformBase.h b/Source/Engine/Platform/Base/PlatformBase.h index 87e2217c2..90bf8690e 100644 --- a/Source/Engine/Platform/Base/PlatformBase.h +++ b/Source/Engine/Platform/Base/PlatformBase.h @@ -369,11 +369,6 @@ public: /// API_PROPERTY() static PlatformType GetPlatformType(); - /// - /// Returns the display server name on Linux. - /// - API_PROPERTY() static String GetDisplayServer(); - /// /// Returns true if system provides decorations for windows. /// diff --git a/Source/Engine/Platform/GDK/GDKPlatform.h b/Source/Engine/Platform/GDK/GDKPlatform.h index de24458a3..e2c23dbf3 100644 --- a/Source/Engine/Platform/GDK/GDKPlatform.h +++ b/Source/Engine/Platform/GDK/GDKPlatform.h @@ -9,6 +9,7 @@ /// /// The GDK platform implementation and application management utilities. /// +API_CLASS(Static, Tag="NoTypeInitializer") class FLAXENGINE_API GDKPlatform : public Win32Platform { public: @@ -37,10 +38,13 @@ public: /// The Win32 application instance. static void PreInit(void* hInstance); - static bool IsRunningOnDevKit(); - - static void SignInSilently(); - static void SignInWithUI(); + // True, if game is running Xbox Devkit. + API_PROPERTY() static bool IsRunningOnDevKit(); + // Signs in user without showing UI. If user is not signed in, it will fail and return false. Use SignInWithUI to show UI and let user sign in. + API_FUNCTION() static void SignInSilently(); + // Signs in user with showing UI. If user is already signed in, it will succeed and return true. If user is not signed in, it will show UI and let user sign in. + API_FUNCTION() static void SignInWithUI(); + // Searches for a user with a specific local ID. static User* FindUser(const struct XUserLocalId& id); public: diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index 7d38e0c07..d3358a2e7 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -1801,6 +1801,11 @@ const String& LinuxPlatform::GetHomeDirectory() return HomeDir; } +String LinuxPlatform::GetDisplayServer() +{ + return xDisplay ? TEXT("X11") : TEXT(""); +} + bool LinuxPlatform::Is64BitPlatform() { #ifdef PLATFORM_64BITS diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.h b/Source/Engine/Platform/Linux/LinuxPlatform.h index 422a6dbfa..6c857ccf9 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.h +++ b/Source/Engine/Platform/Linux/LinuxPlatform.h @@ -10,6 +10,7 @@ /// /// The Linux platform implementation and application management utilities. /// +API_CLASS(Static, Tag="NoTypeInitializer") class FLAXENGINE_API LinuxPlatform : public UnixPlatform { public: @@ -30,9 +31,13 @@ public: /// /// Gets the current user home directory. /// - /// The user home directory. static const String& GetHomeDirectory(); + /// + /// Returns the display server name on Linux (eg. X11, Wayland). + /// + API_PROPERTY() static String GetDisplayServer(); + /// /// An event that is fired when an XEvent is received during platform tick. /// diff --git a/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp b/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp index a30034d7a..d762c90d7 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.Linux.cpp @@ -1691,6 +1691,14 @@ void* SDLPlatform::GetXDisplay() return X11Impl::xDisplay; } +String SDLPlatform::GetDisplayServer() +{ + String driver(SDL_GetCurrentVideoDriver()); + if (driver.Length() > 0) + driver[0] = StringUtils::ToUpper(driver[0]); + return driver; +} + void SDLPlatform::SetHighDpiAwarenessEnabled(bool enable) { base::SetHighDpiAwarenessEnabled(enable); diff --git a/Source/Engine/Platform/SDL/SDLPlatform.cpp b/Source/Engine/Platform/SDL/SDLPlatform.cpp index 6645e106a..9f8d46c2b 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.cpp @@ -196,18 +196,6 @@ bool SDLPlatform::HandleEvent(SDL_Event& event) return true; } -String SDLPlatform::GetDisplayServer() -{ -#if PLATFORM_LINUX - String driver(SDL_GetCurrentVideoDriver()); - if (driver.Length() > 0) - driver[0] = StringUtils::ToUpper(driver[0]); - return driver; -#else - return String::Empty; -#endif -} - bool SDLPlatform::SupportsNativeDecorations() { return SDLImpl::WindowDecorationsSupported; diff --git a/Source/Engine/Platform/SDL/SDLPlatform.h b/Source/Engine/Platform/SDL/SDLPlatform.h index cfb308677..d253ebb2e 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.h +++ b/Source/Engine/Platform/SDL/SDLPlatform.h @@ -62,18 +62,17 @@ private: public: #if PLATFORM_LINUX static void* GetXDisplay(); + static String GetDisplayServer(); #endif static bool UsesWindows(); static bool UsesWayland(); static bool UsesX11(); public: - // [PlatformBase] static bool Init(); static void LogInfo(); static void Tick(); - static String GetDisplayServer(); static bool SupportsNativeDecorations(); static bool SupportsNativeDecorationDragging(); static void SetHighDpiAwarenessEnabled(bool enable); diff --git a/Source/Tools/Flax.Build/Bindings/ApiTypeInfo.cs b/Source/Tools/Flax.Build/Bindings/ApiTypeInfo.cs index 55aea31d6..9e2bca779 100644 --- a/Source/Tools/Flax.Build/Bindings/ApiTypeInfo.cs +++ b/Source/Tools/Flax.Build/Bindings/ApiTypeInfo.cs @@ -126,6 +126,11 @@ namespace Flax.Build.Bindings } } + public bool HasTag(string tag) + { + return Tags != null && Tags.ContainsKey(tag); + } + public string GetTag(string tag) { if (Tags != null && Tags.TryGetValue(tag, out var value)) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs index 3de1c488d..91e8d5f26 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.Cpp.cs @@ -1220,7 +1220,7 @@ namespace Flax.Build.Bindings if (functionInfo.IsStatic) { // Call native static method - string nativeType = caller.Tags != null && caller.Tags.ContainsKey("NativeInvokeUseName") ? caller.Name : caller.NativeName; + string nativeType = caller.HasTag("NativeInvokeUseName") ? caller.Name : caller.NativeName; if (caller.Parent != null && !(caller.Parent is FileInfo)) nativeType = caller.Parent.FullNameNative + "::" + nativeType; call = $"{nativeType}::{functionInfo.Name}"; @@ -2363,6 +2363,8 @@ namespace Flax.Build.Bindings var interfacesTable = GenerateCppInterfaceInheritanceTable(buildData, contents, moduleInfo, classInfo, classTypeNameNative, classTypeNameInternal); // Type initializer + if (classInfo.HasTag("NoTypeInitializer")) + return; if (GenerateCppIsTemplateInstantiationType(classInfo)) contents.Append("template<> "); contents.Append($"ScriptingTypeInitializer {classTypeNameNative}::TypeInitializer((BinaryModule*)GetBinaryModule{moduleInfo.Name}(), ");