From: Joe Wreschnig Date: Sat, 17 Aug 2013 11:51:13 +0000 (+0200) Subject: Add a blacklist of executable names (for wine.bin). Prefer the front window title... X-Git-Tag: version-1.2~15 X-Git-Url: https://git.yukkurigames.com/?p=enjoyable.git;a=commitdiff_plain;h=7fa330d1595971c7ddf79aba72cc85ab1b6c95b2 Add a blacklist of executable names (for wine.bin). Prefer the front window title to the executable name. This allows per-Wine-application bindings. --- diff --git a/Categories/NSRunningApplication+NJPossibleNames.m b/Categories/NSRunningApplication+NJPossibleNames.m index 895134c..7a7bd63 100644 --- a/Categories/NSRunningApplication+NJPossibleNames.m +++ b/Categories/NSRunningApplication+NJPossibleNames.m @@ -10,6 +10,21 @@ @implementation NSRunningApplication (NJPossibleNames) +- (NSArray *)windowTitles { + NSMutableArray *titles = [[NSMutableArray alloc] initWithCapacity:4]; + NSArray *windows = CFBridgingRelease(CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID)); + for (NSDictionary *props in windows) { + NSNumber *pid = props[(id)kCGWindowOwnerPID]; + if (pid.longValue == self.processIdentifier && props[(id)kCGWindowName]) + [titles addObject:props[(id)kCGWindowName]]; + } + return titles; +} + +- (NSString *)frontWindowTitle { + return self.windowTitles[0]; +} + - (NSArray *)possibleMappingNames { NSMutableArray *names = [[NSMutableArray alloc] initWithCapacity:4]; if (self.bundleIdentifier) @@ -20,6 +35,8 @@ [names addObject:[self.bundleURL.lastPathComponent stringByDeletingPathExtension]]; if (self.executableURL) [names addObject:self.executableURL.lastPathComponent]; + if (self.frontWindowTitle) + [names addObject:self.frontWindowTitle]; return names; } @@ -32,13 +49,17 @@ @"com.macromedia.Flash Player Debugger.app", @"com.macromedia.Flash Player.app", ]; - BOOL probablyWrong = [genericBundles containsObject:self.bundleIdentifier]; + NSArray *genericExecutables = @[ @"wine.bin" ]; + BOOL probablyWrong = ([genericBundles containsObject:self.bundleIdentifier] + || [genericExecutables containsObject:self.localizedName]); if (!probablyWrong && self.localizedName) return self.localizedName; else if (!probablyWrong && self.bundleIdentifier) return self.bundleIdentifier; else if (self.bundleURL) return [self.bundleURL.lastPathComponent stringByDeletingPathExtension]; + else if (self.frontWindowTitle) + return self.frontWindowTitle; else if (self.executableURL) return self.executableURL.lastPathComponent; else if (self.localizedName) diff --git a/Classes/NJInputController.m b/Classes/NJInputController.m index face5e7..5ba9828 100644 --- a/Classes/NJInputController.m +++ b/Classes/NJInputController.m @@ -266,10 +266,10 @@ static CVReturn displayLink_update_cb(CVDisplayLinkRef displayLink, - (void)mappingsSet { [self postLoadProcess]; [NSNotificationCenter.defaultCenter - postNotificationName:NJEventMappingListChanged - object:self - userInfo:@{ NJMappingListKey: _mappings, - NJMappingKey: _currentMapping }]; + postNotificationName:NJEventMappingListChanged + object:self + userInfo:@{ NJMappingListKey: _mappings, + NJMappingKey: _currentMapping }]; } - (void)mappingsChanged { diff --git a/Info.plist b/Info.plist index 9917f03..1e6b7d9 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 598 + 605 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright