diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000000..52feba0f75f Binary files /dev/null and b/.DS_Store differ diff --git a/.github/actions/spelling/allow/names.txt b/.github/actions/spelling/allow/names.txt index 1b52d13a22a..83b4727df79 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 diff --git a/build/.DS_Store b/build/.DS_Store new file mode 100644 index 00000000000..b07220cbf1e Binary files /dev/null and b/build/.DS_Store differ 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;