From 34c33ef008d2ff354a66313724db0468a31becdc Mon Sep 17 00:00:00 2001 From: michael starke Date: Mon, 4 Sep 2017 11:01:39 +0200 Subject: [PATCH] fixed various issues with Autotype determining the wrong window title --- MacPass/MPAutotypeDaemon.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/MacPass/MPAutotypeDaemon.m b/MacPass/MPAutotypeDaemon.m index 0a373ba8..b21fc366 100644 --- a/MacPass/MPAutotypeDaemon.m +++ b/MacPass/MPAutotypeDaemon.m @@ -263,6 +263,9 @@ static MPAutotypeDaemon *_sharedInstance; - (NSDictionary *)_infoDictionaryForApplication:(NSRunningApplication *)application { NSArray *currentWindows = CFBridgingRelease(CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements, kCGNullWindowID)); + NSArray *windowNumbers = [NSWindow windowNumbersWithOptions:NSWindowNumberListAllApplications]; + NSUInteger minZIndex = NSNotFound; + NSDictionary *infoDict = nil; for(NSDictionary *windowDict in currentWindows) { NSString *windowTitle = windowDict[(NSString *)kCGWindowName]; if(windowTitle.length <= 0) { @@ -270,13 +273,19 @@ static MPAutotypeDaemon *_sharedInstance; } NSNumber *processId = windowDict[(NSString *)kCGWindowOwnerPID]; if(processId && [processId isEqualToNumber:@(application.processIdentifier)]) { - return @{ - kMPWindowTitleKey: windowDict[(NSString *)kCGWindowName], - kMPProcessIdentifierKey : processId - }; + + NSNumber *number = (NSNumber *)windowDict[(NSString *)kCGWindowNumber]; + NSUInteger zIndex = [windowNumbers indexOfObject:number]; + if(zIndex < minZIndex) { + minZIndex = zIndex; + infoDict = @{ + kMPWindowTitleKey: windowTitle, + kMPProcessIdentifierKey : processId + }; + } } } - return nil; + return infoDict; } - (void)_presentSelectionWindow:(NSArray *)candidates {