JRE-444 CPlatformWindow.nativeGetTopmostPlatformWindowUnderMouse is slow

Replaced number of CGWindowListCopyWindowInfo for each window layer with [NSWindow windowNumberAtPoint: belowWindowWithWindowNumber:]

(cherry picked from commit 2a143af4d62340acdfd9c94d876f684385febbc8)
(cherry picked from commit 6fc369e8bf)
This commit is contained in:
Alexey Ushakov
2017-08-09 10:08:26 +03:00
committed by jbrbot
parent 72249fea98
commit 0135880b07

View File

@@ -357,62 +357,9 @@ AWT_ASSERT_APPKIT_THREAD;
return [window isKindOfClass: [AWTWindow_Panel class]] || [window isKindOfClass: [AWTWindow_Normal class]];
}
// Retrieves the list of possible window layers (levels)
+ (NSArray*) getWindowLayers {
static NSArray *windowLayers;
static dispatch_once_t token;
// Initialize the list of possible window layers
dispatch_once(&token, ^{
// The layers are ordered from front to back, (i.e. the toppest one is the first)
windowLayers = [NSArray arrayWithObjects:
[NSNumber numberWithInt:CGWindowLevelForKey(kCGPopUpMenuWindowLevelKey)],
[NSNumber numberWithInt:CGWindowLevelForKey(kCGFloatingWindowLevelKey)],
[NSNumber numberWithInt:CGWindowLevelForKey(kCGNormalWindowLevelKey)],
nil
];
[windowLayers retain];
});
return windowLayers;
}
// returns id for the topmost window under mouse
+ (NSInteger) getTopmostWindowUnderMouseID {
NSInteger result = -1;
NSArray *windowLayers = [AWTWindow getWindowLayers];
// Looking for the window under mouse starting from the toppest layer
for (NSNumber *layer in windowLayers) {
result = [AWTWindow getTopmostWindowUnderMouseIDImpl:[layer integerValue]];
if (result != -1) {
break;
}
}
return result;
}
+ (NSInteger) getTopmostWindowUnderMouseIDImpl:(NSInteger)windowLayer {
NSInteger result = -1;
NSRect screenRect = [[NSScreen mainScreen] frame];
NSPoint nsMouseLocation = [NSEvent mouseLocation];
CGPoint cgMouseLocation = CGPointMake(nsMouseLocation.x, screenRect.size.height - nsMouseLocation.y);
NSMutableArray *windows = (NSMutableArray *)CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID);
for (NSDictionary *window in windows) {
NSInteger layer = [[window objectForKey:(id)kCGWindowLayer] integerValue];
if (layer == windowLayer) {
CGRect rect;
CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[window objectForKey:(id)kCGWindowBounds], &rect);
if (CGRectContainsPoint(rect, cgMouseLocation)) {
result = [[window objectForKey:(id)kCGWindowNumber] integerValue];
break;
}
}
}
[windows release];
return result;
return [NSWindow windowNumberAtPoint:[NSEvent mouseLocation] belowWindowWithWindowNumber:kCGNullWindowID];
}
// checks that this window is under the mouse cursor and this point is not overlapped by others windows