From b874effc0b91818fa0e72289510e0a75be432a45 Mon Sep 17 00:00:00 2001 From: samuelfessahaye Date: Mon, 13 Oct 2025 13:32:20 -0400 Subject: [PATCH 1/4] Fix: incorrect window size restore after exiting full screen (#351) --- .DS_Store | Bin 0 -> 8196 bytes build/.DS_Store | Bin 0 -> 10244 bytes src/interactivity/win32/window.cpp | 52 +++++++++++++++++++++++++++++ src/interactivity/win32/window.hpp | 4 +++ 4 files changed, 56 insertions(+) create mode 100644 .DS_Store create mode 100644 build/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..52feba0f75f6de273fdf6061b510067c452288b8 GIT binary patch literal 8196 zcmeHMT~8B16um=1wt%rQ5{ZdPiHQ$}R0N_SzLY{WBnpNWKcWV^Z7mDSZqsf-LrD6p zf5QhKOnmj1_+Na|b7vNuS+>z9BRWHN?(Xb4cV^DqndvMSGyKFgi}-{h;-iPiOE`(5vNpF0SOrciFpZ)Nx#Ur>>Ko_xCA=womr2q_ zfa(F~QzL==JQ(R7bldSafiG^`_qx&S>{l_A86G(|>Wn($&dbVncuo_L>JYHFU}v$&rxA+@QAJ1z~V zi`>U^0i_-Ju50QqxP`jED+y)`qZZK|Df?QEVFZsI_%6_ntRXS_;#PX7DmVy0nu( zAtnt}4y{p9tvvsX>Mo)?pf?FVG&1;HOE;+`Yh<7t)KNne>>}qeN+>T?`lzYIc%EGz zI9>{#HPZ1}M1L7xR_I~6s!|=Dk&$tkXa~<&!|y2iR>RC_%bA`;vlhBfM%UrDhLNh% zwyB)dL`RP!S~N7qRw{0?Sec>gnlj8PBMLUWXh;kPmRNt2Y>%RlYO&|whCAUeop~0yi!>y0n0yV(-NPx^SEB&;>5VVvXX*K y9>-zjaUAyKABMQk1InCYZ2QWh1nG}|2+;RNyZ^fw0{&#Ol-LpN{{N5f|33g=`k$Ks literal 0 HcmV?d00001 diff --git a/build/.DS_Store b/build/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b07220cbf1ef7fcaa8d7464a5c270cd85e3899f5 GIT binary patch literal 10244 zcmeHMOHUL*5U%DqE8-3aK4UU*FD4R2AR1x}>-r?dfGk0Xk9B6YStktLo0(Za2+5xH zdp8Q^vX%AyJul`7QASbkgiR4)pS>N&wSHWJ=F^Uq);ng0slkA5zq*1BOu~~g+=gu%RwUr1YfM`u^J(QWh?Pm0g^YB92-T3E1yN8)Oh zbKhymwln9^)si`IgR{u?7!9O>SEi`)_@T$je6_%9tQ<<)qUta*My6z**w`2uzdU4( zUK!sUvNpy?hKH=N%VV3H8DlVa@#;)z$zNvtrMzn(aoB)fb-i7`LaFJQR*C`hIjdm1 zu<3x?P=j??Pn>HAT;5|z;Uo)jLPa2F`}xKh@d5g}(%h$J)*2quXqN}-a4 zD%j{nOITMBpAatW?Ndaox#ZeuN9zjk6rNittqf{;SQPq9%+hSpCf00n++8dV$eY;Z z$x?5m69V*GzZE4J(cUE@S~tEe7qtbpQ5sX}=fBbZ-*}FVT)_x9KKh3dFol8VuEcSj zd~U?`Z>HIZ?3qJ7hkK7?&A$GleFJ@igU61a7(99E^r@10)Un;AN+2Tk4es-x;MeG* zO5l}?RonGgWj>;7QPEqcC9^-JIz!7(cbaBjR8ePOr$G*PC!mzc@un6RLmJH|+`%%bB|KtQ;0Ervoa6%uW12$3x2H?=^&TN-!a(1kpL9L_=)3Ng}h1Gn&ce zr&VhPKZVcZGQAIT7*N*XHN1hh@DV=2SNINFq??%JEICic$Tc!S?ve*&hPdQ8@kpQs zXlrbCA|xk>gm{s9)hV~hLJ^&SqdQQPYT&>!I!1^;PkbUY2OJsllg^QtON$x-jetf# zBcKt`2<%S;+SP4Y;{5;C-v9sa&zskGr4i5w{1pU9$Iar+0uI&48`7hSvvv#1Gc1CH zUR`l%f|WduM=p=!@j@KO%OnWfhEbM;a$X3?>x!d<^w0kcNG2_*gs3^i(fPm5{|{#V F{|nm71@-^{ literal 0 HcmV?d00001 diff --git a/src/interactivity/win32/window.cpp b/src/interactivity/win32/window.cpp index e96848fe3bf..16ff9ae7a67 100644 --- a/src/interactivity/win32/window.cpp +++ b/src/interactivity/win32/window.cpp @@ -59,6 +59,10 @@ Window::Window() : ZeroMemory((void*)&_rcClientLast, sizeof(_rcClientLast)); ZeroMemory((void*)&_rcWindowBeforeFullscreen, sizeof(_rcWindowBeforeFullscreen)); ZeroMemory((void*)&_rcWorkBeforeFullscreen, sizeof(_rcWorkBeforeFullscreen)); + + ZeroMemory((void*)&_clientBeforeFullscreen, sizeof(_clientBeforeFullscreen)); + _viewportCellsBeforeFullscreen = { 0, 0 }; + _bufferCellsBeforeFullscreen = { 0, 0 }; } Window::~Window() @@ -1106,6 +1110,10 @@ void Window::_SetFullscreenPosition(const RECT& rcMonitor, const RECT& rcWork) _fWasMaximizedBeforeFullscreen = IsZoomed(GetWindowHandle()); _rcWorkBeforeFullscreen = rcWork; + GetClientRect(GetWindowHandle(), &_clientBeforeFullscreen); + _viewportCellsBeforeFullscreen = _GetViewportInCharacters(); + _bufferCellsBeforeFullscreen = _GetBufferInCharacters(); + SetWindowPos(GetWindowHandle(), HWND_TOP, rcMonitor.left, @@ -1166,6 +1174,50 @@ void Window::_RestoreFullscreenPosition(const RECT& rcWork) OffsetRect(&rcRestore, 0, rcWork.top - rcRestore.top); } + // Get the width of scrollbars + auto scrollbarWidth = GetSystemMetrics(SM_CXVSCROLL); // vertical scrollbar width + auto scrollbarHeight = GetSystemMetrics(SM_CYHSCROLL); // horizontal scrollbar height + + // Calculate new window dimensions that compensate for scrollbars + auto newWidth = rcRestore.right - rcRestore.left + scrollbarWidth; + auto newHeight = rcRestore.bottom - rcRestore.top + scrollbarHeight; + + // Desired client size is what we had before fullscreen. + int desiredClientW = _clientBeforeFullscreen.right - _clientBeforeFullscreen.left; + int desiredClientH = _clientBeforeFullscreen.bottom - _clientBeforeFullscreen.top; + + // Compare current buffer vs viewport to know if scrollbars are needed. + const COORD curBuffer = _GetBufferInCharacters(); + const COORD curViewport = _GetViewportInCharacters(); + + // If buffer exceeds viewport, Windows will show scrollbars. + // We grow the *outer* window so the client stays the same visible size. + bool needVScroll = curBuffer.X > curViewport.X; // vertical scrollbar (for wider buffer) + bool needHScroll = curBuffer.Y > curViewport.Y; // horizontal scrollbar (for taller buffer) + + // Use per-monitor DPI-aware metrics if available. + UINT dpi = _dpiBeforeFullscreen; // you already track this + int vScrollW = GetSystemMetricsForDpi(SM_CXVSCROLL, dpi); + int hScrollH = GetSystemMetricsForDpi(SM_CYHSCROLL, dpi); + + if (needVScroll) + desiredClientW += vScrollW; + if (needHScroll) + desiredClientH += hScrollH; + + // Convert desired *client* size → *window* (outer) size for current styles/DPI. + RECT outer = { 0, 0, desiredClientW, desiredClientH }; + DWORD style = static_cast(GetWindowLongW(GetWindowHandle(), GWL_STYLE)); + DWORD exstyle = static_cast(GetWindowLongW(GetWindowHandle(), GWL_EXSTYLE)); + AdjustWindowRectExForDpi(&outer, style, FALSE, exstyle, dpi); + + int targetW = outer.right - outer.left; + int targetH = outer.bottom - outer.top; + + // Apply the computed size to your restored position. + rcRestore.right = rcRestore.left + targetW; + rcRestore.bottom = rcRestore.top + targetH; + // Show the window at the computed position. SetWindowPos(GetWindowHandle(), HWND_TOP, diff --git a/src/interactivity/win32/window.hpp b/src/interactivity/win32/window.hpp index a0ad4508f28..bd2f88b84a2 100644 --- a/src/interactivity/win32/window.hpp +++ b/src/interactivity/win32/window.hpp @@ -163,6 +163,10 @@ namespace Microsoft::Console::Interactivity::Win32 RECT _rcWorkBeforeFullscreen; UINT _dpiBeforeFullscreen; + RECT _clientBeforeFullscreen{}; + COORD _viewportCellsBeforeFullscreen{}; + COORD _bufferCellsBeforeFullscreen{}; + // math helpers void _CalculateWindowRect(const til::size coordWindowInChars, _Inout_ til::rect* const prectWindow) const; From 9bcdea4f815c68255b9cb9f11436b4ebb0e2ee87 Mon Sep 17 00:00:00 2001 From: samuelfessahaye Date: Mon, 13 Oct 2025 13:55:59 -0400 Subject: [PATCH 2/4] spelling: allow vscroll/exstyle --- .github/actions/spelling/allow/names.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/spelling/allow/names.txt b/.github/actions/spelling/allow/names.txt index 1b52d13a22a..57cffe2096f 100644 --- a/.github/actions/spelling/allow/names.txt +++ b/.github/actions/spelling/allow/names.txt @@ -66,3 +66,5 @@ Zamora zljubisic Zoey zorio +vscroll +exstyle \ No newline at end of file From 5c0fe0e30c9d6003c392f4293163bac9466bcc48 Mon Sep 17 00:00:00 2001 From: samuelfessahaye Date: Mon, 13 Oct 2025 14:37:15 -0400 Subject: [PATCH 3/4] spelling: allow vscroll/exstyle --- .github/actions/spelling/allow/names.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/actions/spelling/allow/names.txt b/.github/actions/spelling/allow/names.txt index 57cffe2096f..b74e3b7ef97 100644 --- a/.github/actions/spelling/allow/names.txt +++ b/.github/actions/spelling/allow/names.txt @@ -65,6 +65,4 @@ zamora Zamora zljubisic Zoey -zorio -vscroll -exstyle \ No newline at end of file +zorio \ No newline at end of file From 9ef85b74276e07f2d62d547538ed079c17741661 Mon Sep 17 00:00:00 2001 From: samuelfessahaye Date: Mon, 13 Oct 2025 14:44:08 -0400 Subject: [PATCH 4/4] spelling allowlist: add trailing newline --- .github/actions/spelling/allow/names.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/spelling/allow/names.txt b/.github/actions/spelling/allow/names.txt index b74e3b7ef97..83b4727df79 100644 --- a/.github/actions/spelling/allow/names.txt +++ b/.github/actions/spelling/allow/names.txt @@ -65,4 +65,6 @@ zamora Zamora zljubisic Zoey -zorio \ No newline at end of file +zorio +vscroll +exstyle