Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back borderless mode for macOS and Linux #6264

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions osu.Framework/Platform/SDL3/SDL3Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,16 +860,17 @@ 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;

if (windowFlags.HasFlagFast(SDL_WindowFlags.SDL_WINDOW_MINIMIZED))
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;
Expand Down
23 changes: 15 additions & 8 deletions osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,10 +150,7 @@ public virtual IEnumerable<WindowMode> SupportedWindowModes
if (RuntimeInfo.IsMobile)
return new[] { Configuration.WindowMode.Fullscreen };

if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
return Enum.GetValues<WindowMode>();

return new[] { Configuration.WindowMode.Windowed, Configuration.WindowMode.Fullscreen };
return Enum.GetValues<WindowMode>();
}
}

Expand Down Expand Up @@ -583,7 +581,7 @@ private unsafe void updateAndFetchWindowSpecifics()
}
else
{
windowState = SDL_GetWindowFlags(SDLWindowHandle).ToWindowState();
windowState = SDL_GetWindowFlags(SDLWindowHandle).ToWindowState(SDL_GetWindowFullscreenMode(SDLWindowHandle) == null);
}

if (windowState != stateBefore)
Expand Down Expand Up @@ -788,9 +786,9 @@ private void storeWindowPositionToConfig()
/// </remarks>
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))
Comment on lines +789 to +791
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this line makes me unsure whether WindowState can be correct anywhere, regardless of whether there is a comment explaining why this is being done. Thoughts on just not calling this method from the SDL_EVENT_WINDOW_RESIZED path?

Given that we know that path is not safe to read any states of the window, and is only meant to update the size of the window without doing anything else, I think it makes more sense that we just change that path to not do any storing of window size.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WindowState is probably invalid here as this is called from the event watch. Makes sense to avoid storing the size then.

Give it a test on TestSceneWindowed:

diff --git a/osu.Framework/Platform/SDL3/SDL3Window.cs b/osu.Framework/Platform/SDL3/SDL3Window.cs
index bb03b6093..33e509828 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 8007a4a71..33f5a3512 100644
--- a/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs
+++ b/osu.Framework/Platform/SDL3/SDL3Window_Windowing.cs
@@ -445,7 +445,7 @@ private unsafe Rectangle windowDisplayBounds
         /// Updates <see cref="Size"/> and <see cref="Scale"/> according to SDL state.
         /// </summary>
         /// <returns>Whether the window size has been changed after updating.</returns>
-        private unsafe void fetchWindowSize()
+        private unsafe void fetchWindowSize(bool storeToConfig = true)
         {
             int w, h;
             SDL_GetWindowSize(SDLWindowHandle, &w, &h);
@@ -460,7 +460,8 @@ private unsafe void fetchWindowSize()
             Scale = (float)drawableW / w;
             Size = new Size(w, h);
 
-            storeWindowSizeToConfig();
+            if (storeToConfig)
+                storeWindowSizeToConfig();
         }
 
         #region SDL Event Handling
@@ -788,7 +789,7 @@ private void storeWindowPositionToConfig()
 
         private unsafe void storeWindowSizeToConfig()
         {
-            if (WindowState != WindowState.Normal || SDL_GetWindowFlags(SDLWindowHandle).HasFlagFast(SDL_WindowFlags.SDL_WINDOW_FULLSCREEN))
+            if (WindowState != WindowState.Normal)
                 return;
 
             storingSizeToConfig = true;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to work as expected.

return;

storingSizeToConfig = true;
Expand All @@ -805,7 +803,16 @@ private void storeWindowSizeToConfig()
/// <returns>
/// The size of the borderless window's draw area.
/// </returns>
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.
SDL_SetWindowFullscreenMode(SDLWindowHandle, null);
SDL_SetWindowFullscreen(SDLWindowHandle, true);
frenzibyte marked this conversation as resolved.
Show resolved Hide resolved

return display.Bounds.Size;
}

#endregion

Expand Down
Loading