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.
This commit is contained in:
Martin Gräßlin 2016-03-04 14:15:27 +01:00
parent 6c0ed26c65
commit d2716c834b
3 changed files with 65 additions and 0 deletions

View file

@ -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

View file

@ -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<EffectsHandlerImpl*>(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<EffectsHandlerImpl*>(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);

View file

@ -31,7 +31,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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 {