Commit 18e7e6cf authored by Matan Ziv-Av's avatar Matan Ziv-Av Committed by Tomaz Canabrava
Browse files

Image positionioning fixes

- Image display position relative to top left of text display, instead of top left of terminal widget.
  Fixes a problem described here: https://bugs.kde.org/show_bug.cgi?id=449799
- Improve cursor positioning and scrolling after displaying an image
  - Now the cursor ends in the same place relative to image regardless of whether scrolling is needed.
  - If the image fills the whole width of the terminal, the cursor is placed at the start of the line after the image (kitty and iterm protocols).
- Keep images in place when resizing the window vertically
parent 72b26bc2
......@@ -4,7 +4,6 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
// Own
#include "Vt102Emulation.h"
#include "config-konsole.h"
......@@ -827,11 +826,18 @@ void Vt102Emulation::processSessionAttributeRequest(int tokenSize)
}
int rows = -1, cols = -1;
int needScroll = _currentScreen->currentTerminalDisplay()->addPlacement(pixmap, rows, cols);
if (needScroll > 0) {
_currentScreen->scrollUp(needScroll);
if (needScroll > 1) {
_currentScreen->scrollUp(needScroll - 1);
}
if (rows - needScroll - 1 > 0) {
_currentScreen->cursorDown(rows - needScroll - 1);
}
if (_currentScreen->getCursorX() + cols >= _currentScreen->getColumns()) {
_currentScreen->toStartOfLine();
_currentScreen->newLine();
} else {
_currentScreen->cursorRight(cols);
}
_currentScreen->cursorDown(rows - needScroll);
_currentScreen->cursorRight(cols);
}
_pendingSessionAttributesUpdates[attribute] = value;
_sessionAttributesUpdateTimer->start(20);
......@@ -1457,12 +1463,19 @@ void Vt102Emulation::processGraphicsToken(int tokenSize)
int rows = -1, cols = -1;
int needScroll = _currentScreen->currentTerminalDisplay()
->addPlacement(pixmap, rows, cols, -1, -1, true, keys['z'], keys['i'], keys['p'], keys['A'] / 255.0, keys['X'], keys['Y']);
if (needScroll > 0) {
_currentScreen->scrollUp(needScroll);
if (needScroll > 1) {
_currentScreen->scrollUp(needScroll - 1);
}
if (keys['C'] == 0) {
_currentScreen->cursorDown(rows - needScroll);
_currentScreen->cursorRight(cols);
if (rows - needScroll - 1 > 0) {
_currentScreen->cursorDown(rows - needScroll - 1);
}
if (_currentScreen->getCursorX() + cols >= _currentScreen->getColumns()) {
_currentScreen->toStartOfLine();
_currentScreen->newLine();
} else {
_currentScreen->cursorRight(cols);
}
}
if (keys['q'] == 0 && keys['i']) {
QString params = QStringLiteral("i=") + QString::number(keys['i']);
......@@ -2207,9 +2220,11 @@ void Vt102Emulation::SixelModeDisable()
int needScroll = _currentScreen->currentTerminalDisplay()->addPlacement(pixmap, rows, cols, row, col, m_SixelScrolling);
if (m_SixelScrolling) {
if (needScroll > 0) {
_currentScreen->scrollUp(needScroll + 1);
_currentScreen->scrollUp(needScroll);
}
if (rows - needScroll > 0) {
_currentScreen->cursorDown(rows - needScroll);
}
_currentScreen->cursorDown(rows - needScroll);
}
}
......
......@@ -1018,6 +1018,21 @@ void TerminalDisplay::updateImageSize()
if (_resizing) {
showResizeNotification();
if (oldLines != _lines) {
// An image's vertical position is relative to top line of the
// terminal, but text is relative to the bottom line, so the
// position needs adjusting when the terminal is resized.
int histLines = 0;
int change = oldLines - _lines;
if (_screenWindow && _screenWindow->screen()) {
histLines = _screenWindow->screen()->getHistLines();
}
if (histLines) {
scrollUpVisiblePlacements(qMax(-histLines, change));
} else if (oldLines > _lines && cursorPosition().y() >= oldLines - change) {
scrollUpVisiblePlacements(cursorPosition().y() - _lines + 1);
}
}
Q_EMIT changedContentSizeSignal(_contentRect.height(), _contentRect.width()); // expose resizeEvent
}
......@@ -3004,7 +3019,7 @@ int TerminalDisplay::addPlacement(QPixmap pixmap, int &rows, int &cols, int row,
col = pos.x();
}
if (rows == -1) {
rows = (pixmap.height() - 1) / _terminalFont->fontHeight();
rows = (pixmap.height() - 1) / _terminalFont->fontHeight() + 1;
}
if (cols == -1) {
cols = (pixmap.width() - 1) / _terminalFont->fontWidth() + 1;
......
......@@ -432,8 +432,8 @@ void TerminalPainter::drawTextFragment(QPainter &painter,
if (!p || p->z >= 0) {
break;
}
int x = p->col * display->terminalFont()->fontWidth() + p->X;
int y = p->row * display->terminalFont()->fontHeight() + p->Y;
int x = p->col * display->terminalFont()->fontWidth() + p->X + display->contentRect().left();
int y = p->row * display->terminalFont()->fontHeight() + p->Y + display->contentRect().top();
QRectF srcRect(0, 0, p->pixmap.width(), p->pixmap.height());
QRectF dstRect(x, y - scrollDelta, p->pixmap.width(), p->pixmap.height());
painter.setOpacity(p->opacity);
......@@ -458,8 +458,8 @@ void TerminalPainter::drawTextFragment(QPainter &painter,
break;
}
QPixmap image = p->pixmap;
int x = p->col * display->terminalFont()->fontWidth() + p->X;
int y = p->row * display->terminalFont()->fontHeight() + p->Y;
int x = p->col * display->terminalFont()->fontWidth() + p->X + display->contentRect().left();
int y = p->row * display->terminalFont()->fontHeight() + p->Y + display->contentRect().top();
QRectF srcRect(0, 0, image.width(), image.height());
QRectF dstRect(x, y - scrollDelta, image.width(), image.height());
painter.setOpacity(p->opacity);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment