diff --git a/src/Emulation.h b/src/Emulation.h --- a/src/Emulation.h +++ b/src/Emulation.h @@ -209,13 +209,15 @@ virtual void reset() = 0; /** - * Returns true if the active terminal program wants - * mouse input events. + * Returns true if the active terminal program is interested in Mouse + * Tracking events. * - * The programUsesMouseChanged() signal is emitted when this - * changes. + * The programRequestsMouseTracking() signal is emitted when a program + * indicates it's interested in Mouse Tracking events. + * + * See MODE_Mouse100{0,1,2,3} in Vt102Emulation. */ - bool programUsesMouse() const; + bool programUsesMouseTracking() const; bool programBracketedPasteMode() const; @@ -317,13 +319,16 @@ void changeTabTextColorRequest(int color); /** - * This is emitted when the program running in the shell indicates whether or - * not it is interested in mouse events. + * This is emitted when the program (typically editors and other full-screen + * applications, ones that take up the whole terminal display), running in + * the terminal indicates whether or not it is interested in Mouse Tracking + * events. This is an XTerm extension, for more information have a look at: + * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Mouse-Tracking * - * @param usesMouse This will be true if the program wants to be informed about - * mouse events or false otherwise. + * @param usesMouseTracking This will be true if the program is interested + * in Mouse Tracking events or false otherwise. */ - void programUsesMouseChanged(bool usesMouse); + void programRequestsMouseTracking(bool usesMouseTracking); void enableAlternateScrolling(bool enable); @@ -504,14 +509,14 @@ // view void showBulk(); - void usesMouseChanged(bool usesMouse); + void setUsesMouseTracking(bool usesMouseTracking); void bracketedPasteModeChanged(bool bracketedPasteMode); private: Q_DISABLE_COPY(Emulation) - bool _usesMouse; + bool _usesMouseTracking; bool _bracketedPasteMode; QTimer _bulkTimer1; QTimer _bulkTimer2; diff --git a/src/Emulation.cpp b/src/Emulation.cpp --- a/src/Emulation.cpp +++ b/src/Emulation.cpp @@ -39,7 +39,7 @@ _codec(nullptr), _decoder(nullptr), _keyTranslator(nullptr), - _usesMouse(false), + _usesMouseTracking(false), _bracketedPasteMode(false), _bulkTimer1(new QTimer(this)), _bulkTimer2(new QTimer(this)), @@ -54,20 +54,20 @@ QObject::connect(&_bulkTimer2, &QTimer::timeout, this, &Konsole::Emulation::showBulk); // listen for mouse status changes - connect(this, &Konsole::Emulation::programUsesMouseChanged, this, - &Konsole::Emulation::usesMouseChanged); + connect(this, &Konsole::Emulation::programRequestsMouseTracking, this, + &Konsole::Emulation::setUsesMouseTracking); connect(this, &Konsole::Emulation::programBracketedPasteModeChanged, this, &Konsole::Emulation::bracketedPasteModeChanged); } -bool Emulation::programUsesMouse() const +bool Emulation::programUsesMouseTracking() const { - return _usesMouse; + return _usesMouseTracking; } -void Emulation::usesMouseChanged(bool usesMouse) +void Emulation::setUsesMouseTracking(bool usesMouseTracking) { - _usesMouse = usesMouse; + _usesMouseTracking = usesMouseTracking; } bool Emulation::programBracketedPasteMode() const diff --git a/src/Profile.h b/src/Profile.h --- a/src/Profile.h +++ b/src/Profile.h @@ -269,16 +269,19 @@ * increases/decreases the terminal font size. */ MouseWheelZoomEnabled, - /** (bool) Specifies whether emulated up/down key presses are sent - * for mouse scroll wheel events, to programs using the Alternate - * Screen buffer if those programs indicate they're not interested - * in mouse events (check _usesMouse in the Emulation header); this - * is mainly for the benefit of programs that are never interested - * in mouse events (e.g. less). - * Some programs, such as vim, can tell the terminal whether they - * are interested in mouse events or not. Consequently, this option - * affects vim only if it indicates that it's not interested in - * mouse events. + /** (bool) Specifies whether emulated up/down key press events are + * sent, for mouse scroll wheel events, to programs using the + * Alternate Screen buffer; this is mainly for the benefit of + * programs that don't natively support mouse scroll events, e.g. + * less. + * + * This also works for scrolling in applications that support Mouse + * Tracking events but don't indicate they're interested in those + * events; for example, when vim doesn't indicate it's interested + * in Mouse Tracking events (i.e. when the mouse is in Normal + * (not Visual) mode): http://vimdoc.sourceforge.net/htmldoc/intro.html#Normal + * mouse wheel scroll events will send up/down key press events. + * * Default value is true. * See also, MODE_Mouse1007 in the Emulation header, which toggles * Alternate Scrolling with escape sequences. diff --git a/src/Session.cpp b/src/Session.cpp --- a/src/Session.cpp +++ b/src/Session.cpp @@ -304,11 +304,11 @@ connect(widget, &Konsole::TerminalDisplay::mouseSignal, _emulation, &Konsole::Emulation::sendMouseEvent); connect(widget, &Konsole::TerminalDisplay::sendStringToEmu, _emulation, &Konsole::Emulation::sendString); - // allow emulation to notify view when the foreground process - // indicates whether or not it is interested in mouse signals - connect(_emulation, &Konsole::Emulation::programUsesMouseChanged, widget, &Konsole::TerminalDisplay::setUsesMouse); + // allow emulation to notify the view when the foreground process + // indicates whether or not it is interested in Mouse Tracking events + connect(_emulation, &Konsole::Emulation::programRequestsMouseTracking, widget, &Konsole::TerminalDisplay::setUsesMouseTracking); - widget->setUsesMouse(_emulation->programUsesMouse()); + widget->setUsesMouseTracking(_emulation->programUsesMouseTracking()); connect(_emulation, &Konsole::Emulation::enableAlternateScrolling, widget, &Konsole::TerminalDisplay::setAlternateScrolling); diff --git a/src/TerminalDisplay.h b/src/TerminalDisplay.h --- a/src/TerminalDisplay.h +++ b/src/TerminalDisplay.h @@ -564,8 +564,8 @@ return _flowControlWarningEnabled; } - /** See setUsesMouse() */ - bool usesMouse() const; + /** See setUsesMouseTracking() */ + bool usesMouseTracking() const; /** See setAlternateScrolling() */ bool alternateScrolling() const; @@ -628,20 +628,21 @@ void outputSuspended(bool suspended); /** - * Sets whether the program whose output is being displayed in the view - * is interested in mouse events. + * Sets whether the program currently running in the terminal is interested + * in Mouse Tracking events. * - * If this is set to true, mouse signals will be emitted by the view when the user clicks, drags - * or otherwise moves the mouse inside the view. - * The user interaction needed to create selections will also change, and the user will be required - * to hold down the shift key to create a selection or perform other mouse activities inside the - * view area - since the program running in the terminal is being allowed to handle normal mouse - * events itself. + * When set to true, Konsole will send Mouse Tracking events. * - * @param on Set to true if the program running in the terminal is interested in mouse events - * or false otherwise. + * The user interaction needed to create text selections will change + * also, and the user will be required to hold down the Shift key to + * create a selection or perform other mouse activities inside the view + * area, since the program running in the terminal is being allowed + * to handle normal mouse events itself. + * + * @param on Set to true if the program running in the terminal is + * interested in Mouse Tracking events or false otherwise. */ - void setUsesMouse(bool on); + void setUsesMouseTracking(bool on); /** * Sets the AlternateScrolling profile property which controls whether @@ -713,8 +714,8 @@ void changedContentSizeSignal(int height, int width); /** - * Emitted when the user right clicks on the display, or right-clicks with the Shift - * key held down if usesMouse() is true. + * Emitted when the user right clicks on the display, or right-clicks + * with the Shift key held down if usesMouseTracking() is true. * * This can be used to display a context menu. */ @@ -955,7 +956,7 @@ bool _resizing; bool _showTerminalSizeHint; bool _bidiEnabled; - bool _mouseMarks; + bool _usesMouseTracking; bool _alternateScrolling; bool _isPrimaryScreen; bool _bracketedPasteMode; diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -381,7 +381,7 @@ , _resizing(false) , _showTerminalSizeHint(true) , _bidiEnabled(false) - , _mouseMarks(false) + , _usesMouseTracking(false) , _alternateScrolling(true) , _isPrimaryScreen(true) , _bracketedPasteMode(false) @@ -469,7 +469,7 @@ KCursor::setAutoHideCursor(this, true); setMouseTracking(true); - setUsesMouse(true); + setUsesMouseTracking(false); setBracketedPasteMode(false); setColorTable(ColorScheme::defaultTable); @@ -2255,9 +2255,9 @@ _preserveLineBreaks = !(((ev->modifiers() & Qt::ControlModifier) != 0u) && !(ev->modifiers() & Qt::AltModifier)); _columnSelectionMode = ((ev->modifiers() & Qt::AltModifier) != 0u) && ((ev->modifiers() & Qt::ControlModifier) != 0u); - if (_mouseMarks || (ev->modifiers() == Qt::ShiftModifier)) { + if (!_usesMouseTracking || (ev->modifiers() == Qt::ShiftModifier)) { // Only extend selection for programs not interested in mouse - if (_mouseMarks && (ev->modifiers() == Qt::ShiftModifier)) { + if (!_usesMouseTracking && (ev->modifiers() == Qt::ShiftModifier)) { extendSelection(ev->pos()); } else { _screenWindow->clearSelection(); @@ -2284,7 +2284,7 @@ } else if (ev->button() == Qt::MidButton) { processMidButtonClick(ev); } else if (ev->button() == Qt::RightButton) { - if (_mouseMarks || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) { + if (!_usesMouseTracking || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) { emit configureRequest(ev->pos()); } else { if(!_readOnly) { @@ -2351,7 +2351,7 @@ update(_mouseOverHotspotArea | previousHotspotArea); } else if (!_mouseOverHotspotArea.isEmpty()) { if ((_openLinksByDirectClick || ((ev->modifiers() & Qt::ControlModifier) != 0u)) || (cursor().shape() == Qt::PointingHandCursor)) { - setCursor(_mouseMarks ? Qt::IBeamCursor : Qt::ArrowCursor); + setCursor(_usesMouseTracking ? Qt::ArrowCursor : Qt::IBeamCursor); } update(_mouseOverHotspotArea); @@ -2364,10 +2364,10 @@ return; } - // if the terminal is interested in mouse movements - // then emit a mouse movement signal, unless the shift - // key is being held down, which overrides this. - if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier)) { + // if the program running in the terminal is interested in Mouse Tracking + // evnets 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; if ((ev->buttons() & Qt::LeftButton) != 0u) { button = 0; @@ -2637,16 +2637,16 @@ // outside the range. The procedure used in `mouseMoveEvent' // applies here, too. - if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier)) { + if (_usesMouseTracking && !(ev->modifiers() & Qt::ShiftModifier)) { emit mouseSignal(0, charColumn + 1, charLine + 1 + _scrollBar->value() - _scrollBar->maximum() , 2); } } _dragInfo.state = diNone; } - if (!_mouseMarks && + if (_usesMouseTracking && (ev->button() == Qt::RightButton || ev->button() == Qt::MidButton) && !(ev->modifiers() & Qt::ShiftModifier)) { emit mouseSignal(ev->button() == Qt::MidButton ? 1 : 2, @@ -2680,7 +2680,7 @@ void TerminalDisplay::processMidButtonClick(QMouseEvent* ev) { - if (_mouseMarks || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) { + if (!_usesMouseTracking || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) { const bool appendEnter = (ev->modifiers() & Qt::ControlModifier) != 0u; if (_middleClickPasteMode == Enum::PasteFromX11Selection) { @@ -2724,7 +2724,7 @@ QPoint pos(qMin(charColumn, _columns - 1), qMin(charLine, _lines - 1)); // pass on double click as two clicks. - if (!_mouseMarks && !(ev->modifiers() & Qt::ShiftModifier)) { + if (_usesMouseTracking && !(ev->modifiers() & Qt::ShiftModifier)) { if(!_readOnly) { // Send just _ONE_ click event, since the first click of the double click // was already sent by the click handler @@ -2823,9 +2823,10 @@ // wheel-down for decreasing font size decreaseFontSize(); } - } else if (_mouseMarks && (_scrollBar->maximum() > 0)) { - // If the program running in the terminal is not interested in mouse events, - // send the event to the scrollbar if the slider has room to move + } else if (!_usesMouseTracking && (_scrollBar->maximum() > 0)) { + // If the program running in the terminal is not interested in Mouse + // Tracking events, send the event to the scrollbar if the slider + // has room to move _scrollWheelState.addWheelEvent(ev); @@ -2835,7 +2836,7 @@ } else if (!_readOnly) { _scrollWheelState.addWheelEvent(ev); - if(_mouseMarks && !_isPrimaryScreen && _alternateScrolling) { + if(!_usesMouseTracking && !_isPrimaryScreen && _alternateScrolling) { // Send simulated up / down key presses to the terminal program // for the benefit of programs such as 'less' (which use the alternate screen) @@ -2854,7 +2855,7 @@ _screenWindow->screen()->setCurrentTerminalDisplay(this); emit keyPressedSignal(&keyEvent); } - } else if (!_mouseMarks) { + } else if (_usesMouseTracking) { // terminal program wants notification of mouse activity int charLine; @@ -3189,17 +3190,14 @@ _wordCharacters = wc; } -// FIXME: the actual value of _mouseMarks is the opposite of its semantic. -// When using programs not interested with mouse(shell, less), it is true. -// When using programs interested with mouse(vim,mc), it is false. -void TerminalDisplay::setUsesMouse(bool on) +void TerminalDisplay::setUsesMouseTracking(bool on) { - _mouseMarks = on; - setCursor(_mouseMarks ? Qt::IBeamCursor : Qt::ArrowCursor); + _usesMouseTracking = on; + setCursor(_usesMouseTracking ? Qt::ArrowCursor : Qt::IBeamCursor); } -bool TerminalDisplay::usesMouse() const +bool TerminalDisplay::usesMouseTracking() const { - return _mouseMarks; + return _usesMouseTracking; } void TerminalDisplay::setAlternateScrolling(bool enable) diff --git a/src/Vt102Emulation.cpp b/src/Vt102Emulation.cpp --- a/src/Vt102Emulation.cpp +++ b/src/Vt102Emulation.cpp @@ -1401,7 +1401,7 @@ case MODE_Mouse1001: case MODE_Mouse1002: case MODE_Mouse1003: - emit programUsesMouseChanged(false); + emit programRequestsMouseTracking(true); break; case MODE_Mouse1007: emit enableAlternateScrolling(true); @@ -1438,7 +1438,7 @@ case MODE_Mouse1001: case MODE_Mouse1002: case MODE_Mouse1003: - emit programUsesMouseChanged(true); + emit programRequestsMouseTracking(false); break; case MODE_Mouse1007: emit enableAlternateScrolling(false);