File indexing completed on 2024-11-24 04:55:40

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2001, 2002 Ellis Whitehead <ellis@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef _KGLOBALACCEL_X11_H
0009 #define _KGLOBALACCEL_X11_H
0010 
0011 #include "../../kglobalaccel_interface.h"
0012 
0013 #include <QAbstractNativeEventFilter>
0014 #include <QObject>
0015 
0016 struct xcb_key_press_event_t;
0017 typedef xcb_key_press_event_t xcb_key_release_event_t;
0018 typedef struct _XCBKeySymbols xcb_key_symbols_t;
0019 /**
0020  * @internal
0021  *
0022  * The KGlobalAccel private class handles grabbing of global keys,
0023  * and notification of when these keys are pressed.
0024  */
0025 class KGlobalAccelImpl : public KGlobalAccelInterface, public QAbstractNativeEventFilter
0026 {
0027     Q_OBJECT
0028     Q_PLUGIN_METADATA(IID "org.kde.kglobalaccel5.KGlobalAccelInterface" FILE "xcb.json")
0029     Q_INTERFACES(KGlobalAccelInterface)
0030 
0031 public:
0032     KGlobalAccelImpl(QObject *parent = nullptr);
0033     ~KGlobalAccelImpl() override;
0034 
0035 public:
0036     /**
0037      * This function registers or unregisters a certain key for global capture,
0038      * depending on \b grab.
0039      *
0040      * Before destruction, every grabbed key will be released, so this
0041      * object does not need to do any tracking.
0042      *
0043      * \param key the Qt keycode to grab or release.
0044      * \param grab true to grab they key, false to release the key.
0045      *
0046      * \return true if successful, otherwise false.
0047      */
0048     bool grabKey(int key, bool grab) override;
0049 
0050     /// Enable/disable all shortcuts. There will not be any grabbed shortcuts at this point.
0051     void setEnabled(bool) override;
0052 
0053     bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override;
0054 
0055 private:
0056     /**
0057      * Filters X11 events ev for key bindings in the accelerator dictionary.
0058      * If a match is found the activated activated is emitted and the function
0059      * returns true. Return false if the event is not processed.
0060      *
0061      * This is public for compatibility only. You do not need to call it.
0062      */
0063     void x11MappingNotify();
0064     bool x11KeyPress(xcb_key_press_event_t *event);
0065     bool x11KeyRelease(xcb_key_press_event_t *event);
0066 
0067     xcb_key_symbols_t *m_keySymbols;
0068     uint8_t m_xkb_first_event;
0069     void *m_display;
0070     unsigned int m_xrecordCookieSequence;
0071 };
0072 
0073 #endif // _KGLOBALACCEL_X11_H