diff --git a/lib/Emulation.cpp b/lib/Emulation.cpp index 001d15b0..41e3bebc 100644 --- a/lib/Emulation.cpp +++ b/lib/Emulation.cpp @@ -118,6 +118,11 @@ ScreenWindow* Emulation::createWindow() return window; } +void Emulation::checkScreenInUse() +{ + emit primaryScreenInUse(_currentScreen == _screen[0]); +} + Emulation::~Emulation() { QListIterator windowIter(_windows); @@ -141,6 +146,7 @@ void Emulation::setScreen(int n) // tell all windows onto this emulation to switch to the newly active screen for(ScreenWindow* window : qAsConst(_windows)) window->setScreen(_currentScreen); + checkScreenInUse(); } } diff --git a/lib/Emulation.h b/lib/Emulation.h index 7d2263b5..ccb5c031 100644 --- a/lib/Emulation.h +++ b/lib/Emulation.h @@ -433,6 +433,12 @@ public slots: */ void flowControlKeyPressed(bool suspendKeyPressed); + /** + * Emitted when the active screen is switched, to indicate whether the primary + * screen is in use. + */ + void primaryScreenInUse(bool use); + /** * Emitted when the cursor shape or its blinking state is changed via * DECSCUSR sequences. @@ -497,6 +503,9 @@ protected slots: */ void bufferedUpdate(); + // used to emit the primaryScreenInUse(bool) signal + void checkScreenInUse(); + private slots: // triggered by timer, causes the emulation to send an updated screen image to each diff --git a/lib/Session.cpp b/lib/Session.cpp index 4891e4ee..7a4c89fa 100644 --- a/lib/Session.cpp +++ b/lib/Session.cpp @@ -71,6 +71,7 @@ Session::Session(QObject* parent) : // , _zmodemProc(0) // , _zmodemProgress(0) , _hasDarkBackground(false) + , _isPrimaryScreen(true) { //prepare DBus communication // new SessionAdaptor(this); @@ -94,7 +95,8 @@ Session::Session(QObject* parent) : this, SIGNAL( changeTabTextColorRequest( int ) ) ); connect( _emulation, SIGNAL(profileChangeCommandReceived(const QString &)), this, SIGNAL( profileChangeCommandReceived(const QString &)) ); - + connect(_emulation, &Konsole::Emulation::primaryScreenInUse, + this, &Session::onPrimaryScreenInUse); connect(_emulation, SIGNAL(imageResizeRequest(QSize)), this, SLOT(onEmulationSizeChange(QSize))); connect(_emulation, SIGNAL(imageSizeChanged(int, int)), @@ -204,6 +206,8 @@ void Session::addView(TerminalDisplay * widget) SLOT(viewDestroyed(QObject *)) ); //slot for close QObject::connect(this, SIGNAL(finished()), widget, SLOT(close())); +//slot for primaryScreen + QObject::connect(this, &Session::primaryScreenInUse, widget, &TerminalDisplay::usingPrimaryScreen); } @@ -448,6 +452,11 @@ void Session::monitorTimerDone() _notifiedActivity=false; } +bool Session::isPrimaryScreen() +{ + return _isPrimaryScreen; +} + void Session::activityStateSet(int state) { if (state==NOTIFYBELL) { @@ -485,6 +494,12 @@ void Session::onEmulationSizeChange(QSize size) setSize(size); } +void Session::onPrimaryScreenInUse(bool use) +{ + _isPrimaryScreen = use; + emit primaryScreenInUse(use); +} + void Session::updateTerminalSize() { QListIterator viewIter(_views); diff --git a/lib/Session.h b/lib/Session.h index b2a4d6ad..5ab89f3d 100644 --- a/lib/Session.h +++ b/lib/Session.h @@ -375,6 +375,10 @@ class Session : public QObject { */ int getPtySlaveFd() const; + // Returns true if the current screen is the secondary/alternate one + // or false if it's the primary/normal buffer + bool isPrimaryScreen(); + public slots: /** @@ -480,6 +484,15 @@ public slots: */ void flowControlEnabledChanged(bool enabled); + /** + * Emitted when the active screen is switched, to indicate whether the primary + * screen is in use. + * + * This signal serves as a relayer of Emulation::priamyScreenInUse(bool), + * making it usable for higher level component. + */ + void primaryScreenInUse(bool use); + /** * Broker for Emulation::cursorChanged() signal */ @@ -509,6 +522,9 @@ private slots: // void zmodemRcvBlock(const char *data, int len); // void zmodemFinished(); + // Relays the signal from Emulation and sets _isPrimaryScreen + void onPrimaryScreenInUse(bool use); + private: void updateTerminalSize(); @@ -570,6 +586,7 @@ private slots: int ptySlaveFd; + bool _isPrimaryScreen; }; /** diff --git a/lib/TerminalDisplay.cpp b/lib/TerminalDisplay.cpp index a36d3914..14955031 100644 --- a/lib/TerminalDisplay.cpp +++ b/lib/TerminalDisplay.cpp @@ -334,6 +334,7 @@ TerminalDisplay::TerminalDisplay(QWidget *parent) ,_terminalSizeStartup(true) ,_bidiEnabled(false) ,_mouseMarks(false) +,_isPrimaryScreen(true) ,_disabledBracketedPasteMode(false) ,_actSel(0) ,_wordSelectionMode(false) @@ -2554,17 +2555,13 @@ void TerminalDisplay::wheelEvent( QWheelEvent* ev ) if (ev->angleDelta().y() == 0) return; - // if the terminal program is not interested mouse events - // then send the event to the scrollbar if the slider has room to move - // or otherwise send simulated up / down key presses to the terminal program - // for the benefit of programs such as 'less' - if ( _mouseMarks ) - { - bool canScroll = _scrollBar->maximum() > 0; - if (canScroll) - _scrollBar->event(ev); - 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 + _scrollBar->event(ev); + } else if(_mouseMarks && !_isPrimaryScreen) { // assume that each Up / Down key event will cause the terminal application // to scroll by one line. // @@ -2581,21 +2578,18 @@ void TerminalDisplay::wheelEvent( QWheelEvent* ev ) for (int i=0;iposition() , charLine , charColumn ); + int charLine; + int charColumn; + getCharacterPosition( ev->pos() , charLine , charColumn ); - emit mouseSignal( ev->angleDelta().y() > 0 ? 4 : 5, - charColumn + 1, - charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , - 0); - } + emit mouseSignal( ev->angleDelta().y() > 0 ? 4 : 5, + charColumn + 1, + charLine + 1 +_scrollBar->value() -_scrollBar->maximum() , + 0); + } } void TerminalDisplay::tripleClickTimeout() @@ -2700,6 +2694,11 @@ bool TerminalDisplay::usesMouse() const return _mouseMarks; } +void TerminalDisplay::usingPrimaryScreen(bool use) +{ + _isPrimaryScreen = use; +} + void TerminalDisplay::setBracketedPasteMode(bool on) { _bracketedPasteMode = on; diff --git a/lib/TerminalDisplay.h b/lib/TerminalDisplay.h index af9cd176..44196f48 100644 --- a/lib/TerminalDisplay.h +++ b/lib/TerminalDisplay.h @@ -505,6 +505,15 @@ public slots: /** See setUsesMouse() */ bool usesMouse() const; + /** + * Sets _isPrimaryScreen depending on which screen is currently in + * use, primary or alternate + * + * @param use Set to @c true if the primary screen is in use or to + * @c false otherwise (i.e. the alternate screen is in use) + */ + void usingPrimaryScreen(bool use); + void setBracketedPasteMode(bool bracketedPasteMode); bool bracketedPasteMode() const; @@ -767,6 +776,7 @@ private slots: bool _terminalSizeStartup; bool _bidiEnabled; bool _mouseMarks; + bool _isPrimaryScreen; bool _bracketedPasteMode; bool _disabledBracketedPasteMode;