Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error with wrong terminal size during tab switch #1682

Merged
merged 2 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
<description>
<ul>
<li>Do not abort when failing to create `XDG_STATE_HOME/contour/crash` directory</li>
<li>Fixes tab switch crash after resize</li>
<li>Fixes tab shrinking after tab creation/switches when a non-zero horizontal window margin is configured</li>
</ul>
</description>
</release>
Expand Down
14 changes: 10 additions & 4 deletions src/contour/TerminalSessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,27 @@ void TerminalSessionManager::setSession(size_t index)
if (!isAllowedToChangeTabs())
return;

Require(display != nullptr);
auto const pixels = display->pixelSize();
auto const totalPageSize = display->calculatePageSize() + _activeSession->terminal().statusLineHeight();

auto* oldSession = _activeSession;

if (index < _sessions.size())
{
_activeSession = _sessions[index];
// Ensure that the existing session is resized to the display's size.
_activeSession->terminal().resizeScreen(totalPageSize, pixels);
}
else
createSession();

if (oldSession == _activeSession)
return;

Require(display != nullptr);
auto const pixels = display->pixelSize();
auto const totalPageSize = display->calculatePageSize() + _activeSession->terminal().statusLineHeight();

display->setSession(_activeSession);
// Resize active session after display is attached to it
// to return a lost line
_activeSession->terminal().resizeScreen(totalPageSize, pixels);
updateStatusLine();

Expand Down
6 changes: 5 additions & 1 deletion src/contour/display/TerminalDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,11 @@ bool TerminalDisplay::isFullScreen() const
vtbackend::ImageSize TerminalDisplay::pixelSize() const
{
assert(_session);
return gridMetrics().cellSize * _session->terminal().pageSize();
auto const scaledWindowMargins = applyContentScale(_session->profile().margins.value(), contentScale());
auto const scaledWindowMarginsPixels =
vtbackend::ImageSize { Width::cast_from(unbox(scaledWindowMargins.horizontal) * 2),
Height::cast_from(unbox(scaledWindowMargins.vertical) * 2) };
return gridMetrics().cellSize * _session->terminal().pageSize() + scaledWindowMarginsPixels;
}

vtbackend::ImageSize TerminalDisplay::cellSize() const
Expand Down
Loading