add support in TerminalDisplay for disallowing mouse tracking

wilder
Martin T. H. Sandsmark 6 years ago committed by Tomaz Canabrava
parent 570a55f75d
commit 3d64132545
  1. 54
      src/terminalDisplay/TerminalDisplay.cpp
  2. 8
      src/terminalDisplay/TerminalDisplay.h

@ -196,6 +196,7 @@ TerminalDisplay::TerminalDisplay(QWidget *parent)
, _showTerminalSizeHint(true) , _showTerminalSizeHint(true)
, _bidiEnabled(false) , _bidiEnabled(false)
, _usesMouseTracking(false) , _usesMouseTracking(false)
, _allowMouseTracking(true)
, _bracketedPasteMode(false) , _bracketedPasteMode(false)
, _iPntSel(QPoint(-1, -1)) , _iPntSel(QPoint(-1, -1))
, _pntSel(QPoint(-1, -1)) , _pntSel(QPoint(-1, -1))
@ -1155,7 +1156,7 @@ void TerminalDisplay::mousePressEvent(QMouseEvent *ev)
return; return;
} }
auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !_usesMouseTracking); auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !usesMouseTracking());
QPoint pos = QPoint(charColumn, charLine); QPoint pos = QPoint(charColumn, charLine);
processFilters(); processFilters();
@ -1202,23 +1203,23 @@ void TerminalDisplay::mousePressEvent(QMouseEvent *ev)
// //
// Alternate buffer when using Mouse Tracking and with Shift pressed: // Alternate buffer when using Mouse Tracking and with Shift pressed:
// select text or columnSelection // select text or columnSelection
if (!_usesMouseTracking && ((ev->modifiers() == Qt::ShiftModifier) || (((ev->modifiers() & Qt::ShiftModifier) != 0u) && _columnSelectionMode))) { if (!usesMouseTracking() && ((ev->modifiers() == Qt::ShiftModifier) || (((ev->modifiers() & Qt::ShiftModifier) != 0u) && _columnSelectionMode))) {
extendSelection(ev->pos()); extendSelection(ev->pos());
} else if ((!_usesMouseTracking && !((ev->modifiers() & Qt::ShiftModifier))) } else if ((!usesMouseTracking() && !((ev->modifiers() & Qt::ShiftModifier)))
|| (_usesMouseTracking && ((ev->modifiers() & Qt::ShiftModifier) != 0u))) { || (usesMouseTracking() && ((ev->modifiers() & Qt::ShiftModifier) != 0u))) {
_screenWindow->clearSelection(); _screenWindow->clearSelection();
pos.ry() += _scrollBar->value(); pos.ry() += _scrollBar->value();
_iPntSel = _pntSel = pos; _iPntSel = _pntSel = pos;
_actSel = 1; // left mouse button pressed but nothing selected yet. _actSel = 1; // left mouse button pressed but nothing selected yet.
} else if (_usesMouseTracking && !_readOnly) { } else if (usesMouseTracking() && !_readOnly) {
Q_EMIT mouseSignal(0, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum(), 0); Q_EMIT mouseSignal(0, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum(), 0);
} }
} }
} else if (ev->button() == Qt::MiddleButton) { } else if (ev->button() == Qt::MiddleButton) {
processMidButtonClick(ev); processMidButtonClick(ev);
} else if (ev->button() == Qt::RightButton) { } else if (ev->button() == Qt::RightButton) {
if (!_usesMouseTracking || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) { if (!usesMouseTracking() || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) {
Q_EMIT configureRequest(ev->pos()); Q_EMIT configureRequest(ev->pos());
} else { } else {
if (!_readOnly) { if (!_readOnly) {
@ -1245,7 +1246,7 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent *ev)
setFocus(); setFocus();
} }
auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !_usesMouseTracking); auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !usesMouseTracking());
// Ignore mouse movements that don't change the character position, // Ignore mouse movements that don't change the character position,
// but don't ignore the ones generated by AutoScrollHandler (which // but don't ignore the ones generated by AutoScrollHandler (which
@ -1265,7 +1266,7 @@ void TerminalDisplay::mouseMoveEvent(QMouseEvent *ev)
// if the program running in the terminal is interested in Mouse Tracking // if the program running in the terminal is interested in Mouse Tracking
// events 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. // being held down, which overrides this.
if (_usesMouseTracking && !(ev->modifiers() & Qt::ShiftModifier)) { if (usesMouseTracking() && !(ev->modifiers() & Qt::ShiftModifier)) {
if (!_readOnly) { if (!_readOnly) {
int button = 3; int button = 3;
if ((ev->buttons() & Qt::LeftButton) != 0u) { if ((ev->buttons() & Qt::LeftButton) != 0u) {
@ -1489,7 +1490,7 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent *ev)
return; return;
} }
auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !_usesMouseTracking); auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !usesMouseTracking());
if (ev->button() == Qt::LeftButton) { if (ev->button() == Qt::LeftButton) {
if (_dragInfo.state == diPending) { if (_dragInfo.state == diPending) {
@ -1506,14 +1507,14 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent *ev)
// outside the range. The procedure used in `mouseMoveEvent' // outside the range. The procedure used in `mouseMoveEvent'
// applies here, too. // applies here, too.
if (_usesMouseTracking && !(ev->modifiers() & Qt::ShiftModifier) && !_readOnly) { if (usesMouseTracking() && !(ev->modifiers() & Qt::ShiftModifier) && !_readOnly) {
Q_EMIT mouseSignal(0, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum(), 2); Q_EMIT mouseSignal(0, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum(), 2);
} }
} }
_dragInfo.state = diNone; _dragInfo.state = diNone;
} }
if (_usesMouseTracking && !_readOnly && (ev->button() == Qt::RightButton || ev->button() == Qt::MiddleButton) && !(ev->modifiers() & Qt::ShiftModifier)) { if (usesMouseTracking() && !_readOnly && (ev->button() == Qt::RightButton || ev->button() == Qt::MiddleButton) && !(ev->modifiers() & Qt::ShiftModifier)) {
Q_EMIT mouseSignal(ev->button() == Qt::MiddleButton ? 1 : 2, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum(), 2); Q_EMIT mouseSignal(ev->button() == Qt::MiddleButton ? 1 : 2, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum(), 2);
} }
@ -1546,7 +1547,7 @@ void TerminalDisplay::setExpandedMode(bool expand)
void TerminalDisplay::processMidButtonClick(QMouseEvent *ev) void TerminalDisplay::processMidButtonClick(QMouseEvent *ev)
{ {
if (!_usesMouseTracking || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) { if (!usesMouseTracking() || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) {
const bool appendEnter = (ev->modifiers() & Qt::ControlModifier) != 0u; const bool appendEnter = (ev->modifiers() & Qt::ControlModifier) != 0u;
if (_middleClickPasteMode == Enum::PasteFromX11Selection) { if (_middleClickPasteMode == Enum::PasteFromX11Selection) {
@ -1558,7 +1559,7 @@ void TerminalDisplay::processMidButtonClick(QMouseEvent *ev)
} }
} else { } else {
if (!_readOnly) { if (!_readOnly) {
auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !_usesMouseTracking); auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !usesMouseTracking());
Q_EMIT mouseSignal(1, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum(), 0); Q_EMIT mouseSignal(1, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum(), 0);
} }
} }
@ -1576,12 +1577,12 @@ void TerminalDisplay::mouseDoubleClickEvent(QMouseEvent *ev)
return; return;
} }
auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !_usesMouseTracking); auto [charLine, charColumn] = getCharacterPosition(ev->pos(), !usesMouseTracking());
QPoint pos(qMin(charColumn, _columns - 1), qMin(charLine, _lines - 1)); QPoint pos(qMin(charColumn, _columns - 1), qMin(charLine, _lines - 1));
// pass on double click as two clicks. // pass on double click as two clicks.
if (_usesMouseTracking && !(ev->modifiers() & Qt::ShiftModifier)) { if (usesMouseTracking() && !(ev->modifiers() & Qt::ShiftModifier)) {
if (!_readOnly) { if (!_readOnly) {
// Send just _ONE_ click event, since the first click of the double click // Send just _ONE_ click event, since the first click of the double click
// was already sent by the click handler // was already sent by the click handler
@ -1651,7 +1652,7 @@ void TerminalDisplay::wheelEvent(QWheelEvent *ev)
_terminalFont->decreaseFontSize(); _terminalFont->decreaseFontSize();
} }
return; return;
} else if (!_usesMouseTracking && (_scrollBar->maximum() > 0)) { } else if (!usesMouseTracking() && (_scrollBar->maximum() > 0)) {
// If the program running in the terminal is not interested in Mouse // If the program running in the terminal is not interested in Mouse
// Tracking events, send the event to the scrollbar if the slider // Tracking events, send the event to the scrollbar if the slider
// has room to move // has room to move
@ -1674,7 +1675,7 @@ void TerminalDisplay::wheelEvent(QWheelEvent *ev)
Q_ASSERT(!_sessionController->session().isNull()); Q_ASSERT(!_sessionController->session().isNull());
if (!_usesMouseTracking && !_sessionController->session()->isPrimaryScreen() && _scrollBar->alternateScrolling()) { if (!usesMouseTracking() && !_sessionController->session()->isPrimaryScreen() && _scrollBar->alternateScrolling()) {
// Send simulated up / down key presses to the terminal program // Send simulated up / down key presses to the terminal program
// for the benefit of programs such as 'less' (which use the alternate screen) // for the benefit of programs such as 'less' (which use the alternate screen)
@ -1693,10 +1694,10 @@ void TerminalDisplay::wheelEvent(QWheelEvent *ev)
for (int i = 0; i < abs(lines); i++) { for (int i = 0; i < abs(lines); i++) {
Q_EMIT keyPressedSignal(&keyEvent); Q_EMIT keyPressedSignal(&keyEvent);
} }
} else if (_usesMouseTracking) { } else if (usesMouseTracking()) {
// terminal program wants notification of mouse activity // terminal program wants notification of mouse activity
auto [charLine, charColumn] = getCharacterPosition(ev->position().toPoint(), !_usesMouseTracking); auto [charLine, charColumn] = getCharacterPosition(ev->position().toPoint(), !usesMouseTracking());
const int steps = _scrollWheelState.consumeLegacySteps(ScrollState::DEFAULT_ANGLE_SCROLL_LINE); const int steps = _scrollWheelState.consumeLegacySteps(ScrollState::DEFAULT_ANGLE_SCROLL_LINE);
const int button = (steps > 0) ? 4 : 5; const int button = (steps > 0) ? 4 : 5;
for (int i = 0; i < abs(steps); ++i) { for (int i = 0; i < abs(steps); ++i) {
@ -2067,20 +2068,27 @@ void TerminalDisplay::setUsesMouseTracking(bool on)
resetCursor(); resetCursor();
} }
void TerminalDisplay::setAllowMouseTracking(bool allow)
{
_allowMouseTracking = allow;
resetCursor();
}
void TerminalDisplay::resetCursor() void TerminalDisplay::resetCursor()
{ {
setCursor(_usesMouseTracking ? Qt::ArrowCursor : Qt::IBeamCursor); setCursor(usesMouseTracking() ? Qt::ArrowCursor : Qt::IBeamCursor);
} }
bool TerminalDisplay::usesMouseTracking() const bool TerminalDisplay::usesMouseTracking() const
{ {
return _usesMouseTracking; return _usesMouseTracking && _allowMouseTracking;
} }
void TerminalDisplay::setBracketedPasteMode(bool on) void TerminalDisplay::setBracketedPasteMode(bool on)
{ {
_bracketedPasteMode = on; _bracketedPasteMode = on;
} }
bool TerminalDisplay::bracketedPasteMode() const bool TerminalDisplay::bracketedPasteMode() const
{ {
return _bracketedPasteMode; return _bracketedPasteMode;
@ -2510,7 +2518,7 @@ void TerminalDisplay::updateReadOnlyState(bool readonly)
void TerminalDisplay::keyPressEvent(QKeyEvent *event) void TerminalDisplay::keyPressEvent(QKeyEvent *event)
{ {
{ {
auto [charLine, charColumn] = getCharacterPosition(mapFromGlobal(QCursor::pos()), !_usesMouseTracking); auto [charLine, charColumn] = getCharacterPosition(mapFromGlobal(QCursor::pos()), !usesMouseTracking());
// Don't process it if the filterchain handled it for us // Don't process it if the filterchain handled it for us
if (_filterChain->keyPressEvent(this, event, charLine, charColumn)) { if (_filterChain->keyPressEvent(this, event, charLine, charColumn)) {
@ -2556,7 +2564,7 @@ void TerminalDisplay::keyReleaseEvent(QKeyEvent *event)
} }
{ {
auto [charLine, charColumn] = getCharacterPosition(mapFromGlobal(QCursor::pos()), !_usesMouseTracking); auto [charLine, charColumn] = getCharacterPosition(mapFromGlobal(QCursor::pos()), !usesMouseTracking());
_filterChain->keyReleaseEvent(this, event, charLine, charColumn); _filterChain->keyReleaseEvent(this, event, charLine, charColumn);
} }

@ -267,6 +267,13 @@ public:
/** See setUsesMouseTracking() */ /** See setUsesMouseTracking() */
bool usesMouseTracking() const; bool usesMouseTracking() const;
/**
* Set whether mouse tracking should be allowed, even if requested.
* This is stored separately from if mouse tracking is enabled, in case the
* user turns it on/off while mouse tracking is requested.
*/
void setAllowMouseTracking(const bool allow);
bool hasCompositeFocus() const bool hasCompositeFocus() const
{ {
return _hasCompositeFocus; return _hasCompositeFocus;
@ -667,6 +674,7 @@ private:
bool _showTerminalSizeHint; bool _showTerminalSizeHint;
bool _bidiEnabled; bool _bidiEnabled;
bool _usesMouseTracking; bool _usesMouseTracking;
bool _allowMouseTracking;
bool _bracketedPasteMode; bool _bracketedPasteMode;
QPoint _iPntSel; // initial selection point QPoint _iPntSel; // initial selection point

Loading…
Cancel
Save