| #pragma once |
|
|
| |
| |
| |
| |
| |
| |
|
|
| #include <QGuiApplication> |
| #include "config.hh" |
| #include "ex.hh" |
| #include "utils.hh" |
|
|
| #ifdef WITH_X11 |
| #include <fixx11h.h> |
| #include <set> |
| #include <X11/Xlib.h> |
| #include <X11/extensions/record.h> |
| #include <X11/Xlibint.h> |
| #undef Bool |
| #undef min |
| #undef max |
| #endif |
|
|
| #ifdef Q_OS_WIN |
| #include <QAbstractNativeEventFilter> |
| #endif |
|
|
| #ifdef Q_OS_MAC |
| #import <Carbon/Carbon.h> |
| #endif |
|
|
| |
|
|
| struct HotkeyStruct |
| { |
| HotkeyStruct() = default; |
| HotkeyStruct( quint32 key, quint32 key2, quint32 modifier, int handle, int id ): |
| key( key ), |
| key2( key2 ), |
| modifier( modifier ), |
| handle( handle ), |
| id( id ) {}; |
|
|
| quint32 key = 0; |
| quint32 key2 = 0; |
| quint32 modifier = 0; |
| int handle = 0; |
| int id = 0; |
| #ifdef Q_OS_MAC |
| EventHotKeyRef hkRef = nullptr; |
| EventHotKeyRef hkRef2 = nullptr; |
| #endif |
| }; |
|
|
| class HotkeyWrapper: public QThread |
| { |
| Q_OBJECT |
|
|
| friend class QHotkeyApplication; |
|
|
| public: |
|
|
| DEF_EX( exInit, "Hotkey wrapper failed to init", std::exception ) |
|
|
| explicit HotkeyWrapper( QObject * parent ); |
| ~HotkeyWrapper() override; |
|
|
| |
| |
| |
| |
| bool setGlobalKey( const QKeySequence &, int handle ); |
|
|
| |
| void unregister(); |
|
|
| signals: |
| void hotkeyActivated( int handle ); |
|
|
| |
| |
| |
| |
| |
|
|
| protected slots: |
| void waitKey2(); |
|
|
| private: |
| void init(); |
| quint32 nativeKey( int key ); |
|
|
| QList< HotkeyStruct > hotkeys; |
|
|
| bool state2; |
| HotkeyStruct state2waiter; |
|
|
| #ifdef Q_OS_WIN32 |
| virtual bool winEvent( MSG * message, qintptr * result ); |
| HWND hwnd; |
| private slots: |
| bool checkState( quint32 vk, quint32 mod ); |
| #endif |
|
|
| #ifdef Q_OS_MAC |
|
|
| private: |
| void sendCmdC(); |
|
|
| static EventHandlerUPP hotKeyFunction; |
| quint32 keyC; |
| EventHandlerRef handlerRef; |
|
|
| public: |
| void activated( int hkId ); |
|
|
| #endif |
|
|
| #ifdef WITH_X11 |
| static void recordEventCallback( XPointer, XRecordInterceptData * ); |
|
|
| |
| void handleRecordEvent( XRecordInterceptData * ); |
|
|
| void run() override; |
|
|
| |
| KeyCode lShiftCode, rShiftCode, lCtrlCode, rCtrlCode, lAltCode, rAltCode, cCode, insertCode, kpInsertCode, lMetaCode, |
| rMetaCode; |
|
|
| quint32 currentModifiers; |
|
|
| Display * dataDisplay; |
| XRecordRange * recordRange; |
| XRecordContext recordContext; |
| XRecordClientSpec recordClientSpec; |
|
|
| |
| |
| using GrabbedKeys = std::set< std::pair< quint32, quint32 > >; |
| GrabbedKeys grabbedKeys; |
|
|
| GrabbedKeys::iterator keyToUngrab; |
|
|
| |
| |
| bool isCopyToClipboardKey( quint32 keyCode, quint32 modifiers ) const; |
| |
| bool isKeyGrabbed( quint32 keyCode, quint32 modifiers ) const; |
| |
| |
| |
| GrabbedKeys::iterator grabKey( quint32 keyCode, quint32 modifiers ); |
| |
| |
| void ungrabKey( GrabbedKeys::iterator ); |
|
|
| signals: |
|
|
| |
| void keyRecorded( quint32 vk, quint32 mod ); |
|
|
| private slots: |
| bool checkState( quint32 vk, quint32 mod ); |
| #endif |
| }; |
|
|