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

Merged
merged 6 commits into from
Dec 2, 2024
Merged
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
2 changes: 1 addition & 1 deletion osu.Framework/Platform/SDL3/SDL3Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
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 @@ -149,10 +149,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 @@ -447,7 +444,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);
Expand All @@ -462,7 +459,8 @@ private unsafe void fetchWindowSize()
Scale = (float)drawableW / w;
Size = new Size(w, h);

storeWindowSizeToConfig();
if (storeToConfig)
storeWindowSizeToConfig();
}

#region SDL Event Handling
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 @@ -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