[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin] /: Move X11 movingClient handling into a dedicated X11EventFilter
From:       Martin_Flöser <null () kde ! org>
Date:       2017-09-01 15:11:26
Message-ID: E1dnnbS-0007Tn-JB () code ! kde ! org
[Download RAW message or body]

Git commit bd5f5e0915b3178b753dc90f7cc893b46f13bef6 by Martin Flöser.
Committed on 01/09/2017 at 14:57.
Pushed by graesslin into branch 'master'.

Move X11 movingClient handling into a dedicated X11EventFilter

Summary:
Splits out the X11 specific window movement handling so that it's not
used in the Wayland case at runtime. As a nice side effect it
un-spaghetties the X11 event handler.

Test Plan:
Run nested KWin on Xephyr and nested KWin/Wayland to verify
that move/resize of X11 windows is still working

Reviewers: #kwin, #plasma

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D7374

M  +1    -0    CMakeLists.txt
M  +0    -11   events.cpp
A  +62   -0    moving_client_x11_filter.cpp     [License: GPL (v2)]
A  +38   -0    moving_client_x11_filter.h     [License: GPL (v2)]
M  +2    -0    workspace.cpp
M  +1    -0    workspace.h

https://commits.kde.org/kwin/bd5f5e0915b3178b753dc90f7cc893b46f13bef6

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 97313160d..9c6b68034 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -455,6 +455,7 @@ set(kwin_KDEINIT_SRCS
     abstract_opengl_context_attribute_builder.cpp
     egl_context_attribute_builder.cpp
     was_user_interaction_x11_filter.cpp
+    moving_client_x11_filter.cpp
    )
 
 if(KWIN_BUILD_TABBOX)
diff --git a/events.cpp b/events.cpp
index 74c0d155d..933dc38b3 100644
--- a/events.cpp
+++ b/events.cpp
@@ -304,10 +304,6 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e)
         xcb_key_press_event_t *event = reinterpret_cast<xcb_key_press_event_t*>(e);
         KKeyServer::xcbKeyPressEventToQt(event, &keyQt);
 //            qDebug() << "Workspace::keyPress( " << keyQt << " )";
-        if (Client *c = dynamic_cast<Client*>(movingClient)) {
-            c->keyPressEvent(keyQt, event->time);
-            return true;
-        }
 #ifdef KWIN_BUILD_TABBOX
         if (TabBox::TabBox::self()->isGrabbed()) {
             TabBox::TabBox::self()->keyPress(keyQt);
@@ -357,13 +353,6 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e)
             }
         }
     }
-    if (Client *c = dynamic_cast<Client*>(movingClient)) {
-        if (eventType == XCB_BUTTON_PRESS || eventType == XCB_BUTTON_RELEASE || \
                eventType == XCB_MOTION_NOTIFY) {
-            if (c->moveResizeGrabWindow() == \
                reinterpret_cast<xcb_button_press_event_t*>(e)->event && \
                c->windowEvent(e)) {
-                return true;
-            }
-        }
-    }
 
     switch (eventType) {
     case XCB_CREATE_NOTIFY: {
diff --git a/moving_client_x11_filter.cpp b/moving_client_x11_filter.cpp
new file mode 100644
index 000000000..1df408830
--- /dev/null
+++ b/moving_client_x11_filter.cpp
@@ -0,0 +1,62 @@
+/********************************************************************
+ KWin - the KDE window manager
+ This file is part of the KDE project.
+
+Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#include "moving_client_x11_filter.h"
+#include "client.h"
+#include "workspace.h"
+#include <KKeyServer>
+#include <xcb/xcb.h>
+
+namespace KWin
+{
+
+MovingClientX11Filter::MovingClientX11Filter()
+    : X11EventFilter(QVector<int>{XCB_KEY_PRESS, XCB_MOTION_NOTIFY, \
XCB_BUTTON_PRESS, XCB_BUTTON_RELEASE}) +{
+}
+
+bool MovingClientX11Filter::event(xcb_generic_event_t *event)
+{
+    auto client = dynamic_cast<Client*>(workspace()->getMovingClient());
+    if (!client) {
+        return false;
+    }
+    auto testWindow = [client, event] (xcb_window_t window) {
+        return client->moveResizeGrabWindow() == window && \
client->windowEvent(event); +    };
+
+    const uint8_t eventType = event->response_type & ~0x80;
+    switch (eventType) {
+    case XCB_KEY_PRESS: {
+        int keyQt;
+        xcb_key_press_event_t *keyEvent = \
reinterpret_cast<xcb_key_press_event_t*>(event); +        \
KKeyServer::xcbKeyPressEventToQt(keyEvent, &keyQt); +        \
client->keyPressEvent(keyQt, keyEvent->time); +        return true;
+    }
+    case XCB_BUTTON_PRESS:
+    case XCB_BUTTON_RELEASE:
+        return testWindow(reinterpret_cast<xcb_button_press_event_t*>(event)->event);
 +    case XCB_MOTION_NOTIFY:
+        return testWindow(reinterpret_cast<xcb_motion_notify_event_t*>(event)->event);
 +    }
+    return false;
+}
+
+}
diff --git a/moving_client_x11_filter.h b/moving_client_x11_filter.h
new file mode 100644
index 000000000..617760fa4
--- /dev/null
+++ b/moving_client_x11_filter.h
@@ -0,0 +1,38 @@
+/********************************************************************
+ KWin - the KDE window manager
+ This file is part of the KDE project.
+
+Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*********************************************************************/
+#ifndef KWIN_MOVING_CLIENT_X11_FILTER_H
+#define KWIN_MOVING_CLIENT_X11_FILTER_H
+#include "x11eventfilter.h"
+
+namespace KWin
+{
+
+class MovingClientX11Filter : public X11EventFilter
+{
+public:
+    explicit MovingClientX11Filter();
+
+    bool event(xcb_generic_event_t *event) override;
+};
+
+}
+
+#endif
+
diff --git a/workspace.cpp b/workspace.cpp
index 61f214768..d62c2a71c 100644
--- a/workspace.cpp
+++ b/workspace.cpp
@@ -39,6 +39,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "group.h"
 #include "input.h"
 #include "logind.h"
+#include "moving_client_x11_filter.h"
 #include "killwindow.h"
 #include "netinfo.h"
 #include "outline.h"
@@ -217,6 +218,7 @@ void Workspace::init()
 {
     if (kwinApp()->operationMode() == Application::OperationModeX11) {
         m_wasUserInteractionFilter.reset(new WasUserInteractionX11Filter);
+        m_movingClientFilter.reset(new MovingClientX11Filter);
     }
     updateXTime(); // Needed for proper initialization of user_time in Client ctor
     KSharedConfigPtr config = kwinApp()->config();
diff --git a/workspace.h b/workspace.h
index 995cd8333..9b60724b2 100644
--- a/workspace.h
+++ b/workspace.h
@@ -624,6 +624,7 @@ private:
 
     QList<X11EventFilter *> m_eventFilters;
     QList<X11EventFilter *> m_genericEventFilters;
+    QScopedPointer<X11EventFilter> m_movingClientFilter;
 
 private:
     friend bool performTransiencyCheck();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic