Skip to content

Commit

Permalink
Merge pull request #6264 from Susko3/bring-back-borderless
Browse files Browse the repository at this point in the history
Bring back borderless mode for macOS and Linux
  • Loading branch information
peppy authored Dec 2, 2024
2 parents 0665828 + ff2ee9d commit 5743c6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
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);

return display.Bounds.Size;
}

#endregion

Expand Down

0 comments on commit 5743c6e

Please sign in to comment.