Skip to content

Commit

Permalink
Merge pull request ppy#5452 from frenzibyte/fix-sdl-client-size
Browse files Browse the repository at this point in the history
Fix window size properties not correct on Hi-DPI screens
  • Loading branch information
peppy authored Oct 21, 2022
2 parents c464502 + f7d3694 commit a44cf7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion osu.Framework.Tests/Visual/Platform/TestSceneBorderless.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void load(FrameworkConfigManager config, GameHost host)
// set up window
AddStep("switch to windowed", () => windowMode.Value = WindowMode.Windowed);
AddStep($"move window to display {display.Index}", () => window.CurrentDisplayBindable.Value = window.Displays.ElementAt(display.Index));
AddStep("set client size to 1280x720", () => config.SetValue(FrameworkSetting.WindowedSize, new Size(1280, 720)));
AddStep("set window size to 1280x720", () => config.SetValue(FrameworkSetting.WindowedSize, new Size(1280, 720)));
AddStep("store window position", () => originalWindowPosition = window.Position);

// borderless alignment tests
Expand Down
20 changes: 9 additions & 11 deletions osu.Framework/Platform/SDL2DesktopWindow_Windowing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public WindowState WindowState
/// <summary>
/// Returns the drawable area, after scaling.
/// </summary>
public Size ClientSize => new Size(Size.Width, Size.Height);
public Size ClientSize => new Size((int)(Size.Width * Scale), (int)(Size.Height * Scale));

public float Scale = 1;

Expand Down Expand Up @@ -418,15 +418,15 @@ private Rectangle windowDisplayBounds
/// <returns>Whether the window size has been changed after updating.</returns>
private void fetchWindowSize()
{
SDL.SDL_GL_GetDrawableSize(SDLWindowHandle, out int w, out int h);
SDL.SDL_GetWindowSize(SDLWindowHandle, out int actualW, out int _);
SDL.SDL_GetWindowSize(SDLWindowHandle, out int w, out int h);
SDL.SDL_GL_GetDrawableSize(SDLWindowHandle, out int drawableW, out int _);

// When minimised on windows, values may be zero.
// If we receive zeroes for either of these, it seems safe to completely ignore them.
if (actualW <= 0 || w <= 0)
if (w <= 0 || drawableW <= 0)
return;

Scale = (float)w / actualW;
Scale = (float)drawableW / w;
Size = new Size(w, h);

// This function may be invoked before the SDL internal states are all changed. (as documented here: https://wiki.libsdl.org/SDL_SetEventFilter)
Expand Down Expand Up @@ -550,10 +550,10 @@ private void updateWindowStateAndSize(WindowState windowState, Display display,
switch (windowState)
{
case WindowState.Normal:
Size = (sizeWindowed.Value * Scale).ToSize();
Size = sizeWindowed.Value;

SDL.SDL_RestoreWindow(SDLWindowHandle);
SDL.SDL_SetWindowSize(SDLWindowHandle, sizeWindowed.Value.Width, sizeWindowed.Value.Height);
SDL.SDL_SetWindowSize(SDLWindowHandle, Size.Width, Size.Height);
SDL.SDL_SetWindowResizable(SDLWindowHandle, Resizable ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE);

readWindowPositionFromConfig(windowState, display);
Expand All @@ -580,9 +580,7 @@ private void updateWindowStateAndSize(WindowState windowState, Display display,
ensureWindowOnDisplay(display);

SDL.SDL_MaximizeWindow(SDLWindowHandle);

SDL.SDL_GL_GetDrawableSize(SDLWindowHandle, out int w, out int h);
Size = new Size(w, h);
fetchWindowSize();
break;

case WindowState.Minimised:
Expand Down Expand Up @@ -699,7 +697,7 @@ private void storeWindowSizeToConfig()
return;

storingSizeToConfig = true;
sizeWindowed.Value = (Size / Scale).ToSize();
sizeWindowed.Value = Size;
storingSizeToConfig = false;
}

Expand Down

0 comments on commit a44cf7e

Please sign in to comment.