From f3dfc4ad4e8e103802e4f791ea2215a286812668 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Mon, 22 Apr 2024 21:06:27 +0200 Subject: [PATCH 1/5] 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 From 623eef711948cc4909c275d36cef0b2f7becc860 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Fri, 22 Nov 2024 21:06:18 +0000 Subject: [PATCH 2/5] Fix merge fail --- osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs b/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs index 2a2fd94181..c3622b6b06 100644 --- a/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs +++ b/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs @@ -806,6 +806,8 @@ 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. + SDL_SetWindowFullscreenMode(SDLWindowHandle, null); SDL_SetWindowFullscreen(SDLWindowHandle, true); return display.Bounds.Size; From 63b05d46e2281aaff32f6a4657839f25d3306aba Mon Sep 17 00:00:00 2001 From: Susko3 Date: Fri, 22 Nov 2024 23:34:30 +0000 Subject: [PATCH 3/5] Don't store windowed size when in fullscreen WindowState can sometimes be stale as `storeWindowSizeToConfig()` may be called from `HandleEventFromWatch()`. --- osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs b/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs index c3622b6b06..8007a4a710 100644 --- a/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs +++ b/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs @@ -10,6 +10,7 @@ using System.Linq; using osu.Framework.Bindables; using osu.Framework.Configuration; +using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Logging; using osuTK; using SDL; @@ -785,9 +786,9 @@ private void storeWindowPositionToConfig() /// private bool updatingWindowStateAndSize; - private void storeWindowSizeToConfig() + private unsafe void storeWindowSizeToConfig() { - if (WindowState != WindowState.Normal) + if (WindowState != WindowState.Normal || SDL_GetWindowFlags(SDLWindowHandle).HasFlagFast(SDL_WindowFlags.SDL_WINDOW_FULLSCREEN)) return; storingSizeToConfig = true; From 282f21ad0191b9f7bffd533c44ddac43e24cd3fb Mon Sep 17 00:00:00 2001 From: Susko3 Date: Mon, 25 Nov 2024 12:26:34 +0000 Subject: [PATCH 4/5] Revert "Don't store windowed size when in fullscreen" This reverts commit 63b05d46e2281aaff32f6a4657839f25d3306aba. --- osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs b/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs index 8007a4a710..c3622b6b06 100644 --- a/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs +++ b/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs @@ -10,7 +10,6 @@ using System.Linq; using osu.Framework.Bindables; using osu.Framework.Configuration; -using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Logging; using osuTK; using SDL; @@ -786,9 +785,9 @@ private void storeWindowPositionToConfig() /// private bool updatingWindowStateAndSize; - private unsafe void storeWindowSizeToConfig() + private void storeWindowSizeToConfig() { - if (WindowState != WindowState.Normal || SDL_GetWindowFlags(SDLWindowHandle).HasFlagFast(SDL_WindowFlags.SDL_WINDOW_FULLSCREEN)) + if (WindowState != WindowState.Normal) return; storingSizeToConfig = true; From ff2ee9db1de3c44aa5b185477bd12e9a847bc5e0 Mon Sep 17 00:00:00 2001 From: Susko3 Date: Mon, 25 Nov 2024 12:31:42 +0000 Subject: [PATCH 5/5] Don't store windowed size to config from event watch --- osu.Framework/Platform/SDL3/SDL3Window.cs | 2 +- osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Framework/Platform/SDL3/SDL3Window.cs b/osu.Framework/Platform/SDL3/SDL3Window.cs index bb03b60937..33e509828f 100644 --- a/osu.Framework/Platform/SDL3/SDL3Window.cs +++ b/osu.Framework/Platform/SDL3/SDL3Window.cs @@ -316,7 +316,7 @@ protected void HandleEventFromWatch(SDL_Event evt) case SDL_EventType.SDL_EVENT_WINDOW_RESIZED: // polling via SDL_PollEvent blocks on resizes (https://stackoverflow.com/a/50858339) if (!updatingWindowStateAndSize) - fetchWindowSize(); + fetchWindowSize(storeToConfig: false); break; } diff --git a/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs b/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs index c3622b6b06..42b79980dc 100644 --- a/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs +++ b/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs @@ -444,7 +444,7 @@ private unsafe Rectangle windowDisplayBounds /// Updates and according to SDL state. /// /// Whether the window size has been changed after updating. - private unsafe void fetchWindowSize() + private unsafe void fetchWindowSize(bool storeToConfig = true) { int w, h; SDL_GetWindowSize(SDLWindowHandle, &w, &h); @@ -459,7 +459,8 @@ private unsafe void fetchWindowSize() Scale = (float)drawableW / w; Size = new Size(w, h); - storeWindowSizeToConfig(); + if (storeToConfig) + storeWindowSizeToConfig(); } #region SDL Event Handling