Commit 6667d96e authored by Edwin Pujols's avatar Edwin Pujols Committed by Tomaz Canabrava
Browse files

TerminalDisplay: Limit mouse move events.

The terminal display mouse tracking is based on character boxes, i.e.,
unless the mouse moves out of a character box its position hasn't really
changed. So most of the logic in `TerminalDisplay::mouseMoveEvent` can
be skipped/omitted till the pointer crosses box boundaries.

Before my changes applications like Vim/Neovim couldn't do selection via
dragging with the left mouse button (there might be a bug there). I
cursorily checked other features like the color filter and URL
underlining, and they work.
parent 8de0e6c7
......@@ -355,6 +355,8 @@ TerminalDisplay::TerminalDisplay(QWidget* parent)
, _boldIntense(true)
, _lines(1)
, _columns(1)
, _prevCharacterLine(-1)
, _prevCharacterColumn(-1)
, _usedLines(1)
, _usedColumns(1)
, _contentRect(QRect())
......@@ -1413,6 +1415,13 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !_usesMouseTracking);
if (charLine == _prevCharacterLine && charColumn == _prevCharacterColumn) {
return;
}
_prevCharacterLine = charLine;
_prevCharacterColumn = charColumn;
processFilters();
_filterChain->mouseMoveEvent(this, ev, charLine, charColumn);
......@@ -1422,7 +1431,7 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
}
// if the program running in the terminal is interested in Mouse Tracking
// evnets then emit a mouse movement signal, unless the shift key is
// events then emit a mouse movement signal, unless the shift key is
// being held down, which overrides this.
if (_usesMouseTracking && !(ev->modifiers() & Qt::ShiftModifier)) {
int button = 3;
......
......@@ -684,6 +684,11 @@ private:
int _lines; // the number of lines that can be displayed in the widget
int _columns; // the number of columns that can be displayed in the widget
// Character line and character column as per a previous call to
// getCharacterPosition() in mouseMoveEvent().
int _prevCharacterLine;
int _prevCharacterColumn;
int _usedLines; // the number of lines that are actually being used, this will be less
// than 'lines' if the character image provided with setImage() is smaller
// than the maximum image size which can be displayed
......
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