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

Main window auto-size fixes #4029

Merged
merged 3 commits into from
Sep 13, 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
1 change: 1 addition & 0 deletions src/BizHawk.Client.Common/config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public void SetWindowScaleFor(string sysID, int windowScale)
public bool StartFullscreen { get; set; }
public Point? MainWindowPosition { get; set; }
public Size? MainWindowSize { get; set; }
public bool MainWindowMaximized { get; set; }
public bool RunInBackground { get; set; } = true;
public bool AcceptBackgroundInput { get; set; }
public bool AcceptBackgroundInputControllerOnly { get; set; }
Expand Down
5 changes: 5 additions & 0 deletions src/BizHawk.Client.EmuHawk/MainForm.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,11 @@ private void MainForm_Enter(object sender, EventArgs e)
private void MainForm_Resize(object sender, EventArgs e)
{
_presentationPanel.Resized = true;
if (_framebufferResizedPending && WindowState is FormWindowState.Normal)
{
_framebufferResizedPending = false;
FrameBufferResized();
}
}

private void MainForm_Shown(object sender, EventArgs e)
Expand Down
20 changes: 18 additions & 2 deletions src/BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ _argParser.SocketAddress is var (socketIP, socketPort)
{
Size = size;
}

if (Config.MainWindowMaximized)
{
WindowState = FormWindowState.Maximized;
}
}

if (Config.MainFormStayOnTop) TopMost = true;
Expand Down Expand Up @@ -1390,6 +1395,12 @@ public void TakeScreenshot(string path)

public void FrameBufferResized(bool forceWindowResize = false)
{
if (WindowState is not FormWindowState.Normal)
{
// Wait until no longer maximized/minimized to get correct size/location values
_framebufferResizedPending = true;
return;
}
if (!Config.ResizeWithFramebuffer && !forceWindowResize)
{
return;
Expand Down Expand Up @@ -1427,14 +1438,17 @@ public void FrameBufferResized(bool forceWindowResize = false)
// Is window off the screen at this size?
if (!area.Contains(Bounds))
{
// At large framebuffer sizes/low screen resolutions, the window may be too large to fit the screen even at 1x scale
// Prioritize that the top-left of the window is on-screen so the title bar and menu stay accessible

if (Bounds.Right > area.Right) // Window is off the right edge
{
Location = new Point(area.Right - Size.Width, Location.Y);
Left = Math.Max(area.Right - Size.Width, area.Left);
}

if (Bounds.Bottom > area.Bottom) // Window is off the bottom edge
{
Location = new Point(Location.X, area.Bottom - Size.Height);
Top = Math.Max(area.Bottom - Size.Height, area.Top);
}
}
}
Expand Down Expand Up @@ -1692,6 +1706,7 @@ public bool RunLibretroCoreChooser()
private bool _inFullscreen;
private Point _windowedLocation;
private bool _needsFullscreenOnLoad;
private bool _framebufferResizedPending;

private int _lastOpenRomFilter;

Expand Down Expand Up @@ -2424,6 +2439,7 @@ private void SaveConfig(string path = "")
Config.MainWindowPosition = Location;
Config.MainWindowSize = Size;
}
Config.MainWindowMaximized = WindowState is FormWindowState.Maximized && !_inFullscreen;
}
else
{
Expand Down