aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/platform/OSXMediaKeySimulator.mm
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-11-10 00:54:35 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-11-10 00:54:35 -0500
commit58fb7a0cee13d84170aac52f3f89d91888e1afe3 (patch)
tree1d6312ba15f9ece5a8031e5280dfb8b38be8dfa3 /src/lib/platform/OSXMediaKeySimulator.mm
parent28db84b46139c9bb2bbcac8c6cc56e71d1e35629 (diff)
parentbeb08eb751fa8e1f72042f263316ab5e5ddb596d (diff)
Update upstream source from tag 'upstream/2.4.0+dfsg'
Update to upstream version '2.4.0+dfsg' with Debian dir 4b6668cc08c7b0e56b1e1f7b4e89ecdb316182a0
Diffstat (limited to 'src/lib/platform/OSXMediaKeySimulator.mm')
-rw-r--r--src/lib/platform/OSXMediaKeySimulator.mm92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/lib/platform/OSXMediaKeySimulator.mm b/src/lib/platform/OSXMediaKeySimulator.mm
new file mode 100644
index 0000000..efc4251
--- /dev/null
+++ b/src/lib/platform/OSXMediaKeySimulator.mm
@@ -0,0 +1,92 @@
+/*
+ * barrier -- mouse and keyboard sharing utility
+ * Copyright (C) 2016 Symless.
+ *
+ * This package is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * found in the file COPYING that should have accompanied this file.
+ *
+ * This package is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#import "platform/OSXMediaKeySimulator.h"
+
+#import <Cocoa/Cocoa.h>
+
+int convertKeyIDToNXKeyType(KeyID id)
+{
+ // hidsystem/ev_keymap.h
+ // NX_KEYTYPE_SOUND_UP 0
+ // NX_KEYTYPE_SOUND_DOWN 1
+ // NX_KEYTYPE_BRIGHTNESS_UP 2
+ // NX_KEYTYPE_BRIGHTNESS_DOWN 3
+ // NX_KEYTYPE_MUTE 7
+ // NX_KEYTYPE_EJECT 14
+ // NX_KEYTYPE_PLAY 16
+ // NX_KEYTYPE_NEXT 17
+ // NX_KEYTYPE_PREVIOUS 18
+ // NX_KEYTYPE_FAST 19
+ // NX_KEYTYPE_REWIND 20
+
+ int type = -1;
+ switch (id) {
+ case kKeyAudioUp:
+ type = 0;
+ break;
+ case kKeyAudioDown:
+ type = 1;
+ break;
+ case kKeyBrightnessUp:
+ type = 2;
+ break;
+ case kKeyBrightnessDown:
+ type = 3;
+ break;
+ case kKeyAudioMute:
+ type = 7;
+ break;
+ case kKeyEject:
+ type = 14;
+ break;
+ case kKeyAudioPlay:
+ type = 16;
+ break;
+ case kKeyAudioNext:
+ type = 17;
+ break;
+ case kKeyAudioPrev:
+ type = 18;
+ break;
+ default:
+ break;
+ }
+
+ return type;
+}
+
+bool
+fakeNativeMediaKey(KeyID id)
+{
+
+ NSEvent* downRef = [NSEvent otherEventWithType:NSSystemDefined
+ location: NSMakePoint(0, 0) modifierFlags:0xa00
+ timestamp:0 windowNumber:0 context:0 subtype:8
+ data1:(convertKeyIDToNXKeyType(id) << 16) | ((0xa) << 8)
+ data2:-1];
+ CGEventRef downEvent = [downRef CGEvent];
+
+ NSEvent* upRef = [NSEvent otherEventWithType:NSSystemDefined
+ location: NSMakePoint(0, 0) modifierFlags:0xa00
+ timestamp:0 windowNumber:0 context:0 subtype:8
+ data1:(convertKeyIDToNXKeyType(id) << 16) | ((0xb) << 8)
+ data2:-1];
+ CGEventRef upEvent = [upRef CGEvent];
+
+ CGEventPost(kCGHIDEventTap, downEvent);
+ CGEventPost(kCGHIDEventTap, upEvent);
+
+ return true;
+}