Skip to content

Commit

Permalink
Fixes VT sequence DECSCPP and DECCOLM (#1205)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Parpart <christian@parpart.family>
  • Loading branch information
christianparpart committed Sep 20, 2023
1 parent b3ee571 commit 3a51b20
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 56 deletions.
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<li>Fixes rendering in cases of glyphs with inverted orientation (#1115).</li>
<li>Fixes VT sequence DECSTBM and DECSLRM defaulting parameters (#1164).</li>
<li>Fixes VT sequence DECFRA (#1189).</li>
<li>Fixes VT sequence DECSCPP and DECCOLM (#1205).</li>
<li>Adds inheritance of profiles in configuration file based on default profile (#1063).</li>
<li>Clear search term when switch to insert vi mode (#1135)</li>
<li>Delete dpi_scale entry in configuration (#1137)</li>
Expand Down
3 changes: 2 additions & 1 deletion src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ void TerminalSession::attachDisplay(display::TerminalWidget& newDisplay)
// auto const pixels =
// ImageSize { _display->cellSize().width * boxed_cast<Width>(_terminal.pageSize().columns),
// _display->cellSize().height * boxed_cast<Height>(_terminal.pageSize().lines) };
auto const l = scoped_lock { _terminal };
_terminal.resizeScreen(_terminal.pageSize(), pixels);
_terminal.setRefreshRate(_display->refreshRate());
}
Expand Down Expand Up @@ -565,7 +566,7 @@ void TerminalSession::requestWindowResize(LineCount lines, ColumnCount columns)
if (!_display)
return;

sessionLog()("Application request to resize window: {}x{} px", columns, lines);
sessionLog()("Application request to resize window: {}x{}", columns, lines);
_display->post([this, lines, columns]() { _display->resizeWindow(lines, columns); });
}

Expand Down
14 changes: 7 additions & 7 deletions src/contour/display/TerminalWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ void TerminalWidget::updateSizeProperties()

// implicit width/height
auto const dpr = contentScale();
auto const implicitViewSize = _renderer->cellSize() * _session->terminal().pageSize() * (1.0 / dpr);
auto const implicitViewSize = _renderer->cellSize() * _session->terminal().totalPageSize() * (1.0 / dpr);
setImplicitWidth(unbox<qreal>(implicitViewSize.width));
setImplicitHeight(unbox<qreal>(implicitViewSize.height));

Expand All @@ -924,7 +924,7 @@ void TerminalWidget::updateSizeProperties()
auto constexpr MinimumGridSize = PageSize { LineCount(5), ColumnCount(10) };
auto const minSize =
ImageSize { Width::cast_from(unbox<int>(gridMetrics().cellSize.width) * *MinimumGridSize.columns),
Height::cast_from(unbox<int>(gridMetrics().cellSize.width) * *MinimumGridSize.columns) };
Height::cast_from(unbox<int>(gridMetrics().cellSize.width) * *MinimumGridSize.lines) };
auto const scaledMinSize = minSize / dpr;

window()->setMinimumSize(QSize(scaledMinSize.width.as<int>(), scaledMinSize.height.as<int>()));
Expand Down Expand Up @@ -1114,6 +1114,7 @@ void TerminalWidget::resizeWindow(terminal::Width newWidth, terminal::Height new
* unbox<int>(gridMetrics().cellSize.width)),
terminal::Height::cast_from(unbox(requestedPageSize.lines)
* unbox<int>(gridMetrics().cellSize.height)) };
auto const l = scoped_lock { terminal() };
terminal().resizeScreen(requestedPageSize, pixels);
}

Expand All @@ -1125,20 +1126,18 @@ void TerminalWidget::resizeWindow(terminal::LineCount newLineCount, terminal::Co
return;
}

auto requestedPageSize = terminal().pageSize();
auto requestedPageSize = terminal().totalPageSize();
if (*newColumnCount)
requestedPageSize.columns = newColumnCount;
if (*newLineCount)
requestedPageSize.lines = newLineCount;

// setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
const_cast<config::TerminalProfile&>(profile()).terminalSize = requestedPageSize;
_renderer->setPageSize(requestedPageSize);
auto const pixels = terminal::ImageSize {
terminal::Width(unbox<unsigned>(requestedPageSize.columns) * *gridMetrics().cellSize.width),
terminal::Height(unbox<unsigned>(requestedPageSize.lines) * *gridMetrics().cellSize.height)
};
terminal().resizeScreen(requestedPageSize, pixels);

window()->resize(QSize(pixels.width.as<int>(), pixels.height.as<int>()));
}

void TerminalWidget::setFonts(terminal::rasterizer::FontDescriptions fontDescriptions)
Expand Down Expand Up @@ -1189,6 +1188,7 @@ bool TerminalWidget::setPageSize(PageSize newPageSize)
ImageSize { Width(*gridMetrics().cellSize.width * unbox<unsigned>(profile().terminalSize.columns)),
Height(*gridMetrics().cellSize.width * unbox<unsigned>(profile().terminalSize.columns)) };
_renderer->setPageSize(newPageSize);
auto const l = scoped_lock { terminal() };
terminal().resizeScreen(newPageSize, viewSize);
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/contour/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ void applyResize(terminal::ImageSize newPixelSize,
auto const viewSize = cellSize * newPageSize;
displayLog()("Applying resize: {} (new pixel size) {} (view size)", newPixelSize, viewSize);

auto const l = scoped_lock { terminal };

if (newPageSize == terminal.pageSize())
return;

Expand Down
10 changes: 8 additions & 2 deletions src/vtbackend/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3545,8 +3545,14 @@ ApplyResult Screen<Cell>::apply(FunctionDefinition const& function, Sequence con
case DECSCPP:
if (auto const columnCount = seq.param_or(0, 80); columnCount == 80 || columnCount == 132)
{
// EXTENSION: only 80 and 132 are specced, but we allow any.
_terminal.resizeColumns(ColumnCount(columnCount), false);
// If the cursor is beyond the width of the new page,
// then the cursor moves to the right column of the new page.
if (*cursor().position.column >= columnCount)
cursor().position.column = ColumnOffset::cast_from(columnCount) - 1;

_terminal.requestWindowResize(
PageSize { _terminal.totalPageSize().lines,
ColumnCount::cast_from(columnCount ? columnCount : 80) });
return ApplyResult::Ok;
}
else
Expand Down
69 changes: 27 additions & 42 deletions src/vtbackend/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,12 +1096,6 @@ void Terminal::tick(chrono::steady_clock::time_point now) noexcept
}

void Terminal::resizeScreen(PageSize totalPageSize, optional<ImageSize> pixels)
{
auto const _ = std::lock_guard { *this };
resizeScreenInternal(totalPageSize, pixels);
}

void Terminal::resizeScreenInternal(PageSize totalPageSize, std::optional<ImageSize> pixels)
{
// NOTE: This will only resize the currently active buffer.
// Any other buffer will be resized when it is switched to.
Expand Down Expand Up @@ -1138,31 +1132,6 @@ void Terminal::resizeScreenInternal(PageSize totalPageSize, std::optional<ImageS
verifyState();
}

void Terminal::resizeColumns(ColumnCount newColumnCount, bool clear)
{
// DECCOLM / DECSCPP
if (clear)
{
// Sets the left, right, top and bottom scrolling margins to their default positions.
setTopBottomMargin({}, unbox<LineOffset>(_settings.pageSize.lines) - LineOffset(1)); // DECSTBM
setLeftRightMargin({}, unbox<ColumnOffset>(_settings.pageSize.columns) - ColumnOffset(1)); // DECRLM

// Erases all data in page memory
clearScreen();
}

// resets vertical split screen mode (DECLRMM) to unavailable
setMode(DECMode::LeftRightMargin, false); // DECSLRM

// Pre-resize in case the event callback right after is not actually resizing the window
// (e.g. either by choice or because the window manager does not allow that, such as tiling WMs).
auto const newSize = PageSize { _settings.pageSize.lines, newColumnCount };
auto const pixels = cellPixelSize() * newSize;
resizeScreen(newSize, pixels);

requestWindowResize(newSize);
}

void Terminal::verifyState()
{
#if !defined(NDEBUG)
Expand Down Expand Up @@ -1531,20 +1500,36 @@ void Terminal::setMode(DECMode mode, bool enable)
}
break;
case DECMode::Origin: _currentScreen.get().cursor().originMode = enable; break;
case DECMode::Columns132:
case DECMode::Columns132: {
if (!isModeEnabled(DECMode::AllowColumns80to132))
break;
if (enable != isModeEnabled(DECMode::Columns132))
{
auto const clear = enable != isModeEnabled(mode);
terminalLog()("Ignoring DECCOLM because DECCOLM is not allowed by mode setting.");
break;
}

// sets the number of columns on the page to 80 or 132 and selects the
// corresponding 80- or 132-column font
auto const columns = ColumnCount(enable ? 132 : 80);
// sets the number of columns on the page to 80 or 132 and selects the
// corresponding 80- or 132-column font
auto const columns = ColumnCount(enable ? 132 : 80);

resizeColumns(columns, clear);
}
break;
terminalLog()("DECCOLM: Setting columns to {}", columns);

// Sets the left, right, top and bottom scrolling margins to their default positions.
setTopBottomMargin(std::nullopt, std::nullopt); // DECSTBM
setLeftRightMargin(std::nullopt, std::nullopt); // DECRLM

// resets vertical split screen mode (DECLRMM) to unavailable
setMode(DECMode::LeftRightMargin, false); // DECSLRM

// DECCOLM clears data from the status line if the status line is set to host-writable.
if (_state.statusDisplayType == StatusDisplayType::HostWritable)
_hostWritableStatusLineScreen.clearScreen();

// Erases all data in page memory
clearScreen();

requestWindowResize(PageSize { totalPageSize().lines, columns });
}
break;
case DECMode::BatchedRendering:
if (_state.modes.enabled(DECMode::BatchedRendering) != enable)
synchronizedOutput(enable);
Expand Down Expand Up @@ -1975,7 +1960,7 @@ void Terminal::setStatusDisplay(StatusDisplayType statusDisplayType)
_state.statusDisplayType = statusDisplayType;

if (statusLineVisibleBefore != statusLineVisibleAfter)
resizeScreenInternal(_settings.pageSize, nullopt);
resizeScreen(_settings.pageSize, nullopt);
}

void Terminal::setActiveStatusDisplay(ActiveStatusDisplay activeDisplay)
Expand Down
4 changes: 0 additions & 4 deletions src/vtbackend/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ class Terminal
/// Important! In case a status line is currently visible, the status line count is being
/// accumulated into the screen size, too.
void resizeScreen(PageSize totalPageSize, std::optional<ImageSize> pixels = std::nullopt);
void resizeScreenInternal(PageSize totalPageSize, std::optional<ImageSize> pixels);

/// Implements semantics for DECCOLM / DECSCPP.
void resizeColumns(ColumnCount newColumnCount, bool clear);

void clearScreen();

Expand Down

0 comments on commit 3a51b20

Please sign in to comment.