diff --git a/src/TerminalDisplay.h b/src/TerminalDisplay.h --- a/src/TerminalDisplay.h +++ b/src/TerminalDisplay.h @@ -24,6 +24,7 @@ // Qt #include #include +#include #include // Konsole @@ -45,6 +46,7 @@ class QScrollBar; class QShowEvent; class QHideEvent; +class QTabBar; class QTimerEvent; class KMessageWidget; @@ -930,6 +932,7 @@ QVBoxLayout *_verticalLayout; bool _fixedFont; // has fixed pitch + int _tabToBeClosedOnMiddleMouseButtonRelease; int _fontHeight; // height int _fontWidth; // width int _fontAscent; // ascend @@ -1071,6 +1074,9 @@ IncrementalSearchBar *_searchBar; QRect _searchResultRect; + + QTabBar *_tabBar; + friend class TerminalDisplayAccessible; }; diff --git a/src/TerminalDisplay.cpp b/src/TerminalDisplay.cpp --- a/src/TerminalDisplay.cpp +++ b/src/TerminalDisplay.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -398,6 +399,7 @@ , _bellMasked(false) , _verticalLayout(new QVBoxLayout(this)) , _fixedFont(true) + , _tabToBeClosedOnMiddleMouseButtonRelease(-1) , _fontHeight(1) , _fontWidth(1) , _fontAscent(1) @@ -475,6 +477,7 @@ , _scrollWheelState(ScrollState()) , _searchBar(new IncrementalSearchBar(this)) , _searchResultRect(QRect()) + , _tabBar(qobject_cast(parent)) { // terminal applications are not designed with Right-To-Left in mind, // so the layout is forced to Left-To-Right @@ -2492,6 +2495,13 @@ } } } else if (ev->button() == Qt::MidButton) { + const int index = _tabBar->tabAt(ev->pos()); + if (index >= 0 && ev->button() == Qt::MiddleButton) { + _tabToBeClosedOnMiddleMouseButtonRelease = index; + return; + } + QWidget::mousePressEvent(ev); + processMidButtonClick(ev); } else if (ev->button() == Qt::RightButton) { if (!_usesMouseTracking || ((ev->modifiers() & Qt::ShiftModifier) != 0u)) { @@ -2827,6 +2837,15 @@ _dragInfo.state = diNone; } + const int index = _tabBar->tabAt(ev->pos()); + if (index >= 0 && index == _tabToBeClosedOnMiddleMouseButtonRelease + && ev->button() == Qt::MiddleButton) { + // Mouse middle click on a tab closes this tab. + emit _tabBar->tabCloseRequested(index); + return; + } + QWidget::mouseReleaseEvent(ev); + if (_usesMouseTracking && (ev->button() == Qt::RightButton || ev->button() == Qt::MidButton) && !(ev->modifiers() & Qt::ShiftModifier)) {