diff --git a/src/MainWindow.h b/src/MainWindow.h --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -121,6 +121,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; 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" @@ -220,6 +222,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 @@ -243,6 +249,7 @@ Q_ASSERT(controller); _pluggedController = controller; + _pluggedController->view()->installEventFilter(this); setBlur(ViewManager::profileHasBlurEnabled(SessionManager::instance()->sessionProfile(_pluggedController->session()))); @@ -881,6 +888,40 @@ KXmlGuiWindow::showEvent(event); } +bool MainWindow::eventFilter(QObject *obj, QEvent *event) +{ + if (obj != _pluggedController->view()) { + return QObject::eventFilter(obj, event); + } + + switch(event->type()) { + case QEvent::MouseButtonPress: + case QEvent::MouseButtonDblClick: + switch(static_cast(event)->button()) { + case Qt::ForwardButton: + if (auto nextView = actionCollection()->action(QStringLiteral("next-view"))) { + if (nextView->isEnabled()) { + nextView->trigger(); + return true; + } + } + break; + case Qt::BackButton: + if (auto prevView = actionCollection()->action(QStringLiteral("previous-view"))) { + if (prevView->isEnabled()) { + prevView->trigger(); + return true; + } + } + break; + default: ; + } + default: ; + } + + return QObject::eventFilter(obj, event); +} + bool MainWindow::focusNextPrevChild(bool) { // In stand-alone konsole, always disable implicit focus switching