From f3dfc4ad4e8e103802e4f791ea2215a286812668 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Mon, 22 Apr 2024 21:06:27 +0200 Subject: [PATCH] Bring back borderless mode for macOS and Linux This partially reverts 0e78180d07a828fdad8655ea34efa89ff4744678 --- osu.Framework/Platform/SDL/SDL3Extensions.cs | 5 +++-- osu.Framework/Platform/SDL3Window_Windowing.cs | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/osu.Framework/Platform/SDL/SDL3Extensions.cs b/osu.Framework/Platform/SDL/SDL3Extensions.cs index abf451ce40..3c75634ba3 100644 --- a/osu.Framework/Platform/SDL/SDL3Extensions.cs +++ b/osu.Framework/Platform/SDL/SDL3Extensions.cs @@ -859,8 +859,9 @@ public static SDL_Scancode ToScancode(this InputKey inputKey) } } - public static WindowState ToWindowState(this SDL_WindowFlags windowFlags) + public static WindowState ToWindowState(this SDL_WindowFlags windowFlags, bool isFullscreenBorderless) { + // for windows if (windowFlags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_BORDERLESS)) return WindowState.FullscreenBorderless; @@ -868,7 +869,7 @@ public static WindowState ToWindowState(this SDL_WindowFlags windowFlags) return WindowState.Minimised; if (windowFlags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_FULLSCREEN)) - return WindowState.Fullscreen; + return isFullscreenBorderless ? WindowState.FullscreenBorderless : WindowState.Fullscreen; if (windowFlags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_MAXIMIZED)) return WindowState.Maximised; diff --git a/osu.Framework/Platform/SDL3Window_Windowing.cs b/osu.Framework/Platform/SDL3Window_Windowing.cs index 12150fda19..ad31c39f6e 100644 --- a/osu.Framework/Platform/SDL3Window_Windowing.cs +++ b/osu.Framework/Platform/SDL3Window_Windowing.cs @@ -146,10 +146,7 @@ public virtual IEnumerable SupportedWindowModes if (RuntimeInfo.IsMobile) return new[] { Configuration.WindowMode.Fullscreen }; - if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows) - return Enum.GetValues(); - - return new[] { Configuration.WindowMode.Windowed, Configuration.WindowMode.Fullscreen }; + return Enum.GetValues(); } } @@ -577,7 +574,7 @@ private unsafe void updateAndFetchWindowSpecifics() } else { - windowState = SDL3.SDL_GetWindowFlags(SDLWindowHandle).ToWindowState(); + windowState = SDL3.SDL_GetWindowFlags(SDLWindowHandle).ToWindowState(SDL3.SDL_GetWindowFullscreenMode(SDLWindowHandle) == null); } if (windowState != stateBefore) @@ -799,7 +796,16 @@ private void storeWindowSizeToConfig() /// /// The size of the borderless window's draw area. /// - protected virtual Size SetBorderless(Display display) => throw new PlatformNotSupportedException(); + protected virtual unsafe Size SetBorderless(Display display) + { + ensureWindowOnDisplay(display); + + // this is a generally sane method of handling borderless, and works well on macOS and linux. + SDL3.SDL_SetWindowFullscreenMode(SDLWindowHandle, null); + SDL3.SDL_SetWindowFullscreen(SDLWindowHandle, SDL_bool.SDL_TRUE); + + return display.Bounds.Size; + } #endregion