From d2716c834b6eb1b39bfe56b67d55482473bd10ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 4 Mar 2016 14:15:27 +0100 Subject: [PATCH] Pass pointer and wheel events to TabBox from special event filter The TabBox implements methods for those events and performs same logic as on X11. Click outside of TabBox closes. If the event is on the TabBox we don't filter the event out and let the internal filter forward the event. --- input.cpp | 13 +++++++++++++ tabbox/tabbox.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++++ tabbox/tabbox.h | 4 ++++ 3 files changed, 65 insertions(+) diff --git a/input.cpp b/input.cpp index 0f737fa9d6..c78c741203 100644 --- a/input.cpp +++ b/input.cpp @@ -481,6 +481,13 @@ public: class TabBoxInputFilter : public InputEventFilter { public: + bool pointerEvent(QMouseEvent *event, quint32 button) override { + Q_UNUSED(button) + if (!TabBox::TabBox::self() || !TabBox::TabBox::self()->isGrabbed()) { + return false; + } + return TabBox::TabBox::self()->handleMouseEvent(event); + } bool keyEvent(QKeyEvent *event) override { if (!TabBox::TabBox::self() || !TabBox::TabBox::self()->isGrabbed()) { return false; @@ -488,6 +495,12 @@ public: TabBox::TabBox::self()->keyPress(event->modifiers() | event->key()); return true; } + bool wheelEvent(QWheelEvent *event) override { + if (!TabBox::TabBox::self() || !TabBox::TabBox::self()->isGrabbed()) { + return false; + } + return TabBox::TabBox::self()->handleWheelEvent(event); + } }; #endif diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index db7c5cd0be..a930f3f2d3 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -901,6 +901,54 @@ bool TabBox::handleMouseEvent(xcb_motion_notify_event_t *e) return false; } +bool TabBox::handleMouseEvent(QMouseEvent *event) +{ + if (!m_isShown && isDisplayed()) { + // tabbox has been replaced, check effects + if (effects && static_cast(effects)->checkInputWindowEvent(event)) { + return true; + } + } + switch (event->type()) { + case QEvent::MouseMove: + if (!m_tabBox->containsPos(event->globalPos())) { + // filter out all events which are not on the TabBox window. + // We don't want windows to react on the mouse events + return true; + } + return false; + case QEvent::MouseButtonPress: + if ((!m_isShown && isDisplayed()) || !m_tabBox->containsPos(event->globalPos())) { + close(); // click outside closes tab + return true; + } + // fall through + case QEvent::MouseButtonRelease: + default: + // we do not filter it out, the intenal filter takes care + return false; + } + return false; +} + +bool TabBox::handleWheelEvent(QWheelEvent *event) +{ + if (!m_isShown && isDisplayed()) { + // tabbox has been replaced, check effects + if (effects && static_cast(effects)->checkInputWindowEvent(event)) { + return true; + } + } + if (event->angleDelta().y() == 0) { + return false; + } + const QModelIndex index = m_tabBox->nextPrev(event->angleDelta().y() > 0); + if (index.isValid()) { + setCurrentIndex(index); + } + return true; +} + void TabBox::grabbedKeyEvent(QKeyEvent* event) { emit tabBoxKeyEvent(event); diff --git a/tabbox/tabbox.h b/tabbox/tabbox.h index 3b6da64e49..a7bdce6a85 100644 --- a/tabbox/tabbox.h +++ b/tabbox/tabbox.h @@ -31,7 +31,9 @@ along with this program. If not, see . class KConfigGroup; class QAction; +class QMouseEvent; class QKeyEvent; +class QWheelEvent; struct xcb_button_press_event_t; struct xcb_motion_notify_event_t; @@ -162,6 +164,8 @@ public: bool handleMouseEvent(xcb_button_press_event_t *e); bool handleMouseEvent(xcb_motion_notify_event_t *e); + bool handleMouseEvent(QMouseEvent *event); + bool handleWheelEvent(QWheelEvent *event); void grabbedKeyEvent(QKeyEvent* event); bool isGrabbed() const {