forked from ckaiser/UGlobalHotkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuglobalhotkeys.h
72 lines (63 loc) · 1.75 KB
/
uglobalhotkeys.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <QWidget>
#include <QAbstractNativeEventFilter>
#include <QSet>
#if defined(Q_OS_LINUX)
#include "xcb/xcb.h"
#include "xcb/xcb_keysyms.h"
#elif defined(Q_OS_MAC)
#include <Carbon/Carbon.h>
#endif
#include "ukeysequence.h"
#include "uglobal.h"
#if defined(Q_OS_LINUX)
struct UHotkeyData {
xcb_keycode_t keyCode;
int mods;
bool operator ==(const UHotkeyData &data) const
{
return data.keyCode == this->keyCode && data.mods == this->mods;
}
};
#endif
class UGLOBALHOTKEY_EXPORT UGlobalHotkeys : public QWidget
#if defined(Q_OS_LINUX)
, public QAbstractNativeEventFilter
#endif
{
Q_OBJECT
public:
explicit UGlobalHotkeys(QWidget *parent = 0);
bool registerHotkey(const QString &keySeq, size_t id = 1);
bool registerHotkey(const UKeySequence &keySeq, size_t id = 1);
void unregisterHotkey(size_t id = 1);
void unregisterAllHotkeys();
~UGlobalHotkeys();
protected:
#if defined(Q_OS_WIN)
bool winEvent(MSG *message, long *result);
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
#elif defined(Q_OS_LINUX)
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
bool linuxEvent(xcb_generic_event_t *message);
void regLinuxHotkey(const UKeySequence &keySeq, size_t id);
void unregLinuxHotkey(size_t id);
#endif
public:
#if defined (Q_OS_MAC)
void onHotkeyPressed(size_t id);
#endif
signals:
void activated(size_t id);
private:
#if defined(Q_OS_WIN)
QSet<size_t> Registered;
#elif defined(Q_OS_LINUX)
QHash<size_t, UHotkeyData> Registered;
xcb_connection_t *X11Connection;
xcb_window_t X11Wid;
xcb_key_symbols_t *X11KeySymbs;
#elif defined(Q_OS_MAC)
QHash<size_t, EventHotKeyRef> HotkeyRefs;
#endif
};