Skip to content

Commit

Permalink
#793 properly size menubar/notch padding for Monterey
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Nov 19, 2021
1 parent 6bcf544 commit 7fc2869
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions src/display_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/workspace.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7fc2869

Please sign in to comment.