diff --git a/cursor.h b/cursor.h --- a/cursor.h +++ b/cursor.h @@ -80,12 +80,6 @@ * @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/cursor.cpp b/cursor.cpp --- a/cursor.cpp +++ b/cursor.cpp @@ -227,16 +227,6 @@ { } -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/events.cpp b/events.cpp --- a/events.cpp +++ b/events.cpp @@ -391,8 +391,6 @@ 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 --- a/plugins/platforms/x11/standalone/CMakeLists.txt +++ b/plugins/platforms/x11/standalone/CMakeLists.txt @@ -9,6 +9,7 @@ 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.h b/plugins/platforms/x11/standalone/x11cursor.h --- a/plugins/platforms/x11/standalone/x11cursor.h +++ b/plugins/platforms/x11/standalone/x11cursor.h @@ -21,8 +21,11 @@ #define KWIN_X11CURSOR_H #include "cursor.h" +#include + namespace KWin { +class XFixesCursorEventFilter; class KWIN_EXPORT X11Cursor : public Cursor { @@ -35,6 +38,13 @@ 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 @@ QTimer *m_mousePollingTimer; bool m_hasXInput; bool m_needsPoll; + + std::unique_ptr m_xfixesFilter; + friend class Cursor; }; diff --git a/plugins/platforms/x11/standalone/x11cursor.cpp b/plugins/platforms/x11/standalone/x11cursor.cpp --- a/plugins/platforms/x11/standalone/x11cursor.cpp +++ b/plugins/platforms/x11/standalone/x11cursor.cpp @@ -22,6 +22,7 @@ #include "keyboard_input.h" #include "utils.h" #include "xcbutils.h" +#include "xfixes_cursor_event_filter.h" #include #include @@ -51,6 +52,16 @@ 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 @@ 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/xfixes_cursor_event_filter.h b/plugins/platforms/x11/standalone/xfixes_cursor_event_filter.h new file mode 100644 --- /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 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 --- /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; +} + +}