vlc | branch: master | Marvin Scholz <[email protected]> | Thu Aug  2 02:01:32 
2018 +0200| [1827563799bb18a8ebb724721b56ed399ad7c95f] | committer: Marvin 
Scholz

macosx: SPMediaKeyTap: Remove need for SPInvocationGrabbing

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1827563799bb18a8ebb724721b56ed399ad7c95f
---

 .../package/macosx/VLC.xcodeproj/project.pbxproj   |   6 -
 modules/gui/macosx/Makefile.am                     |   1 -
 modules/gui/macosx/SPInvocationGrabbing.h          |  36 ------
 modules/gui/macosx/SPInvocationGrabbing.m          | 142 ---------------------
 modules/gui/macosx/SPMediaKeyTap.m                 |  20 +--
 5 files changed, 12 insertions(+), 193 deletions(-)

diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj 
b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index eb30f9c9dd..4c01e1c294 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -59,7 +59,6 @@
                1C3114031E508C8800D4DD76 /* AppleRemote.m in Sources */ = {isa 
= PBXBuildFile; fileRef = CC6D8D9D0A878DED006F2BBE /* AppleRemote.m */; };
                1C3114051E508C8800D4DD76 /* SideBarItem.m in Sources */ = {isa 
= PBXBuildFile; fileRef = CCCDDEF013E870BB00A35661 /* SideBarItem.m */; };
                1C3114071E508C8800D4DD76 /* PXSourceList.m in Sources */ = {isa 
= PBXBuildFile; fileRef = CC0CD0E013DE0EAE00B0D90D /* PXSourceList.m */; };
-               1C31140B1E508C8800D4DD76 /* SPInvocationGrabbing.m in Sources 
*/ = {isa = PBXBuildFile; fileRef = CCF0777A13659A8000AF19FD /* 
SPInvocationGrabbing.m */; };
                1C31140D1E508C8800D4DD76 /* SPMediaKeyTap.m in Sources */ = 
{isa = PBXBuildFile; fileRef = CCF0777C13659A8000AF19FD /* SPMediaKeyTap.m */; 
};
                1C5716AC1F5B142200678627 /* coreaudio_common.c in Sources */ = 
{isa = PBXBuildFile; fileRef = 1C5716AB1F5B142200678627 /* coreaudio_common.c 
*/; };
                1CAC3EE820CD1B3B00613DB2 /* VLCVideoOutputProvider.m in Sources 
*/ = {isa = PBXBuildFile; fileRef = 1CAC3EE620CD1B3B00613DB2 /* 
VLCVideoOutputProvider.m */; };
@@ -509,8 +508,6 @@
                CCDBA3B313D32E200006127B /* macosx.m */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = macosx.m; path 
= ../../../modules/video_output/macosx.m; sourceTree = "<group>"; };
                CCDDF1AC172FF4C4007729A1 /* netconf.c */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.c; name = netconf.c; path = 
../../../src/darwin/netconf.c; sourceTree = "<group>"; };
                CCDDF1AD172FF4C4007729A1 /* dirs.c */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.c; name = dirs.c; path = 
../../../src/darwin/dirs.c; sourceTree = "<group>"; };
-               CCF0777913659A8000AF19FD /* SPInvocationGrabbing.h */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.h; path = 
SPInvocationGrabbing.h; sourceTree = "<group>"; };
-               CCF0777A13659A8000AF19FD /* SPInvocationGrabbing.m */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = 
SPInvocationGrabbing.m; sourceTree = "<group>"; };
                CCF0777B13659A8000AF19FD /* SPMediaKeyTap.h */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SPMediaKeyTap.h; 
sourceTree = "<group>"; };
                CCF0777C13659A8000AF19FD /* SPMediaKeyTap.m */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = 
SPMediaKeyTap.m; sourceTree = "<group>"; };
                DC1A176914E2778A001477C6 /* qtsound.m */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name 
= qtsound.m; path = ../../../modules/access/qtsound.m; sourceTree = "<group>"; 
};
@@ -1375,8 +1372,6 @@
                CC78DA4A13DE0E0100E9603C /* SPMediaKeyTap */ = {
                        isa = PBXGroup;
                        children = (
-                               CCF0777913659A8000AF19FD /* 
SPInvocationGrabbing.h */,
-                               CCF0777A13659A8000AF19FD /* 
SPInvocationGrabbing.m */,
                                CCF0777B13659A8000AF19FD /* SPMediaKeyTap.h */,
                                CCF0777C13659A8000AF19FD /* SPMediaKeyTap.m */,
                        );
@@ -1557,7 +1552,6 @@
                                6B4D50961E7A7D16004479B5 /* 
NSSound+VLCAdditions.m in Sources */,
                                6BF093F91EE0182B0049D8B0 /* VLCTimeField.m in 
Sources */,
                                1C3114071E508C8800D4DD76 /* PXSourceList.m in 
Sources */,
-                               1C31140B1E508C8800D4DD76 /* 
SPInvocationGrabbing.m in Sources */,
                                1C31140D1E508C8800D4DD76 /* SPMediaKeyTap.m in 
Sources */,
                                1C3113EF1E508C7600D4DD76 /* 
VLCRendererDiscovery.m in Sources */,
                                1C3113F11E508C7600D4DD76 /* VLCRendererItem.m 
in Sources */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index 5f9e53b03a..9c18c36013 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -56,7 +56,6 @@ libmacosx_plugin_la_SOURCES = \
        gui/macosx/VLCSimplePrefsController.h 
gui/macosx/VLCSimplePrefsController.m \
        gui/macosx/VLCSimplePrefsWindow.h gui/macosx/VLCSimplePrefsWindow.m \
        gui/macosx/VLCHotkeyChangeWindow.h gui/macosx/VLCHotkeyChangeWindow.m \
-       gui/macosx/SPInvocationGrabbing.h gui/macosx/SPInvocationGrabbing.m \
        gui/macosx/SPMediaKeyTap.h gui/macosx/SPMediaKeyTap.m \
        gui/macosx/Spotify.h \
        gui/macosx/VLCStringUtility.h gui/macosx/VLCStringUtility.m \
diff --git a/modules/gui/macosx/SPInvocationGrabbing.h 
b/modules/gui/macosx/SPInvocationGrabbing.h
deleted file mode 100644
index 78cbaade21..0000000000
--- a/modules/gui/macosx/SPInvocationGrabbing.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- Copyright (c) 2011, Joachim Bengtsson
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:
-
- * Neither the name of the organization nor the names of its contributors may 
be used to endorse or promote products derived from this software without 
specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import <Foundation/Foundation.h>
-
-@interface SPInvocationGrabber : NSObject {
-    int frameCount;
-    char **frameStrings;
-}
--(id)initWithObject:(id)obj;
--(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
-@property (readonly, retain, nonatomic) id object;
-@property (readonly, retain, nonatomic) NSInvocation *invocation;
-@property BOOL backgroundAfterForward;
-@property BOOL onMainAfterForward;
-@property BOOL waitUntilDone;
--(void)invoke; // will release object and invocation
--(void)printBacktrace;
--(void)saveBacktrace;
-@end
-
-@interface NSObject (SPInvocationGrabbing)
--(id)grab;
--(id)invokeAfter:(NSTimeInterval)delta;
--(id)nextRunloop;
--(id)inBackground;
--(id)onMainAsync:(BOOL)async;
-@end
diff --git a/modules/gui/macosx/SPInvocationGrabbing.m 
b/modules/gui/macosx/SPInvocationGrabbing.m
deleted file mode 100644
index c6f2ed0a8c..0000000000
--- a/modules/gui/macosx/SPInvocationGrabbing.m
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- Copyright (c) 2011, Joachim Bengtsson
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:
-
- * Neither the name of the organization nor the names of its contributors may 
be used to endorse or promote products derived from this software without 
specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "SPInvocationGrabbing.h"
-#import <execinfo.h>
-
-#pragma mark Invocation grabbing
-@interface SPInvocationGrabber ()
-@property (readwrite, retain, nonatomic) id object;
-@property (readwrite, retain, nonatomic) NSInvocation *invocation;
-
-@end
-
-@implementation SPInvocationGrabber
-- (id)initWithObject:(id)obj;
-{
-    return [self initWithObject:obj stacktraceSaving:YES];
-}
-
--(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
-{
-    self.object = obj;
-    if(saveStack)
-        [self saveBacktrace];
-
-    return self;
-}
-
--(void)dealloc;
-{
-    free(frameStrings);
-    self.object = nil;
-    self.invocation = nil;
-}
-
-- (void)runInBackground;
-{
-    @autoreleasepool {
-        @try {
-            [self invoke];
-        }
-        @finally {
-            ;
-        }
-    }
-}
-
-
-- (void)forwardInvocation:(NSInvocation *)anInvocation {
-    [anInvocation retainArguments];
-    anInvocation.target = _object;
-    self.invocation = anInvocation;
-
-    if(_backgroundAfterForward)
-        [NSThread detachNewThreadSelector:@selector(runInBackground) 
toTarget:self withObject:nil];
-    else if(_onMainAfterForward)
-        [self performSelectorOnMainThread:@selector(invoke) withObject:nil 
waitUntilDone:_waitUntilDone];
-}
-
-- (NSMethodSignature *)methodSignatureForSelector:(SEL)inSelector {
-    NSMethodSignature *signature = [super 
methodSignatureForSelector:inSelector];
-    if (signature == NULL)
-        signature = [_object methodSignatureForSelector:inSelector];
-
-    return signature;
-}
-
-- (void)invoke;
-{
-    @try {
-        [_invocation invoke];
-    }
-
-    @catch (NSException * e) {
-        NSLog(@"SPInvocationGrabber's target raised %@:\n\t%@\nInvocation was 
originally scheduled at:", e.name, e);
-        [self printBacktrace];
-        printf("\n");
-        [e raise];
-    }
-
-    self.invocation = nil;
-    self.object = nil;
-}
-
--(void)saveBacktrace;
-{
-    void *backtraceFrames[128];
-    frameCount = backtrace(&backtraceFrames[0], 128);
-    frameStrings = backtrace_symbols(&backtraceFrames[0], frameCount);
-}
-
--(void)printBacktrace;
-{
-    for(int x = 3; x < frameCount; x++) {
-        if(frameStrings[x] == NULL) { break; }
-        printf("%s\n", frameStrings[x]);
-    }
-}
-@end
-
-@implementation NSObject (SPInvocationGrabbing)
--(id)grab;
-{
-    return [[SPInvocationGrabber alloc] initWithObject:self];
-}
-
--(id)invokeAfter:(NSTimeInterval)delta;
-{
-    id grabber = [self grab];
-    [NSTimer scheduledTimerWithTimeInterval:delta target:grabber 
selector:@selector(invoke) userInfo:nil repeats:NO];
-    return grabber;
-}
-
-- (id)nextRunloop;
-{
-    return [self invokeAfter:0];
-}
-
--(id)inBackground;
-{
-    SPInvocationGrabber *grabber = [self grab];
-    grabber.backgroundAfterForward = YES;
-    return grabber;
-}
-
--(id)onMainAsync:(BOOL)async;
-{
-    SPInvocationGrabber *grabber = [self grab];
-    grabber.onMainAfterForward = YES;
-    grabber.waitUntilDone = !async;
-    return grabber;
-}
-
-@end
diff --git a/modules/gui/macosx/SPMediaKeyTap.m 
b/modules/gui/macosx/SPMediaKeyTap.m
index fa95fb9e66..3083660bde 100644
--- a/modules/gui/macosx/SPMediaKeyTap.m
+++ b/modules/gui/macosx/SPMediaKeyTap.m
@@ -23,7 +23,6 @@
 
 // Copyright (c) 2010 Spotify AB
 #import "SPMediaKeyTap.h"
-#import "SPInvocationGrabbing.h"
 
 // Define to enable app list debug output
 // #define DEBUG_SPMEDIAKEY_APPLIST 1
@@ -34,6 +33,7 @@ NSString *kIgnoreMediaKeysDefaultsKey = @"SPIgnoreMediaKeys";
     CFMachPortRef _eventPort;
     CFRunLoopSourceRef _eventPortSource;
     CFRunLoopRef _tapThreadRL;
+    NSThread *_tapThread;
     BOOL _shouldInterceptMediaKeyEvents;
     id _delegate;
     // The app that is frontmost in this list owns media keys
@@ -122,7 +122,10 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, 
CGEventType type, CGEv
         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];
+    _tapThread = [[NSThread alloc] initWithTarget:self
+                                         selector:@selector(eventTapThread)
+                                           object:nil];
+    [_tapThread start];
 
     return YES;
 }
@@ -218,9 +221,9 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, 
CGEventType type, CGEv
     return shouldIntercept;
 }
 
-- (void)pauseTapOnTapThread:(BOOL)yeahno
+- (void)pauseTapOnTapThread:(NSNumber *)yeahno
 {
-    CGEventTapEnable(self->_eventPort, yeahno);
+    CGEventTapEnable(self->_eventPort, [yeahno boolValue]);
 }
 
 - (void)setShouldInterceptMediaKeyEvents:(BOOL)newSetting
@@ -231,10 +234,11 @@ static CGEventRef tapEventCallback(CGEventTapProxy proxy, 
CGEventType type, CGEv
         _shouldInterceptMediaKeyEvents = newSetting;
     }
     if(_tapThreadRL && oldSetting != newSetting) {
-        id grab = [self grab];
-        [grab pauseTapOnTapThread:newSetting];
-        NSTimer *timer = [NSTimer timerWithTimeInterval:0 invocation:[grab 
invocation] repeats:NO];
-        CFRunLoopAddTimer(_tapThreadRL, 
(CFRunLoopTimerRef)CFBridgingRetain(timer), kCFRunLoopCommonModes);
+        [self performSelector:@selector(pauseTapOnTapThread:)
+                     onThread:_tapThread
+                   withObject:@(newSetting)
+                waitUntilDone:NO];
+
     }
 }
 

_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits

Reply via email to