Add IsOverlapped implementation for macOS.

This commit is contained in:
John Preston 2021-04-20 16:47:09 +04:00
parent 98e3ba2c58
commit eb768c8c4b

View file

@ -103,7 +103,55 @@ void IgnoreAllActivation(not_null<QWidget*> widget) {
std::optional<bool> IsOverlapped(
not_null<QWidget*> widget,
const QRect &rect) {
return std::nullopt;
NSWindow *window = [reinterpret_cast<NSView*>(widget->window()->winId()) window];
Assert(window != nullptr);
if (![window isOnActiveSpace]) {
return true;
}
const auto nativeRect = CGRectMake(
rect.x(),
rect.y(),
rect.width(),
rect.height());
CGWindowID windowId = (CGWindowID)[window windowNumber];
const CGWindowListOption options = kCGWindowListExcludeDesktopElements
| kCGWindowListOptionOnScreenAboveWindow;
CFArrayRef windows = CGWindowListCopyWindowInfo(options, windowId);
if (!windows) {
return std::nullopt;
}
const auto guard = gsl::finally([&] {
CFRelease(windows);
});
NSMutableArray *list = (__bridge NSMutableArray*)windows;
for (NSDictionary *window in list) {
NSNumber *alphaValue = [window objectForKey:@"kCGWindowAlpha"];
const auto alpha = alphaValue ? [alphaValue doubleValue] : 1.;
if (alpha == 0.) {
continue;
}
NSString *owner = [window objectForKey:@"kCGWindowOwnerName"];
NSNumber *layerValue = [window objectForKey:@"kCGWindowLayer"];
const auto layer = layerValue ? [layerValue intValue] : 0;
if (owner && [owner isEqualToString:@"Dock"] && layer == 20) {
// It is always full screen.
continue;
}
CFDictionaryRef bounds = (__bridge CFDictionaryRef)[window objectForKey:@"kCGWindowBounds"];
if (!bounds) {
continue;
}
CGRect rect;
if (!CGRectMakeWithDictionaryRepresentation(bounds, &rect)) {
continue;
} else if (CGRectIntersectsRect(rect, nativeRect)) {
return true;
}
}
return false;
}
TitleControls::Layout TitleControlsLayout() {