Skip to content

Commit

Permalink
added 'left of notch' and 'right of notch' item positions
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixKratz committed Dec 5, 2021
1 parent 83690a3 commit 6fba6e3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
20 changes: 9 additions & 11 deletions src/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void bar_redraw(struct bar* bar) {

uint32_t bar_left_first_item_x = g_bar_manager.background.padding_left;
uint32_t bar_right_first_item_x = bar->frame.size.width - g_bar_manager.background.padding_right;
uint32_t bar_center_first_item_x = (bar->frame.size.width - bar_manager_length_for_bar_side(&g_bar_manager, bar, POSITION_CENTER)) / 2;
uint32_t bar_right_center_first_item_x = (bar->frame.size.width + bar->notch_width) / 2;
uint32_t bar_left_center_first_item_x =(bar->frame.size.width + bar->notch_width) / 2;
uint32_t bar_center_first_item_x = (bar->frame.size.width - 2*g_bar_manager.margin - bar_manager_length_for_bar_side(&g_bar_manager, bar, POSITION_CENTER)) / 2 - 1;
uint32_t bar_center_right_first_item_x = (bar->frame.size.width + bar->notch_width) / 2 - 1;
uint32_t bar_center_left_first_item_x = (bar->frame.size.width - bar->notch_width) / 2 - 1;

uint32_t* next_position = NULL;
uint32_t y = bar->frame.size.height / 2;
Expand All @@ -74,26 +74,24 @@ void bar_redraw(struct bar* bar) {

if (bar_item->position == POSITION_LEFT) next_position = &bar_left_first_item_x;
else if (bar_item->position == POSITION_CENTER) next_position = &bar_center_first_item_x;
else {
next_position = &bar_right_first_item_x;
rtl = true;
}
else if (bar_item->position == POSITION_RIGHT) next_position = &bar_right_first_item_x, rtl = true;
else if (bar_item->position == POSITION_CENTER_RIGHT) next_position = &bar_center_right_first_item_x;
else next_position = &bar_center_left_first_item_x, rtl = true;

if (bar_item->position == POSITION_RIGHT)
if (bar_item->position == POSITION_RIGHT || bar_item->position == POSITION_CENTER_LEFT)
*next_position -= bar_item_display_length + bar_item->background.padding_left + bar_item->background.padding_right;

bar_item->graph.rtl = rtl;
uint32_t bar_item_length = bar_item_calculate_bounds(bar_item, bar->frame.size.height - (g_bar_manager.background.border_width + 1), *next_position, y);

if (bar_item->position == POSITION_RIGHT) {
if (bar_item->position == POSITION_RIGHT || bar_item->position == POSITION_CENTER_LEFT) {
*next_position += bar_item->has_const_width ? bar_item_display_length
+ bar_item->background.padding_left
+ bar_item->background.padding_right
- bar_item->custom_width : 0;
} else
*next_position += bar_item_length + bar_item->background.padding_left + bar_item->background.padding_right;
}

bar_draw_bar_items(bar);
}

Expand Down Expand Up @@ -184,7 +182,6 @@ void bar_create_window(struct bar* bar) {
bar->context = SLWindowContextCreate(g_connection, bar->id, 0);
CGContextSetInterpolationQuality(bar->context, kCGInterpolationNone);
bar_set_font_smoothing(bar, g_bar_manager.font_smoothing);
bar->notch_width = 100;
}

void bar_close_window(struct bar* bar) {
Expand All @@ -198,6 +195,7 @@ struct bar *bar_create(uint32_t did) {
bar->hidden = false;
bar->did = did;
bar->sid = mission_control_index(display_space_id(did));
bar->notch_width = CGDisplayIsBuiltin(did) ? g_bar_manager.notch_width : 0;
bar_create_window(bar);
return bar;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bar_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh
}

if (bar_item->group && group_is_first_member(bar_item->group, bar_item))
group_calculate_bounds(bar_item->group, bar_item->position == POSITION_RIGHT ?
group_calculate_bounds(bar_item->group, (bar_item->position == POSITION_RIGHT || bar_item->position == POSITION_CENTER_LEFT) ?
(icon_position - group_get_length(bar_item->group) + bar_item_length) :
icon_position, y, bar_item->position == POSITION_RIGHT);
icon_position, y, bar_item->position == POSITION_RIGHT || bar_item->position == POSITION_CENTER_LEFT);

text_calculate_bounds(&bar_item->icon, icon_position, y + bar_item->y_offset);
text_calculate_bounds(&bar_item->label, label_position, y + bar_item->y_offset);
Expand Down
11 changes: 11 additions & 0 deletions src/bar_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void bar_manager_init(struct bar_manager* bar_manager) {
bar_manager->window_level = NSNormalWindowLevel;
bar_manager->topmost = false;
bar_manager->picky_redraw = false;
bar_manager->notch_width = 200;

background_init(&bar_manager->background);
bar_manager->background.bounds.size.height = 25;
Expand Down Expand Up @@ -161,6 +162,16 @@ bool bar_manager_set_shadow(struct bar_manager* bar_manager, bool shadow) {
return true;
}

bool bar_manager_set_notch_width(struct bar_manager* bar_manager, uint32_t width) {
if (bar_manager->notch_width == width) return false;
bar_manager->notch_width = width;
for (int i = 0; i < bar_manager->bar_count; ++i)
bar_destroy(bar_manager->bars[i]);

bar_manager_begin(bar_manager);
return true;
}

bool bar_manager_set_font_smoothing(struct bar_manager* bar_manager, bool smoothing) {
if (bar_manager->font_smoothing == smoothing) return false;
bar_manager->font_smoothing = smoothing;
Expand Down
2 changes: 2 additions & 0 deletions src/bar_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct bar_manager {
char display;
uint32_t margin;
uint32_t blur_radius;
uint32_t notch_width;
int y_offset;
bool shadow;

Expand Down Expand Up @@ -57,6 +58,7 @@ bool bar_manager_set_hidden(struct bar_manager* bar_manager, uint32_t sid, bool
bool bar_manager_set_topmost(struct bar_manager* bar_manager, bool topmost);
bool bar_manager_set_shadow(struct bar_manager* bar_manager, bool shadow);
bool bar_manager_set_font_smoothing(struct bar_manager* bar_manager, bool smoothing);
bool bar_manager_set_notch_width(struct bar_manager* bar_manager, uint32_t width);
void bar_manager_sort(struct bar_manager* bar_manager, struct bar_item** ordering, uint32_t count);

struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t adid);
Expand Down
4 changes: 4 additions & 0 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ static void message_parse_set_message_for_bar_item(FILE* rsp, struct bar_item* b
bar_item->update_frequency = token_to_uint32t(get_token(&message));
} else if (token_equals(property, PROPERTY_POSITION)) {
bar_item->position = get_token(&message).text[0];
needs_update = true;
} else if (token_equals(property, PROPERTY_ASSOCIATED_SPACE)) {
struct token token = get_token(&message);
uint32_t prev = bar_item->associated_space;
Expand Down Expand Up @@ -283,6 +284,9 @@ static bool handle_domain_bar(FILE *rsp, struct token domain, char *message) {
} else if (token_equals(command, PROPERTY_SHADOW)) {
struct token state = get_token(&message);
needs_refresh = bar_manager_set_shadow(&g_bar_manager, evaluate_boolean_state(state, g_bar_manager.shadow));
} else if (token_equals(command, PROPERTY_NOTCH_WIDTH)) {
struct token token = get_token(&message);
needs_refresh = bar_manager_set_notch_width(&g_bar_manager, token_to_uint32t(token));
} else if (token_equals(command, PROPERTY_HIDDEN)) {
struct token state = get_token(&message);
struct token select = get_token(&message);
Expand Down
3 changes: 3 additions & 0 deletions src/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
#define PROPERTY_FONT_SMOOTHING "font_smoothing"
#define PROPERTY_SHADOW "shadow"
#define PROPERTY_ALIGN "align"
#define PROPERTY_NOTCH_WIDTH "notch_width"

#define DOMAIN_SUBSCRIBE "--subscribe"
#define COMMAND_SUBSCRIBE_FRONT_APP_SWITCHED "front_app_switched"
Expand Down Expand Up @@ -108,6 +109,8 @@
#define POSITION_LEFT 'l'
#define POSITION_RIGHT 'r'
#define POSITION_CENTER 'c'
#define POSITION_CENTER_LEFT 'q'
#define POSITION_CENTER_RIGHT 'e'

#define DISPLAY_MAIN 'm'
#define DISPLAY_ALL 'a'
Expand Down

0 comments on commit 6fba6e3

Please sign in to comment.