Skip to content

Commit 2e4d2ce

Browse files
authored
Add option to disable automatic resize of main window (squashed PR #4011)
* Add option to disable automatic main window resize * Add option to window size submenu * Rename parameter to `forceWindowResize` * Add XML doc comments * Save main window size * Make `Config.MainWndx `/`MainWndy` nullable * Reduce total diff size * Move cast inside of `foreach` * Remove obsolete workaround Position isn't saved anymore when minimized * Combine config values into `Point` and `Size` * Add `Point` and `Size` to known good serializable types * Remove doc comment from implementation
1 parent d0482ac commit 2e4d2ce

File tree

8 files changed

+65
-37
lines changed

8 files changed

+65
-37
lines changed

src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void SetWindowSize(int size)
197197
if (size == 1 || size == 2 || size == 3 || size == 4 || size == 5 || size == 10)
198198
{
199199
_config.SetWindowScaleFor(Emulator.SystemId, size);
200-
_mainForm.FrameBufferResized();
200+
_mainForm.FrameBufferResized(forceWindowResize: true);
201201
_displayManager.OSD.AddMessage($"Window size set to {size}x");
202202
}
203203
else

src/BizHawk.Client.Common/IMainFormForApi.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public interface IMainFormForApi
5353
/// <remarks>only referenced from <c>EmuClientApi</c></remarks>
5454
void FrameAdvance(bool discardApiHawkSurfaces = true);
5555

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

5859
void FrameSkipMessage();
5960

src/BizHawk.Client.Common/config/Config.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Drawing;
23
using System.IO;
34

45
using BizHawk.Bizware.Graphics;
@@ -139,8 +140,8 @@ public void SetWindowScaleFor(string sysID, int windowScale)
139140
public bool MainFormStayOnTop { get; set; }
140141
public bool StartPaused { get; set; }
141142
public bool StartFullscreen { get; set; }
142-
public int MainWndx { get; set; } = -1; // Negative numbers will be ignored
143-
public int MainWndy { get; set; } = -1;
143+
public Point? MainWindowPosition { get; set; }
144+
public Size? MainWindowSize { get; set; }
144145
public bool RunInBackground { get; set; } = true;
145146
public bool AcceptBackgroundInput { get; set; }
146147
public bool AcceptBackgroundInputControllerOnly { get; set; }
@@ -277,6 +278,11 @@ public void SetWindowScaleFor(string sysID, int windowScale)
277278
public int DispCropRight { get; set; } = 0;
278279
public int DispCropBottom { get; set; } = 0;
279280

281+
/// <summary>
282+
/// Automatically resize main window when framebuffer size changes (default behavior)
283+
/// </summary>
284+
public bool ResizeWithFramebuffer { get; set; } = true;
285+
280286
// Sound options
281287
public ESoundOutputMethod SoundOutputMethod { get; set; } = HostCapabilityDetector.HasXAudio2 ? ESoundOutputMethod.XAudio2 : ESoundOutputMethod.OpenAL;
282288

src/BizHawk.Client.EmuHawk/IMainFormForTools.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public interface IMainFormForTools : IDialogController
5858
void FrameAdvance(bool discardApiHawkSurfaces = true);
5959

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

6364
/// <remarks>only referenced from <see cref="BasicBot"/></remarks>
6465
bool LoadQuickSave(int slot, bool suppressOSD = false);

src/BizHawk.Client.EmuHawk/MainForm.Designer.cs

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BizHawk.Client.EmuHawk/MainForm.Events.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -611,16 +611,27 @@ private void ViewSubMenu_DropDownOpened(object sender, EventArgs e)
611611
private void WindowSizeSubMenu_DropDownOpened(object sender, EventArgs e)
612612
{
613613
var windowScale = Config.GetWindowScaleFor(Emulator.SystemId);
614-
foreach (ToolStripMenuItem item in WindowSizeSubMenu.DropDownItems)
614+
foreach (var item in WindowSizeSubMenu.DropDownItems)
615615
{
616-
item.Checked = (int) item.Tag == windowScale;
616+
// filter out separators
617+
if (item is ToolStripMenuItem menuItem && menuItem.Tag is int itemScale)
618+
{
619+
menuItem.Checked = itemScale == windowScale && Config.ResizeWithFramebuffer;
620+
}
617621
}
622+
DisableResizeWithFramebufferMenuItem.Checked = !Config.ResizeWithFramebuffer;
623+
}
624+
625+
private void DisableResizeWithFramebufferMenuItem_Click(object sender, EventArgs e)
626+
{
627+
Config.ResizeWithFramebuffer = !DisableResizeWithFramebufferMenuItem.Checked;
628+
FrameBufferResized();
618629
}
619630

620631
private void WindowSize_Click(object sender, EventArgs e)
621632
{
622633
Config.SetWindowScaleFor(Emulator.SystemId, (int) ((ToolStripMenuItem) sender).Tag);
623-
FrameBufferResized();
634+
FrameBufferResized(forceWindowResize: true);
624635
}
625636

626637
private void SwitchToFullscreenMenuItem_Click(object sender, EventArgs e)

src/BizHawk.Client.EmuHawk/MainForm.cs

+22-29
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ private void MainForm_Load(object sender, EventArgs e)
6161
{
6262
UpdateWindowTitle();
6363

64-
ToolStripItem[] CreateWindowSizeFactorSubmenus()
6564
{
66-
var items = new ToolStripItem[WINDOW_SCALE_MAX];
6765
for (int i = 1; i <= WINDOW_SCALE_MAX; i++)
6866
{
6967
long quotient = Math.DivRem(i, 10, out long remainder);
@@ -73,11 +71,9 @@ ToolStripItem[] CreateWindowSizeFactorSubmenus()
7371
Text = $"{(quotient > 0 ? quotient : "")}&{remainder}x"
7472
};
7573
temp.Click += this.WindowSize_Click;
76-
items[i - 1] = temp;
74+
WindowSizeSubMenu.DropDownItems.Insert(i - 1, temp);
7775
}
78-
return items;
7976
}
80-
WindowSizeSubMenu.DropDownItems.AddRange(CreateWindowSizeFactorSubmenus());
8177

8278
foreach (var (appliesTo, coreNames) in Config.CorePickerUIData)
8379
{
@@ -603,20 +599,17 @@ _argParser.SocketAddress is var (socketIP, socketPort)
603599
CheatList.Changed += Tools.UpdateCheatRelatedTools;
604600
RewireSound();
605601

606-
// Workaround for windows, location is -32000 when minimized, if they close it during this time, that's what gets saved
607-
if (Config.MainWndx == -32000)
608-
{
609-
Config.MainWndx = 0;
610-
}
611-
612-
if (Config.MainWndy == -32000)
602+
if (Config.SaveWindowPosition)
613603
{
614-
Config.MainWndy = 0;
615-
}
604+
if (Config.MainWindowPosition is Point position)
605+
{
606+
Location = position;
607+
}
616608

617-
if (Config.MainWndx != -1 && Config.MainWndy != -1 && Config.SaveWindowPosition)
618-
{
619-
Location = new Point(Config.MainWndx, Config.MainWndy);
609+
if (Config.MainWindowSize is Size size && !Config.ResizeWithFramebuffer)
610+
{
611+
Size = size;
612+
}
620613
}
621614

622615
if (Config.MainFormStayOnTop) TopMost = true;
@@ -1395,8 +1388,12 @@ public void TakeScreenshot(string path)
13951388
AddOnScreenMessage($"{fi.Name} saved.");
13961389
}
13971390

1398-
public void FrameBufferResized()
1391+
public void FrameBufferResized(bool forceWindowResize = false)
13991392
{
1393+
if (!Config.ResizeWithFramebuffer && !forceWindowResize)
1394+
{
1395+
return;
1396+
}
14001397
// run this entire thing exactly twice, since the first resize may adjust the menu stacking
14011398
for (int i = 0; i < 2; i++)
14021399
{
@@ -2422,20 +2419,16 @@ private void SaveConfig(string path = "")
24222419
{
24232420
if (Config.SaveWindowPosition)
24242421
{
2425-
if (Config.MainWndx != -32000) // When minimized location is -32000, don't save this into the config file!
2426-
{
2427-
Config.MainWndx = Location.X;
2428-
}
2429-
2430-
if (Config.MainWndy != -32000)
2422+
if (WindowState is FormWindowState.Normal)
24312423
{
2432-
Config.MainWndy = Location.Y;
2424+
Config.MainWindowPosition = Location;
2425+
Config.MainWindowSize = Size;
24332426
}
24342427
}
24352428
else
24362429
{
2437-
Config.MainWndx = -1;
2438-
Config.MainWndy = -1;
2430+
Config.MainWindowPosition = null;
2431+
Config.MainWindowSize = null;
24392432
}
24402433

24412434
Config.LastWrittenFrom = VersionInfo.MainVersion;
@@ -2591,7 +2584,7 @@ private void IncreaseWindowSize()
25912584
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
25922585
}
25932586
AddOnScreenMessage($"Screensize set to {windowScale}x");
2594-
FrameBufferResized();
2587+
FrameBufferResized(forceWindowResize: true);
25952588
}
25962589

25972590
private void DecreaseWindowSize()
@@ -2603,7 +2596,7 @@ private void DecreaseWindowSize()
26032596
Config.SetWindowScaleFor(Emulator.SystemId, windowScale);
26042597
}
26052598
AddOnScreenMessage($"Screensize set to {windowScale}x");
2606-
FrameBufferResized();
2599+
FrameBufferResized(forceWindowResize: true);
26072600
}
26082601

26092602
private static readonly int[] SpeedPercents = { 1, 3, 6, 12, 25, 50, 75, 100, 150, 200, 300, 400, 800, 1600, 3200, 6400 };

src/BizHawk.Tests/Client.Common/config/SerializationStabilityTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Drawing;
23
using System.Reflection;
34

45
using BizHawk.Client.Common;
@@ -32,8 +33,10 @@ public sealed class SerializationStabilityTests
3233
typeof(List<>),
3334
typeof(Nullable<>),
3435
typeof(object),
36+
typeof(Point),
3537
typeof(Queue<>),
3638
typeof(float),
39+
typeof(Size),
3740
typeof(string),
3841
};
3942

0 commit comments

Comments
 (0)