From 7fc2869391edc2b303abea09628f40630be82d44 Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Fri, 19 Nov 2021 14:06:58 +0100 Subject: [PATCH] #793 properly size menubar/notch padding for Monterey --- src/display.c | 7 ++++--- src/display_manager.c | 10 +++++++--- src/workspace.h | 2 +- src/workspace.m | 9 +++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/display.c b/src/display.c index f19aa139..a0e2d91d 100644 --- a/src/display.c +++ b/src/display.c @@ -102,9 +102,10 @@ CGRect display_bounds_constrained(uint32_t did) } if (display_manager_menu_bar_hidden()) { - if (workspace_display_has_notch(did)) { - frame.origin.y += 38; - frame.size.height -= 38; + int notch_height = workspace_display_has_notch(did); + if (notch_height) { + frame.origin.y += notch_height; + frame.size.height -= notch_height; } } else { CGRect menu = display_manager_menu_bar_rect(did); diff --git a/src/display_manager.c b/src/display_manager.c index 28a295b8..8e0188d9 100644 --- a/src/display_manager.c +++ b/src/display_manager.c @@ -212,12 +212,16 @@ CGRect display_manager_menu_bar_rect(uint32_t did) // // NOTE(koekeishiya): SLSGetRevealedMenuBarBounds is broken on Apple Silicon and always returns an empty rectangle, - // The menubar height seems to be a constant of 24/44em always, regardless of the display being a 13" or 16", - // so we patch it here. The width of the menubar should be equal to the width of the display. + // The menubar height seems to be a constant of 24em always, regardless of the display being a 13" or 16", + // so we patch it here. For screens with a notch, the height of the notch determines the lowest y-coordinate + // that windows can be placed at. The width of the menubar should be equal to the width of the display. // - bounds.size.height = workspace_display_has_notch(did) ? 44 : 24; + int notch_height = workspace_display_has_notch(did); + if (!notch_height) notch_height = 24; + bounds.size.height = notch_height; + bounds.size.width = CGDisplayPixelsWide(did); #endif return bounds; diff --git a/src/workspace.h b/src/workspace.h index 15435a1d..1576b599 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -17,7 +17,7 @@ bool workspace_application_is_observable(struct process *process); bool workspace_application_is_finished_launching(struct process *process); void workspace_application_observe_finished_launching(void *context, struct process *process); void workspace_application_observe_activation_policy(void *context, struct process *process); -bool workspace_display_has_notch(uint32_t did); +int workspace_display_has_notch(uint32_t did); pid_t workspace_get_dock_pid(void); bool workspace_is_macos_monterey(void); bool workspace_is_macos_bigsur(void); diff --git a/src/workspace.m b/src/workspace.m index a38af7c7..ec8bc11c 100644 --- a/src/workspace.m +++ b/src/workspace.m @@ -99,19 +99,20 @@ bool workspace_application_is_finished_launching(struct process *process) } } -bool workspace_display_has_notch(uint32_t did) +int workspace_display_has_notch(uint32_t did) { - if (!CGDisplayIsBuiltin(did)) return false; + if (!CGDisplayIsBuiltin(did)) return 0; if (__builtin_available(macos 12.0, *)) { for (NSScreen *screen in [NSScreen screens]) { if ([[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue] == did) { - return screen.safeAreaInsets.top != 0; + printf("safeAreaInsets.top = %f\n", screen.safeAreaInsets.top); + return screen.safeAreaInsets.top; } } } - return false; + return 0; } pid_t workspace_get_dock_pid(void)