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

Add option to disable automatic resize of main window #4011

Merged
merged 12 commits into from
Sep 13, 2024
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void SetWindowSize(int size)
if (size == 1 || size == 2 || size == 3 || size == 4 || size == 5 || size == 10)
{
_config.SetWindowScaleFor(Emulator.SystemId, size);
_mainForm.FrameBufferResized();
_mainForm.FrameBufferResized(forceWindowResize: true);
_displayManager.OSD.AddMessage($"Window size set to {size}x");
}
else
Expand Down
3 changes: 2 additions & 1 deletion src/BizHawk.Client.Common/IMainFormForApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public interface IMainFormForApi
/// <remarks>only referenced from <c>EmuClientApi</c></remarks>
void FrameAdvance(bool discardApiHawkSurfaces = true);

void FrameBufferResized();
/// <param name="forceWindowResize">Override <see cref="Common.Config.ResizeWithFramebuffer"/></param>
void FrameBufferResized(bool forceWindowResize = false);

void FrameSkipMessage();

Expand Down
10 changes: 8 additions & 2 deletions src/BizHawk.Client.Common/config/Config.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;

using BizHawk.Bizware.Graphics;
Expand Down Expand Up @@ -136,8 +137,8 @@ public void SetWindowScaleFor(string sysID, int windowScale)
public bool MainFormStayOnTop { get; set; }
public bool StartPaused { get; set; }
public bool StartFullscreen { get; set; }
public int MainWndx { get; set; } = -1; // Negative numbers will be ignored
public int MainWndy { get; set; } = -1;
public Point? MainWindowPosition { get; set; }
public Size? MainWindowSize { get; set; }
kalimag marked this conversation as resolved.
Show resolved Hide resolved
public bool RunInBackground { get; set; } = true;
public bool AcceptBackgroundInput { get; set; }
public bool AcceptBackgroundInputControllerOnly { get; set; }
Expand Down Expand Up @@ -274,6 +275,11 @@ public void SetWindowScaleFor(string sysID, int windowScale)
public int DispCropRight { get; set; } = 0;
public int DispCropBottom { get; set; } = 0;

/// <summary>
/// Automatically resize main window when framebuffer size changes (default behavior)
/// </summary>
public bool ResizeWithFramebuffer { get; set; } = true;

// Sound options
public ESoundOutputMethod SoundOutputMethod { get; set; } = HostCapabilityDetector.HasXAudio2 ? ESoundOutputMethod.XAudio2 : ESoundOutputMethod.OpenAL;

Expand Down
3 changes: 2 additions & 1 deletion src/BizHawk.Client.EmuHawk/IMainFormForTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public interface IMainFormForTools : IDialogController
void FrameAdvance(bool discardApiHawkSurfaces = true);

/// <remarks>only referenced from <see cref="LuaConsole"/></remarks>
void FrameBufferResized();
/// <param name="forceWindowResize">Override <see cref="Common.Config.ResizeWithFramebuffer"/></param>
void FrameBufferResized(bool forceWindowResize = false);

/// <remarks>only referenced from <see cref="BasicBot"/></remarks>
bool LoadQuickSave(int slot, bool suppressOSD = false);
Expand Down
13 changes: 13 additions & 0 deletions src/BizHawk.Client.EmuHawk/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions src/BizHawk.Client.EmuHawk/MainForm.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,27 @@ private void ViewSubMenu_DropDownOpened(object sender, EventArgs e)
private void WindowSizeSubMenu_DropDownOpened(object sender, EventArgs e)
{
var windowScale = Config.GetWindowScaleFor(Emulator.SystemId);
foreach (ToolStripMenuItem item in WindowSizeSubMenu.DropDownItems)
foreach (var item in WindowSizeSubMenu.DropDownItems)
{
item.Checked = (int) item.Tag == windowScale;
// filter out separators
if (item is ToolStripMenuItem menuItem && menuItem.Tag is int itemScale)
{
menuItem.Checked = itemScale == windowScale && Config.ResizeWithFramebuffer;
}
}
DisableResizeWithFramebufferMenuItem.Checked = !Config.ResizeWithFramebuffer;
}

private void DisableResizeWithFramebufferMenuItem_Click(object sender, EventArgs e)
YoshiRulz marked this conversation as resolved.
Show resolved Hide resolved
{
Config.ResizeWithFramebuffer = !DisableResizeWithFramebufferMenuItem.Checked;
FrameBufferResized();
}

private void WindowSize_Click(object sender, EventArgs e)
{
Config.SetWindowScaleFor(Emulator.SystemId, (int) ((ToolStripMenuItem) sender).Tag);
FrameBufferResized();
FrameBufferResized(forceWindowResize: true);
}

private void SwitchToFullscreenMenuItem_Click(object sender, EventArgs e)
Expand Down
51 changes: 22 additions & 29 deletions src/BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ private void MainForm_Load(object sender, EventArgs e)
{
UpdateWindowTitle();

ToolStripItem[] CreateWindowSizeFactorSubmenus()
YoshiRulz marked this conversation as resolved.
Show resolved Hide resolved
{
var items = new ToolStripItem[WINDOW_SCALE_MAX];
for (int i = 1; i <= WINDOW_SCALE_MAX; i++)
{
long quotient = Math.DivRem(i, 10, out long remainder);
Expand All @@ -72,11 +70,9 @@ ToolStripItem[] CreateWindowSizeFactorSubmenus()
Text = $"{(quotient > 0 ? quotient : "")}&{remainder}x"
};
temp.Click += this.WindowSize_Click;
items[i - 1] = temp;
WindowSizeSubMenu.DropDownItems.Insert(i - 1, temp);
}
return items;
}
WindowSizeSubMenu.DropDownItems.AddRange(CreateWindowSizeFactorSubmenus());

foreach (var (appliesTo, coreNames) in Config.CorePickerUIData)
{
Expand Down Expand Up @@ -608,20 +604,17 @@ _argParser.SocketAddress is var (socketIP, socketPort)
CheatList.Changed += Tools.UpdateCheatRelatedTools;
RewireSound();

// Workaround for windows, location is -32000 when minimized, if they close it during this time, that's what gets saved
if (Config.MainWndx == -32000)
{
Config.MainWndx = 0;
}

if (Config.MainWndy == -32000)
if (Config.SaveWindowPosition)
{
Config.MainWndy = 0;
}
if (Config.MainWindowPosition is Point position)
{
Location = position;
}

if (Config.MainWndx != -1 && Config.MainWndy != -1 && Config.SaveWindowPosition)
{
Location = new Point(Config.MainWndx, Config.MainWndy);
if (Config.MainWindowSize is Size size && !Config.ResizeWithFramebuffer)
{
Size = size;
}
}

if (Config.MainFormStayOnTop) TopMost = true;
Expand Down Expand Up @@ -1372,8 +1365,12 @@ public void TakeScreenshot(string path)
AddOnScreenMessage($"{fi.Name} saved.");
}

public void FrameBufferResized()
public void FrameBufferResized(bool forceWindowResize = false)
YoshiRulz marked this conversation as resolved.
Show resolved Hide resolved
{
if (!Config.ResizeWithFramebuffer && !forceWindowResize)
{
return;
}
// run this entire thing exactly twice, since the first resize may adjust the menu stacking
for (int i = 0; i < 2; i++)
{
Expand Down Expand Up @@ -2399,20 +2396,16 @@ private void SaveConfig(string path = "")
{
if (Config.SaveWindowPosition)
{
if (Config.MainWndx != -32000) // When minimized location is -32000, don't save this into the config file!
{
Config.MainWndx = Location.X;
}

if (Config.MainWndy != -32000)
if (WindowState is FormWindowState.Normal)
{
Config.MainWndy = Location.Y;
Config.MainWindowPosition = Location;
Config.MainWindowSize = Size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify for anyone else: This preserves the existing behaviour of not updating the config in the edge case where EmuHawk is closed while already minimised.

}
}
else
{
Config.MainWndx = -1;
Config.MainWndy = -1;
Config.MainWindowPosition = null;
Config.MainWindowSize = null;
}

Config.LastWrittenFrom = VersionInfo.MainVersion;
Expand Down Expand Up @@ -2568,7 +2561,7 @@ private void IncreaseWindowSize()
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
}
AddOnScreenMessage($"Screensize set to {windowScale}x");
FrameBufferResized();
FrameBufferResized(forceWindowResize: true);
}

private void DecreaseWindowSize()
Expand All @@ -2580,7 +2573,7 @@ private void DecreaseWindowSize()
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
}
AddOnScreenMessage($"Screensize set to {windowScale}x");
FrameBufferResized();
FrameBufferResized(forceWindowResize: true);
}

private static readonly int[] SpeedPercents = { 1, 3, 6, 12, 25, 50, 75, 100, 150, 200, 300, 400, 800, 1600, 3200, 6400 };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;

using BizHawk.Client.Common;
Expand Down Expand Up @@ -32,8 +33,10 @@ public sealed class SerializationStabilityTests
typeof(List<>),
typeof(Nullable<>),
typeof(object),
typeof(Point),
typeof(Queue<>),
typeof(float),
typeof(Size),
typeof(string),
};

Expand Down