[vlc-commits] macosx: SPMediaKeyTap: Improve error handling
Marvin Scholz
git at videolan.org
Wed Aug 1 20:40:25 CEST 2018
vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Wed Aug 1 20:31:47 2018 +0200| [5ed5ef0c99d83570e05b2467e342363251c4da06] | committer: Marvin Scholz
macosx: SPMediaKeyTap: Improve error handling
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5ed5ef0c99d83570e05b2467e342363251c4da06
---
modules/gui/macosx/SPMediaKeyTap.h | 2 +-
modules/gui/macosx/SPMediaKeyTap.m | 12 ++++++++++--
modules/gui/macosx/VLCCoreInteraction.m | 12 ++++++++----
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/modules/gui/macosx/SPMediaKeyTap.h b/modules/gui/macosx/SPMediaKeyTap.h
index 82519ffd4c..78b4ce9b3c 100644
--- a/modules/gui/macosx/SPMediaKeyTap.h
+++ b/modules/gui/macosx/SPMediaKeyTap.h
@@ -33,7 +33,7 @@
-(id)initWithDelegate:(id)delegate;
+(BOOL)usesGlobalMediaKeyTap;
--(void)startWatchingMediaKeys;
+-(BOOL)startWatchingMediaKeys;
-(void)stopWatchingMediaKeys;
-(void)handleAndReleaseMediaKeyEvent:(NSEvent *)event;
@end
diff --git a/modules/gui/macosx/SPMediaKeyTap.m b/modules/gui/macosx/SPMediaKeyTap.m
index c7c97e25de..57f5fb00aa 100644
--- a/modules/gui/macosx/SPMediaKeyTap.m
+++ b/modules/gui/macosx/SPMediaKeyTap.m
@@ -69,7 +69,7 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
_app_switching_ref = NULL;
}
--(void)startWatchingMediaKeys;{
+-(BOOL)startWatchingMediaKeys;{
// Prevent having multiple mediaKeys threads
[self stopWatchingMediaKeys];
@@ -82,13 +82,21 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
CGEventMaskBit(NX_SYSDEFINED),
tapEventCallback,
(__bridge void * __nullable)(self));
- assert(_eventPort != NULL);
+
+ // Can be NULL if the app has no accessibility access permission
+ if (_eventPort == NULL)
+ return NO;
_eventPortSource = CFMachPortCreateRunLoopSource(kCFAllocatorSystemDefault, _eventPort, 0);
assert(_eventPortSource != NULL);
+ if (_eventPortSource == NULL)
+ return NO;
+
// Let's do this in a separate thread so that a slow app doesn't lag the event tap
[NSThread detachNewThreadSelector:@selector(eventTapThread) toTarget:self withObject:nil];
+
+ return YES;
}
-(void)stopWatchingMediaKeys;
{
diff --git a/modules/gui/macosx/VLCCoreInteraction.m b/modules/gui/macosx/VLCCoreInteraction.m
index f127844b57..cd1fe33c8b 100644
--- a/modules/gui/macosx/VLCCoreInteraction.m
+++ b/modules/gui/macosx/VLCCoreInteraction.m
@@ -903,14 +903,18 @@ static int BossCallback(vlc_object_t *p_this, const char *psz_var,
if (b_mediaKeySupport && ([[[main playlist] model] hasChildren] ||
[[main inputManager] hasInput])) {
if (!b_mediaKeyTrapEnabled) {
- b_mediaKeyTrapEnabled = YES;
- msg_Dbg(p_intf, "Enable media key support");
- [_mediaKeyController startWatchingMediaKeys];
+ msg_Dbg(p_intf, "Enabling media key support");
+ if ([_mediaKeyController startWatchingMediaKeys]) {
+ b_mediaKeyTrapEnabled = YES;
+ } else {
+ msg_Warn(p_intf, "Failed to enable media key support, likely "
+ "app needs to be whitelisted in Security Settings.");
+ }
}
} else {
if (b_mediaKeyTrapEnabled) {
b_mediaKeyTrapEnabled = NO;
- msg_Dbg(p_intf, "Disable media key support");
+ msg_Dbg(p_intf, "Disabling media key support");
[_mediaKeyController stopWatchingMediaKeys];
}
}
More information about the vlc-commits
mailing list