Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/actions/spelling/allow/names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@
Zamora
zljubisic
Zoey
zorio
zorio
Binary file added build/.DS_Store
Binary file not shown.
52 changes: 52 additions & 0 deletions src/interactivity/win32/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
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()
Expand Down Expand Up @@ -1106,6 +1110,10 @@
_fWasMaximizedBeforeFullscreen = IsZoomed(GetWindowHandle());
_rcWorkBeforeFullscreen = rcWork;

GetClientRect(GetWindowHandle(), &_clientBeforeFullscreen);
_viewportCellsBeforeFullscreen = _GetViewportInCharacters();
_bufferCellsBeforeFullscreen = _GetBufferInCharacters();

SetWindowPos(GetWindowHandle(),
HWND_TOP,
rcMonitor.left,
Expand Down Expand Up @@ -1166,6 +1174,50 @@
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<DWORD>(GetWindowLongW(GetWindowHandle(), GWL_STYLE));
DWORD exstyle = static_cast<DWORD>(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,
Expand Down
4 changes: 4 additions & 0 deletions src/interactivity/win32/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down