Add SPMediaKeyTap back (#621)
This commit is contained in:
@@ -4,11 +4,13 @@
|
||||
#include "globalshortcuts/globalshortcutbackend-macos.h"
|
||||
|
||||
class PlatformInterface;
|
||||
@class SPMediaKeyTap;
|
||||
|
||||
@interface AppDelegate : NSObject<NSApplicationDelegate, NSUserNotificationCenterDelegate> {
|
||||
PlatformInterface* application_handler_;
|
||||
NSMenu* dock_menu_;
|
||||
GlobalShortcutBackendMacOS* shortcut_handler_;
|
||||
SPMediaKeyTap* key_tap_;
|
||||
|
||||
}
|
||||
|
||||
@@ -27,4 +29,5 @@ class PlatformInterface;
|
||||
- (void) setDockMenu: (NSMenu*)menu;
|
||||
- (GlobalShortcutBackendMacOS*) shortcut_handler;
|
||||
- (void) setShortcutHandler: (GlobalShortcutBackendMacOS*)backend;
|
||||
- (void) mediaKeyTap: (SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
|
||||
@end
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
|
||||
#import <QuartzCore/CALayer.h>
|
||||
|
||||
#import "3rdparty/SPMediaKeyTap/SPMediaKeyTap.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "mac_delegate.h"
|
||||
@@ -146,6 +148,19 @@ QDebug operator<<(QDebug dbg, NSObject* object) {
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
|
||||
Q_UNUSED(aNotification);
|
||||
|
||||
key_tap_ = [ [SPMediaKeyTap alloc] initWithDelegate:self];
|
||||
if ([SPMediaKeyTap usesGlobalMediaKeyTap]) {
|
||||
if ([key_tap_ startWatchingMediaKeys]) {
|
||||
qLog(Debug) << "Media key monitoring started";
|
||||
} else {
|
||||
qLog(Warning) << "Failed to start media key monitoring";
|
||||
}
|
||||
}
|
||||
else {
|
||||
qLog(Warning) << "Media key monitoring disabled";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (BOOL)application:(NSApplication*)app openFile:(NSString*)filename {
|
||||
@@ -171,6 +186,26 @@ QDebug operator<<(QDebug dbg, NSObject* object) {
|
||||
|
||||
}
|
||||
|
||||
- (void) mediaKeyTap: (SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event {
|
||||
#pragma unused(keyTap)
|
||||
[self handleMediaEvent:event];
|
||||
}
|
||||
|
||||
- (BOOL) handleMediaEvent:(NSEvent*)event {
|
||||
// if it is not a media key event, then ignore
|
||||
if ([event type] == NSEventTypeSystemDefined && [event subtype] == 8) {
|
||||
int keyCode = (([event data1] & 0xFFFF0000) >> 16);
|
||||
int keyFlags = ([event data1] & 0x0000FFFF);
|
||||
int keyIsReleased = (((keyFlags & 0xFF00) >> 8)) == 0xB;
|
||||
if (keyIsReleased) {
|
||||
shortcut_handler_->MacMediaKeyPressed(keyCode);
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*) sender {
|
||||
Q_UNUSED(sender);
|
||||
return NSTerminateNow;
|
||||
@@ -226,15 +261,7 @@ QDebug operator<<(QDebug dbg, NSObject* object) {
|
||||
|
||||
- (void)sendEvent:(NSEvent*)event {
|
||||
|
||||
if ([event type] == NSEventTypeSystemDefined && [event subtype] == 8) {
|
||||
int keyCode = (([event data1] & 0xFFFF0000) >> 16);
|
||||
int keyFlags = ([event data1] & 0x0000FFFF);
|
||||
int keyIsReleased = (((keyFlags & 0xFF00) >> 8)) == 0xB;
|
||||
if (keyIsReleased) {
|
||||
shortcut_handler_->MacMediaKeyPressed(keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
[delegate_ handleMediaEvent:event];
|
||||
[super sendEvent:event];
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user