diff --git a/src/MainWindow.h b/src/MainWindow.h --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -119,6 +119,7 @@ protected: // Reimplemented for internal reasons. void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; + bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; // reimplemented from KMainWindow bool queryClose() Q_DECL_OVERRIDE; @@ -168,6 +169,7 @@ void restoreMenuAccelerators(); void setupActions(); QString activeSessionDir() const; + void triggerAction(const QString &name) const; /** * Returns the bookmark handler associated with this window. diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -22,6 +22,7 @@ // Qt #include +#include // KDE #include @@ -54,6 +55,7 @@ #include "ProfileManager.h" #include "KonsoleSettings.h" #include "WindowSystemInfo.h" +#include "TerminalDisplay.h" #include "settings/FileLocationSettings.h" #include "settings/GeneralSettings.h" #include "settings/ProfileSettings.h" @@ -219,6 +221,10 @@ disconnect(controller, &Konsole::SessionController::iconChanged, this, &Konsole::MainWindow::updateWindowIcon); + if (auto view = controller->view()) { + view->removeEventFilter(this); + } + // KXmlGuiFactory::removeClient() will try to access actions associated // with the controller internally, which may not be valid after the controller // itself is no longer valid (after the associated session and or view have @@ -242,6 +248,7 @@ Q_ASSERT(controller); _pluggedController = controller; + _pluggedController->view()->installEventFilter(this); setBlur(ViewManager::profileHasBlurEnabled(SessionManager::instance()->sessionProfile(_pluggedController->session()))); @@ -829,6 +836,37 @@ KXmlGuiWindow::showEvent(event); } +void MainWindow::triggerAction(const QString &name) const +{ + if (auto action = actionCollection()->action(name)) { + if (action->isEnabled()) { + action->trigger(); + } + } +} + +bool MainWindow::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == _pluggedController->view()) { + switch(event->type()) { + case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: + switch(static_cast(event)->button()) { + case Qt::ForwardButton: + triggerAction(QStringLiteral("next-view")); + break; + case Qt::BackButton: + triggerAction(QStringLiteral("previous-view")); + break; + default: ; + } + default: ; + } + } + + return KXmlGuiWindow::eventFilter(obj, event); +} + bool MainWindow::focusNextPrevChild(bool) { // In stand-alone konsole, always disable implicit focus switching