-
Notifications
You must be signed in to change notification settings - Fork 421
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
Conversation
This partially reverts 0e78180
@Joehuu please check if the borderless mode works as expected in this pull. |
Borderless itself seems to behave/work as expected (before SDL3) but windowed size gets maximised after toggling between the modes. Didn't happen in latest master. Screen.Recording.2024-04-22.at.12.50.50.PM.mov |
I'm also somewhat hesitant to add back borderless mode on macOS when it goes against how basically any other app works. |
If borderless isn't coming back then we should remove this game-side disclaimer. |
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding #6264 (comment), it appears that once the window is in borderless mode, it does not have the SDL_WINDOW_FULLSCREEN
flag set:
Therefore, the WindowState
is kept at normal even after the window has switched to borderless, and sizeWindowed
becomes corrupted as a result, causing the window to become maximised when returning from borderless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frenzibyte could you re-test this?
It's possible that this is because the window has not yet entered the fullscreen borderless mode due to animations still happening. Are the SDL window flags correct after the SDL_EVENT_WINDOW_ENTER_FULLSCREEN
event arrives?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can reproduce again, and the statement above seems correct. The following path is triggered before the SDL_EVENT_WINDOW_ENTER_FULLSCREEN
event, causing the size bindable to incorrectly store the borderless size:
osu-framework/osu.Framework/Platform/SDL3/SDL3Window.cs
Lines 316 to 321 in 316bbce
case SDL_EventType.SDL_EVENT_WINDOW_RESIZED: | |
// polling via SDL_PollEvent blocks on resizes (https://stackoverflow.com/a/50858339) | |
if (!updatingWindowStateAndSize) | |
fetchWindowSize(); | |
break; |
I recall there was something about SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED
being more reliable than SDL_EVENT_WINDOW_RESIZED
to get the window size while the window is in its final state, I'm not sure how correct that is right now.
All I can confirm is that SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED
gets called after SDL_EVENT_WINDOW_ENTER_FULLSCREEN
, and we have only been handling SDL_EVENT_WINDOW_RESIZED
so the game doesn't look weird when resizing it. Perhaps we can just not store the window size in the "resized" event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following path is triggered [...]
When this is triggered, what is the value of SDL_GetWindowFlags(SDLWindowHandle)
? Framework has cached a stale state, but what does SDL say?
Also please still check this:
Are the SDL window flags correct after the SDL_EVENT_WINDOW_ENTER_FULLSCREEN event arrives?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does have SDL_WINDOW_FULLSCREEN
when checking the flags at SDL_EVENT_WINDOW_RESIZED
, while WindowState
is indeed stale.
The next event triggered after resize is SDL_EVENT_WINDOW_ENTER_FULLSCREEN
, which is what updates the WindowState
to FullscreenBorderless
because of calling updateAndFetchWindowSpecifics()
I suppose, and yes the SDL window flags remains correct thereafter.
9c2e2a5
to
f3dfc4a
Compare
WindowState can sometimes be stale as `storeWindowSizeToConfig()` may be called from `HandleEventFromWatch()`.
private unsafe void storeWindowSizeToConfig() | ||
{ | ||
if (WindowState != WindowState.Normal) | ||
if (WindowState != WindowState.Normal || SDL_GetWindowFlags(SDLWindowHandle).HasFlagFast(SDL_WindowFlags.SDL_WINDOW_FULLSCREEN)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a tentative approval to say this is pretty much good from macOS's side, and will at least bring back a less-broken fullscreen mode. Leaving it to others as to whether this can get in or not.
Gonna merge this to keep things moving. |
Noticed when looking into #6262.
The SDL3 migration readme is cryptic about borderless being available:
Not only can you check if the used fullscreen mode will be borderless, you can also set it by passing
NULL
toSDL_SetWindowFullscreenMode
!