-
Notifications
You must be signed in to change notification settings - Fork 0
/
nativefilters_mac.mm
53 lines (45 loc) · 1.25 KB
/
nativefilters_mac.mm
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
#include "nativefilters_mac.h"
#include <QDebug>
#import <AppKit/AppKit.h>
#import <IOKit/hidsystem/ev_keymap.h>
NativeFilter::NativeFilter(QObject* parent) : QObject(parent)
{}
bool NativeFilter::nativeEventFilter(const QByteArray& eventType, void* message, long*)
{
if (eventType != "mac_generic_NSEvent")
{
return false;
}
NSEvent *event = static_cast<NSEvent *>(message);
if ([event type] == NSEventTypeSystemDefined && [event subtype] == 8)
{
int keyCode = (([event data1] & 0xFFFF0000) >> 16);
int keyFlags = ([event data1] & 0x0000FFFF);
bool keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
bool keyRepeat = (keyFlags & 0x1);
emitMediaKeyEvent(keyCode, keyState, keyRepeat);
}
return false;
}
void NativeFilter::emitMediaKeyEvent(int keyCode, bool pressed, bool /* repeat */)
{
// only care about released keys
if (pressed)
{
return;
}
switch (keyCode)
{
case NX_KEYTYPE_PLAY:
emit(mediaKeyDownPlay());
break;
case NX_KEYTYPE_FAST:
case NX_KEYTYPE_NEXT:
emit(mediaKeyDownNext());
break;
case NX_KEYTYPE_REWIND:
case NX_KEYTYPE_PREVIOUS:
emit(mediaKeyDownPrevious());
break;
}
}