[vlc-devel] [VLC 3.x v2 05/11] macosx: SPMediaKeyTap: Consolidate callbacks
Marvin Scholz
epirat07 at gmail.com
Fri Apr 23 01:19:32 UTC 2021
One callback only existed to call the other one with the
autorelease pool. Move that to the other one and get rid of
the unnecessary callback.
---
modules/gui/macosx/SPMediaKeyTap.m | 72 ++++++++++++++----------------
1 file changed, 33 insertions(+), 39 deletions(-)
diff --git a/modules/gui/macosx/SPMediaKeyTap.m b/modules/gui/macosx/SPMediaKeyTap.m
index 0b7dccdf70..4ffb01087a 100644
--- a/modules/gui/macosx/SPMediaKeyTap.m
+++ b/modules/gui/macosx/SPMediaKeyTap.m
@@ -213,48 +213,42 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEv
#pragma mark -
#pragma mark Event tap callbacks
-static CGEventRef tapEventCallback2(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
-{
- SPMediaKeyTap *self = (__bridge SPMediaKeyTap *)refcon;
-
- if(type == kCGEventTapDisabledByTimeout) {
- NSLog(@"VLC SPMediaKeyTap: Media key event tap was disabled by timeout");
- CGEventTapEnable(self->_eventPort, TRUE);
- return event;
- } else if(type == kCGEventTapDisabledByUserInput) {
- // Was disabled manually by -setShouldInterceptMediaKeyEvents:
- return event;
- }
- NSEvent *nsEvent = nil;
- @try {
- nsEvent = [NSEvent eventWithCGEvent:event];
- }
- @catch (NSException * e) {
- NSLog(@"VLC SPMediaKeyTap: Strange CGEventType: %d: %@", type, e);
- assert(0);
- return event;
- }
-
- if (type != NX_SYSDEFINED || [nsEvent subtype] != SPSystemDefinedEventMediaKeys)
- return event;
-
- int keyCode = (([nsEvent data1] & 0xFFFF0000) >> 16);
- if (keyCode != NX_KEYTYPE_PLAY && keyCode != NX_KEYTYPE_FAST && keyCode != NX_KEYTYPE_REWIND && keyCode != NX_KEYTYPE_PREVIOUS && keyCode != NX_KEYTYPE_NEXT)
- return event;
-
- if (!self->_shouldInterceptMediaKeyEvents)
- return event;
-
- [self performSelectorOnMainThread:@selector(handleAndReleaseMediaKeyEvent:) withObject:nsEvent waitUntilDone:NO];
-
- return NULL;
-}
-
static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{
@autoreleasepool {
- CGEventRef ret = tapEventCallback2(proxy, type, event, refcon);
- return ret;
+ SPMediaKeyTap *self = (__bridge SPMediaKeyTap *)refcon;
+
+ if(type == kCGEventTapDisabledByTimeout) {
+ NSLog(@"VLC SPMediaKeyTap: Media key event tap was disabled by timeout");
+ CGEventTapEnable(self->_eventPort, TRUE);
+ return event;
+ } else if(type == kCGEventTapDisabledByUserInput) {
+ // Was disabled manually by -setShouldInterceptMediaKeyEvents:
+ return event;
+ }
+ NSEvent *nsEvent = nil;
+ @try {
+ nsEvent = [NSEvent eventWithCGEvent:event];
+ }
+ @catch (NSException * e) {
+ NSLog(@"VLC SPMediaKeyTap: Strange CGEventType: %d: %@", type, e);
+ assert(0);
+ return event;
+ }
+
+ if (type != NX_SYSDEFINED || [nsEvent subtype] != SPSystemDefinedEventMediaKeys)
+ return event;
+
+ int keyCode = (([nsEvent data1] & 0xFFFF0000) >> 16);
+ if (keyCode != NX_KEYTYPE_PLAY && keyCode != NX_KEYTYPE_FAST && keyCode != NX_KEYTYPE_REWIND && keyCode != NX_KEYTYPE_PREVIOUS && keyCode != NX_KEYTYPE_NEXT)
+ return event;
+
+ if (!self->_shouldInterceptMediaKeyEvents)
+ return event;
+
+ [self performSelectorOnMainThread:@selector(handleAndReleaseMediaKeyEvent:) withObject:nsEvent waitUntilDone:NO];
+
+ return NULL;
}
}
--
2.30.1
More information about the vlc-devel
mailing list