File indexing completed on 2024-02-18 16:20:24

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2014 Fredrik Höglund <fredrik@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <xcb/xcb.h>
0013 
0014 #include <QVector>
0015 
0016 #include <kwin_export.h>
0017 
0018 namespace KWin
0019 {
0020 
0021 class KWIN_EXPORT X11EventFilter
0022 {
0023 public:
0024     /**
0025      * Creates an event filter for the given event type.
0026      */
0027     X11EventFilter(int eventType, int opcode = 0, int genericEventType = 0);
0028     X11EventFilter(int eventType, int opcode, const QVector<int> &genericEventTypes);
0029     X11EventFilter(const QVector<int> &eventTypes);
0030 
0031     /**
0032      * Destroys the event filter.
0033      */
0034     virtual ~X11EventFilter();
0035 
0036     /**
0037      * Returns the type of events to filter.
0038      */
0039     QVector<int> eventTypes() const
0040     {
0041         return m_eventTypes;
0042     }
0043 
0044     /**
0045      * Returns the major opcode of the extension.
0046      *
0047      * Only used when the event type is XCB_GE_GENERIC.
0048      */
0049     int extension() const
0050     {
0051         return m_extension;
0052     }
0053 
0054     /**
0055      * Returns the types of generic events to filter.
0056      *
0057      * Only used when the event type is XCB_GE_GENERIC.
0058      */
0059     QVector<int> genericEventTypes() const
0060     {
0061         return m_genericEventTypes;
0062     }
0063 
0064     /**
0065      * This method is called for every event of the filtered type.
0066      *
0067      * Return true to accept the event and stop further processing, and false otherwise.
0068      */
0069     virtual bool event(xcb_generic_event_t *event) = 0;
0070 
0071     /**
0072      * Whether the event filter is for XCB_GE_GENERIC events.
0073      */
0074     bool isGenericEvent() const;
0075 
0076 private:
0077     QVector<int> m_eventTypes;
0078     int m_extension;
0079     QVector<int> m_genericEventTypes;
0080 };
0081 
0082 } // namespace KWin