Fixes issue on restore window size after maximize causing width shrinking

This commit is contained in:
BDisp
2025-07-30 22:50:33 +01:00
parent 50cfa71445
commit 88bf87b8bb
3 changed files with 28 additions and 12 deletions

View File

@@ -632,6 +632,13 @@ internal partial class WindowsConsole
return new (winRect.Right + 1, newRows - 1 < 0 ? 0 : winRect.Bottom + 1);
}
internal Size GetLargestConsoleWindowSize ()
{
Coord maxWinSize = GetLargestConsoleWindowSize (IsVirtualTerminal ? _outputHandle : _screenBuffer);
return new (maxWinSize.X, maxWinSize.Y);
}
private void SetConsoleOutputWindow (CONSOLE_SCREEN_BUFFER_INFOEX csbi)
{
if ((IsVirtualTerminal

View File

@@ -420,9 +420,9 @@ internal class WindowsDriver : ConsoleDriver
{
if (WinConsole is { })
{
// BUGBUG: The results from GetConsoleOutputWindow are incorrect when called from Init.
// Our thread in WindowsMainLoop.CheckWin will get the correct results. See #if HACK_CHECK_WINCHANGED
Size winSize = WinConsole.GetConsoleOutputWindow (out _);
// The results from GetConsoleBufferWindow are correct when called from Init.
// Our thread in WindowsMainLoop.CheckWin will get the resize event. See #if HACK_CHECK_WINCHANGED
Size winSize = WinConsole.GetConsoleBufferWindow (out _);
Cols = winSize.Width;
Rows = winSize.Height;
OnSizeChanged (new SizeChangedEventArgs (new (Cols, Rows)));
@@ -602,13 +602,6 @@ internal class WindowsDriver : ConsoleDriver
return;
}
int w = e.Size.Value.Width;
if (w == Cols - 3 && e.Size.Value.Height < Rows)
{
w += 3;
}
Left = 0;
Top = 0;
Cols = e.Size.Value.Width;
@@ -617,7 +610,7 @@ internal class WindowsDriver : ConsoleDriver
if (!RunningUnitTests)
{
Size newSize = WinConsole.SetConsoleWindow (
(short)Math.Max (w, 16),
(short)Math.Max (e.Size.Value.Width, 16),
(short)Math.Max (e.Size.Value.Height, 0));
Cols = newSize.Width;

View File

@@ -220,6 +220,7 @@ internal class WindowsMainLoop : IMainLoopDriver
private readonly ManualResetEventSlim _winChange = new (false);
private bool _winChanged;
private Size _windowSize;
private Size? _lastWindowSizeBeforeMaximized = null;
private void CheckWinChange ()
{
while (_mainLoop is { })
@@ -232,7 +233,22 @@ internal class WindowsMainLoop : IMainLoopDriver
while (_mainLoop is { })
{
Task.Delay (500).Wait ();
_windowSize = _winConsole.GetConsoleBufferWindow (out _);
Size largestWindowSize = _winConsole!.GetLargestConsoleWindowSize ();
_windowSize = _winConsole!.GetConsoleBufferWindow (out _);
if (_lastWindowSizeBeforeMaximized is null && _windowSize == largestWindowSize)
{
_lastWindowSizeBeforeMaximized = new (_consoleDriver.Cols, _consoleDriver.Rows);
}
else if (_lastWindowSizeBeforeMaximized is { } && _windowSize != largestWindowSize)
{
if (_windowSize != _lastWindowSizeBeforeMaximized)
{
_windowSize = _lastWindowSizeBeforeMaximized.Value;
}
_lastWindowSizeBeforeMaximized = null;
}
if (_windowSize != Size.Empty
&& (_windowSize.Width != _consoleDriver.Cols