Skip to content

Commit

Permalink
#220 automatically offset the position of the statusbar if the macOS …
Browse files Browse the repository at this point in the history
…menubar remain visible
  • Loading branch information
koekeishiya committed Nov 29, 2019
1 parent 033b7c1 commit 9e10cbd
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 48 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Adding/removing nodes to/from the tree should properly reset the zoom-state [#227](https://github.com/koekeishiya/yabai/issues/227)
- Ability to enable/disable debug output at runtime [#312](https://github.com/koekeishiya/yabai/issues/312)
- Fix improper calculation of overlapping parts of status_bar when truncating title, and resolve an invalid free if the title could not be truncated [#313](https://github.com/koekeishiya/yabai/issues/313)
- Automatically offset the position of the status_bar if the macOS Menubar is not set to autohide [#220](https://github.com/koekeishiya/yabai/issues/220)
- Remove the line drawn at the bottom of the status_bar in a *poorly dimmed* version of the background color.

## [2.1.2] - 2019-11-10
### Changed
Expand Down
65 changes: 35 additions & 30 deletions src/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ void bar_refresh(struct bar *bar)
CGContextClearRect(bar->context, bar->frame);
CGContextSetRGBFillColor(bar->context, bar->background_color.r, bar->background_color.g, bar->background_color.b, bar->background_color.a);
CGContextFillRect(bar->context, bar->frame);
CGContextSetRGBStrokeColor(bar->context, bar->background_color_dim.r, bar->background_color_dim.g, bar->background_color_dim.b, bar->background_color_dim.a);
CGContextSetLineWidth(bar->context, 2.0f);
CGContextMoveToPoint(bar->context, 0, 1);
CGContextAddLineToPoint(bar->context, bar->frame.size.width, 1);
CGContextStrokePath(bar->context);

//
Expand Down Expand Up @@ -302,25 +298,6 @@ void bar_refresh(struct bar *bar)
SLSReenableUpdate(g_connection);
}

void bar_resize(struct bar *bar)
{
if (!bar->enabled) return;

bar->did = display_manager_main_display_id();
CGRect bounds = display_bounds(bar->did);

CFTypeRef frame_region;
bar->frame = (CGRect) {{0,0},{bounds.size.width, 26}};
CGSNewRegionWithRect(&bar->frame, &frame_region);
SLSDisableUpdate(g_connection);
SLSOrderWindow(g_connection, bar->id, -1, 0);
SLSSetWindowShape(g_connection, bar->id, 0.0f, 0.0f, frame_region);
bar_refresh(bar);
SLSOrderWindow(g_connection, bar->id, 1, 0);
SLSReenableUpdate(g_connection);
CFRelease(frame_region);
}

void bar_set_foreground_color(struct bar *bar, uint32_t color)
{
bar->foreground_color = rgba_color_from_hex(color);
Expand All @@ -334,7 +311,6 @@ void bar_set_foreground_color(struct bar *bar, uint32_t color)
void bar_set_background_color(struct bar *bar, uint32_t color)
{
bar->background_color = rgba_color_from_hex(color);
bar->background_color_dim = rgba_color_dim(bar->background_color);
bar_refresh(bar);
}

Expand Down Expand Up @@ -487,6 +463,39 @@ void bar_set_space_icon(struct bar *bar, char *icon)
bar_refresh(bar);
}

static float bar_create_frame(struct bar *bar, CFTypeRef *frame_region)
{
bar->did = display_manager_main_display_id();
CGRect bounds = display_bounds(bar->did);

float y_offset = 0.0f;
if (!display_manager_menu_bar_hidden()) {
CGRect menu = display_manager_menu_bar_rect(bar->did);
y_offset = menu.size.height;
}

bar->frame = (CGRect) {{0, 0},{bounds.size.width, 26}};
CGSNewRegionWithRect(&bar->frame, frame_region);

return y_offset;
}

void bar_resize(struct bar *bar)
{
if (!bar->enabled) return;

CFTypeRef frame_region;
float y_offset = bar_create_frame(bar, &frame_region);

SLSDisableUpdate(g_connection);
SLSOrderWindow(g_connection, bar->id, -1, 0);
SLSSetWindowShape(g_connection, bar->id, 0.0f, y_offset, frame_region);
bar_refresh(bar);
SLSOrderWindow(g_connection, bar->id, 1, 0);
SLSReenableUpdate(g_connection);
CFRelease(frame_region);
}

void bar_create(struct bar *bar)
{
if (bar->enabled) return;
Expand All @@ -510,14 +519,10 @@ void bar_create(struct bar *bar)
uint32_t clear_tags[2] = { 0, 0 };
*((int8_t *)(clear_tags) + 0x5) = 0x20;

bar->did = display_manager_main_display_id();
CGRect bounds = display_bounds(bar->did);

CFTypeRef frame_region;
bar->frame = (CGRect) {{0,0},{bounds.size.width, 26}};
float y_offset = bar_create_frame(bar, &frame_region);

CGSNewRegionWithRect(&bar->frame, &frame_region);
SLSNewWindow(g_connection, 2, 0.0f, 0.0f, frame_region, &bar->id);
SLSNewWindow(g_connection, 2, 0.0f, y_offset, frame_region, &bar->id);
CFRelease(frame_region);

SLSSetWindowResolution(g_connection, bar->id, 2.0f);
Expand Down
4 changes: 2 additions & 2 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ CGRect display_bounds(uint32_t did)
CGRect display_bounds_constrained(uint32_t did)
{
CGRect frame = display_bounds(did);
CGRect menu = display_manager_menu_bar_rect();
CGRect menu = display_manager_menu_bar_rect(did);
CGRect dock = display_manager_dock_rect();

if (g_bar.enabled && did == display_manager_main_display_id()) {
if (g_bar.enabled && g_bar.did == did) {
frame.origin.y += g_bar.frame.size.height;
frame.size.height -= g_bar.frame.size.height;
}
Expand Down
3 changes: 1 addition & 2 deletions src/display_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,9 @@ bool display_manager_menu_bar_hidden(void)
return status;
}

CGRect display_manager_menu_bar_rect(void)
CGRect display_manager_menu_bar_rect(uint32_t did)
{
CGRect bounds = {};
uint32_t did = display_manager_active_display_id();
SLSGetRevealedMenuBarBounds(&bounds, g_connection, display_space_id(did));
return bounds;
}
Expand Down
2 changes: 1 addition & 1 deletion src/display_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ uint32_t display_manager_next_display_id(uint32_t did);
uint32_t display_manager_first_display_id(void);
uint32_t display_manager_last_display_id(void);
bool display_manager_menu_bar_hidden(void);
CGRect display_manager_menu_bar_rect(void);
CGRect display_manager_menu_bar_rect(uint32_t did);
bool display_manager_dock_hidden(void);
int display_manager_dock_orientation(void);
CGRect display_manager_dock_rect(void);
Expand Down
1 change: 1 addition & 0 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_MENU_BAR_HIDDEN_CHANGED)
{
debug("%s:\n", __FUNCTION__);
space_manager_mark_spaces_invalid(&g_space_manager);
bar_resize(&g_bar);
return EVENT_SUCCESS;
}

Expand Down
13 changes: 0 additions & 13 deletions src/misc/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ rgba_color_from_hex(uint32_t color)
return result;
}

static struct rgba_color
rgba_color_dim(struct rgba_color color)
{
struct rgba_color result;
result.is_valid = true;
result.p = color.p;
result.r = 0.25f*color.r;
result.g = 0.25f*color.g;
result.b = 0.25f*color.b;
result.a = 0.25f*color.a;
return result;
}

static inline bool is_root(void)
{
return getuid() == 0 || geteuid() == 0;
Expand Down

0 comments on commit 9e10cbd

Please sign in to comment.