Skip to content

Commit

Permalink
Add IsOverlapped implementation for macOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Apr 20, 2021
1 parent 98e3ba2 commit eb768c8
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion ui/platform/mac/ui_utility_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit eb768c8

Please sign in to comment.