From 6f99b577360d772c6c2569caf986fa0123486b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Fri, 15 Sep 2017 19:59:49 +0200 Subject: [PATCH] Move XFixes cursor change tracking into the x11 standalone platform Summary: A dedicated X11EventFilter is added and created from the X11Cursor in case we have XFixes. This means some more X11 specific code is now only on X11. Test Plan: Only compile tested. Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7843 --- cursor.cpp | 10 ----- cursor.h | 6 --- events.cpp | 2 - .../platforms/x11/standalone/CMakeLists.txt | 1 + .../platforms/x11/standalone/x11cursor.cpp | 20 +++++++++ plugins/platforms/x11/standalone/x11cursor.h | 13 ++++++ .../standalone/xfixes_cursor_event_filter.cpp | 40 ++++++++++++++++++ .../standalone/xfixes_cursor_event_filter.h | 41 +++++++++++++++++++ 8 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 plugins/platforms/x11/standalone/xfixes_cursor_event_filter.cpp create mode 100644 plugins/platforms/x11/standalone/xfixes_cursor_event_filter.h diff --git a/cursor.cpp b/cursor.cpp index 47b55906ba..46d403eab8 100644 --- a/cursor.cpp +++ b/cursor.cpp @@ -227,16 +227,6 @@ void Cursor::doStopCursorTracking() { } -void Cursor::notifyCursorChanged(uint32_t serial) -{ - Q_UNUSED(serial) - if (m_cursorTrackingCounter <= 0) { - // cursor change tracking is currently disabled, so don't emit signal - return; - } - emit cursorChanged(); -} - QVector Cursor::cursorAlternativeNames(const QByteArray &name) const { static const QHash> alternatives = { diff --git a/cursor.h b/cursor.h index f81d214423..ee5c17c89e 100644 --- a/cursor.h +++ b/cursor.h @@ -80,12 +80,6 @@ public: * @see startCursorTracking */ void stopCursorTracking(); - /** - * @internal - * - * Called from X11 event handler. - */ - void notifyCursorChanged(uint32_t serial); /** * @brief The name of the currently used Cursor theme. diff --git a/events.cpp b/events.cpp index c3c028bfbe..2f58be3a36 100644 --- a/events.cpp +++ b/events.cpp @@ -391,8 +391,6 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e) c->syncEvent(reinterpret_cast< xcb_sync_alarm_notify_event_t* >(e)); for (Client *c : desktops) c->syncEvent(reinterpret_cast< xcb_sync_alarm_notify_event_t* >(e)); - } else if (eventType == Xcb::Extensions::self()->fixesCursorNotifyEvent() && Xcb::Extensions::self()->isFixesAvailable()) { - Cursor::self()->notifyCursorChanged(reinterpret_cast(e)->cursor_serial); } break; } diff --git a/plugins/platforms/x11/standalone/CMakeLists.txt b/plugins/platforms/x11/standalone/CMakeLists.txt index de2fa07f43..260987019e 100644 --- a/plugins/platforms/x11/standalone/CMakeLists.txt +++ b/plugins/platforms/x11/standalone/CMakeLists.txt @@ -9,6 +9,7 @@ set(X11PLATFORM_SOURCES screenedges_filter.cpp non_composited_outline.cpp x11_decoration_renderer.cpp + xfixes_cursor_event_filter.cpp ) if(X11_Xinput_FOUND) diff --git a/plugins/platforms/x11/standalone/x11cursor.cpp b/plugins/platforms/x11/standalone/x11cursor.cpp index 21f762c2cc..cd27f0f440 100644 --- a/plugins/platforms/x11/standalone/x11cursor.cpp +++ b/plugins/platforms/x11/standalone/x11cursor.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . #include "keyboard_input.h" #include "utils.h" #include "xcbutils.h" +#include "xfixes_cursor_event_filter.h" #include #include @@ -51,6 +52,16 @@ X11Cursor::X11Cursor(QObject *parent, bool xInputSupport) if (m_hasXInput) { connect(qApp->eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, this, &X11Cursor::aboutToBlock); } + +#ifndef KCMRULES + connect(kwinApp(), &Application::workspaceCreated, this, + [this] { + if (Xcb::Extensions::self()->isFixesAvailable()) { + m_xfixesFilter = std::make_unique(this); + } + } + ); +#endif } X11Cursor::~X11Cursor() @@ -173,4 +184,13 @@ xcb_cursor_t X11Cursor::createCursor(const QByteArray &name) return cursor; } +void X11Cursor::notifyCursorChanged() +{ + if (!isCursorTracking()) { + // cursor change tracking is currently disabled, so don't emit signal + return; + } + emit cursorChanged(); +} + } diff --git a/plugins/platforms/x11/standalone/x11cursor.h b/plugins/platforms/x11/standalone/x11cursor.h index b480c7c711..a735ce30b6 100644 --- a/plugins/platforms/x11/standalone/x11cursor.h +++ b/plugins/platforms/x11/standalone/x11cursor.h @@ -21,8 +21,11 @@ along with this program. If not, see . #define KWIN_X11CURSOR_H #include "cursor.h" +#include + namespace KWin { +class XFixesCursorEventFilter; class KWIN_EXPORT X11Cursor : public Cursor { @@ -35,6 +38,13 @@ public: m_needsPoll = true; } + /** + * @internal + * + * Called from X11 event handler. + */ + void notifyCursorChanged(); + protected: virtual xcb_cursor_t getX11Cursor(Qt::CursorShape shape); xcb_cursor_t getX11Cursor(const QByteArray &name) override; @@ -63,6 +73,9 @@ private: QTimer *m_mousePollingTimer; bool m_hasXInput; bool m_needsPoll; + + std::unique_ptr m_xfixesFilter; + friend class Cursor; }; diff --git a/plugins/platforms/x11/standalone/xfixes_cursor_event_filter.cpp b/plugins/platforms/x11/standalone/xfixes_cursor_event_filter.cpp new file mode 100644 index 0000000000..b23bafe589 --- /dev/null +++ b/plugins/platforms/x11/standalone/xfixes_cursor_event_filter.cpp @@ -0,0 +1,40 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2017 Martin Flöser + +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 . +*********************************************************************/ +#include "xfixes_cursor_event_filter.h" +#include "x11cursor.h" +#include "xcbutils.h" + +namespace KWin +{ + +XFixesCursorEventFilter::XFixesCursorEventFilter(X11Cursor *cursor) + : X11EventFilter(QVector{Xcb::Extensions::self()->fixesCursorNotifyEvent()}) + , m_cursor(cursor) +{ +} + +bool XFixesCursorEventFilter::event(xcb_generic_event_t *event) +{ + Q_UNUSED(event); + m_cursor->notifyCursorChanged(); + return false; +} + +} diff --git a/plugins/platforms/x11/standalone/xfixes_cursor_event_filter.h b/plugins/platforms/x11/standalone/xfixes_cursor_event_filter.h new file mode 100644 index 0000000000..cb15efef89 --- /dev/null +++ b/plugins/platforms/x11/standalone/xfixes_cursor_event_filter.h @@ -0,0 +1,41 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2017 Martin Flöser + +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 . +*********************************************************************/ +#ifndef KWIN_XFIXES_CURSOR_EVENT_FILTER_H +#define KWIN_XFIXES_CURSOR_EVENT_FILTER_H +#include "x11eventfilter.h" + +namespace KWin +{ +class X11Cursor; + +class XFixesCursorEventFilter : public X11EventFilter +{ +public: + explicit XFixesCursorEventFilter(X11Cursor *cursor); + + bool event(xcb_generic_event_t *event) override; + +private: + X11Cursor *m_cursor; +}; + +} + +#endif