aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Gräßlin <[email protected]>2016-11-15 08:22:41 +0100
committerMartin Gräßlin <[email protected]>2016-11-16 07:48:19 +0100
commit9f976a4b8dd78b7b4312806b2f78c609879c3ea8 (patch)
treee1e75c6ad62a4beb728fa66019ccd1acdee1c882
parent730fd05f58f9bc71fa044aee5e22139b2e6bbded (diff)
Support multiple event types in X11EventFilter
Summary: So far the X11EventFilter only supported one event type. But most usecases for an X11EventFilter require to support multiple event types. E.g. a filter listens for both key press and key release. This change extends the internal X11EventFilter to support multiple types and Workspace::workspaceEvent makes use of that. Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D3361
-rw-r--r--autotests/test_xrandr_screens.cpp4
-rw-r--r--events.cpp6
-rw-r--r--x11eventfilter.cpp18
-rw-r--r--x11eventfilter.h10
4 files changed, 30 insertions, 8 deletions
diff --git a/autotests/test_xrandr_screens.cpp b/autotests/test_xrandr_screens.cpp
index 9ee401e..674198b 100644
--- a/autotests/test_xrandr_screens.cpp
+++ b/autotests/test_xrandr_screens.cpp
@@ -135,8 +135,8 @@ void TestXRandRScreens::testStartup()
{
KWin::MockWorkspace ws;
QScopedPointer<XRandRScreens> screens(new XRandRScreens(this));
- QVERIFY(screens->eventType() != 0);
- QCOMPARE(screens->eventType(), Xcb::Extensions::self()->randrNotifyEvent());
+ QVERIFY(!screens->eventTypes().isEmpty());
+ QCOMPARE(screens->eventTypes().first(), Xcb::Extensions::self()->randrNotifyEvent());
QCOMPARE(screens->extension(), 0);
QCOMPARE(screens->genericEventTypes(), QVector<int>{0});
screens->init();
diff --git a/events.cpp b/events.cpp
index d8da5a7..d48afa2 100644
--- a/events.cpp
+++ b/events.cpp
@@ -182,7 +182,7 @@ QVector<QByteArray> s_xcbEerrors({
void Workspace::registerEventFilter(X11EventFilter *filter)
{
- if (filter->eventType() == XCB_GE_GENERIC)
+ if (filter->isGenericEvent())
m_genericEventFilters.append(filter);
else
m_eventFilters.append(filter);
@@ -190,7 +190,7 @@ void Workspace::registerEventFilter(X11EventFilter *filter)
void Workspace::unregisterEventFilter(X11EventFilter *filter)
{
- if (filter->eventType() == XCB_GE_GENERIC)
+ if (filter->isGenericEvent())
m_genericEventFilters.removeOne(filter);
else
m_eventFilters.removeOne(filter);
@@ -243,7 +243,7 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e)
}
} else {
foreach (X11EventFilter *filter, m_eventFilters) {
- if (filter->eventType() == eventType && filter->event(e)) {
+ if (filter->eventTypes().contains(eventType) && filter->event(e)) {
return true;
}
}
diff --git a/x11eventfilter.cpp b/x11eventfilter.cpp
index 643ca0e..ea2daf9 100644
--- a/x11eventfilter.cpp
+++ b/x11eventfilter.cpp
@@ -24,13 +24,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
+X11EventFilter::X11EventFilter(const QVector<int> &eventTypes)
+ : m_eventTypes(eventTypes)
+ , m_extension(0)
+{
+ Workspace::self()->registerEventFilter(this);
+}
+
+
X11EventFilter::X11EventFilter(int eventType, int opcode, int genericEventType)
: X11EventFilter(eventType, opcode, QVector<int>{genericEventType})
{
}
X11EventFilter::X11EventFilter(int eventType, int opcode, const QVector< int > &genericEventTypes)
- : m_eventType(eventType), m_extension(opcode), m_genericEventTypes(genericEventTypes)
+ : m_eventTypes(QVector<int>{eventType}), m_extension(opcode), m_genericEventTypes(genericEventTypes)
{
Workspace::self()->registerEventFilter(this);
}
@@ -42,4 +50,12 @@ X11EventFilter::~X11EventFilter()
}
}
+bool X11EventFilter::isGenericEvent() const
+{
+ if (m_eventTypes.count() != 1) {
+ return false;
+ }
+ return m_eventTypes.first() == XCB_GE_GENERIC;
+}
+
}
diff --git a/x11eventfilter.h b/x11eventfilter.h
index f352fdc..ea25ef0 100644
--- a/x11eventfilter.h
+++ b/x11eventfilter.h
@@ -38,6 +38,7 @@ public:
*/
X11EventFilter(int eventType, int opcode = 0, int genericEventType = 0);
X11EventFilter(int eventType, int opcode, const QVector<int> &genericEventTypes);
+ X11EventFilter(const QVector<int> &eventTypes);
/**
* Destroys the event filter.
@@ -47,7 +48,7 @@ public:
/**
* Returns the type of events to filter.
*/
- int eventType() const { return m_eventType; }
+ QVector<int> eventTypes() const { return m_eventTypes; }
/**
* Returns the major opcode of the extension.
@@ -70,8 +71,13 @@ public:
*/
virtual bool event(xcb_generic_event_t *event) = 0;
+ /**
+ * Whether the event filter is for XCB_GE_GENERIC events.
+ **/
+ bool isGenericEvent() const;
+
private:
- int m_eventType;
+ QVector<int> m_eventTypes;
int m_extension;
QVector<int> m_genericEventTypes;
};