@sync code executed into notification callback (to avoid threading issues)
This commit is contained in:
Patrick Wardle
2019-01-04 16:23:25 -10:00
parent 0d03e0b0e0
commit c0124824d8
5 changed files with 39 additions and 52 deletions
+2 -2
View File
@@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.1</string>
<string>1.0.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0.1</string>
<string>1.0.2</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
+2 -2
View File
@@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.1</string>
<string>1.0.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0.1</string>
<string>1.0.2</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
+2 -2
View File
@@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.1</string>
<string>1.0.2</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
@@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.0.1</string>
<string>1.0.2</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
+11 -4
View File
@@ -17,7 +17,10 @@
NSRect selectionRect = {0};
//selection path
NSBezierPath *selectionPath = nil;
NSBezierPath* selectionPath = nil;
//selection color
NSColor* selectionColor = nil;
//highlight selected rows
if(self.selectionHighlightStyle != NSTableViewSelectionHighlightStyleNone)
@@ -25,9 +28,13 @@
//make selection rect
selectionRect = NSInsetRect(self.bounds, 2.5, 2.5);
NSColor *selectionColor = [NSColor systemGrayColor];
//default color
selectionColor = [NSColor systemGrayColor];
if (@available(macOS 10.14, *)) {
//10.4, set to unemphasized
if (@available(macOS 10.14, *))
{
//set
selectionColor = [NSColor unemphasizedSelectedContentBackgroundColor];
}
@@ -38,7 +45,7 @@
[selectionColor setFill];
//create selection path
// ->with rounded corners
// with rounded corners
selectionPath = [NSBezierPath bezierPathWithRoundedRect:selectionRect xRadius:5 yRadius:5];
//fill
+22 -42
View File
@@ -16,30 +16,6 @@
@synthesize previousTaps;
//init method
// set some intial flags, init daemon comms, etc.
-(id)init
{
//super
self = [super init];
if(self != nil)
{
/*
//alloc set
currentTaps = [NSMutableSet set];
//init current taps
for(NSDictionary* tap in [self enumerate])
{
//add
[currentTaps addObject:tap[@"tapID"]];
}
*/
}
return self;
}
//enumerate event taps
// activated keyboard taps
-(NSMutableDictionary*)enumerate
@@ -189,28 +165,33 @@ bail:
//register 'kCGNotifyEventTapAdded' notification
notify_register_dispatch(kCGNotifyEventTapAdded, &notifyToken, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(int token) {
//grab current taps
// ...should now include any new ones
currentTaps = [self enumerate];
//identify any new taps
// invoke callback for those...
for(NSNumber* tapID in currentTaps.allKeys)
//sync to assure thread safety
@synchronized(self)
{
//not new?
if(nil != self.previousTaps[tapID])
//grab current taps
// ...should now include any new ones
currentTaps = [self enumerate];
//identify any new taps
// invoke callback for those...
for(NSNumber* tapID in currentTaps.allKeys)
{
//skip
continue;
//not new?
if(nil != self.previousTaps[tapID])
{
//skip
continue;
}
//new!
callback(currentTaps[tapID]);
}
//new!
callback(currentTaps[tapID]);
}
//update taps
self.previousTaps = currentTaps;
//update taps
self.previousTaps = currentTaps;
} //sync
});
//run loop
@@ -219,5 +200,4 @@ bail:
return;
}
@end