From 6fba6e343d79d2d83c4c05ea26b532bb4584232c Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sun, 5 Dec 2021 20:25:24 +0100 Subject: [PATCH] added 'left of notch' and 'right of notch' item positions --- src/bar.c | 20 +++++++++----------- src/bar_item.c | 4 ++-- src/bar_manager.c | 11 +++++++++++ src/bar_manager.h | 2 ++ src/message.c | 4 ++++ src/message.h | 3 +++ 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/bar.c b/src/bar.c index eb0165e5..867479f2 100644 --- a/src/bar.c +++ b/src/bar.c @@ -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; @@ -74,18 +74,17 @@ 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 @@ -93,7 +92,6 @@ void bar_redraw(struct bar* bar) { } else *next_position += bar_item_length + bar_item->background.padding_left + bar_item->background.padding_right; } - bar_draw_bar_items(bar); } @@ -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) { @@ -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; } diff --git a/src/bar_item.c b/src/bar_item.c index 9806ef13..5010b5a9 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -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); diff --git a/src/bar_manager.c b/src/bar_manager.c index 01e57119..959a77c1 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -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; @@ -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; diff --git a/src/bar_manager.h b/src/bar_manager.h index 4a94d676..eddad3a2 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -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; @@ -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); diff --git a/src/message.c b/src/message.c index 2678095b..52fe9d85 100644 --- a/src/message.c +++ b/src/message.c @@ -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; @@ -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); diff --git a/src/message.h b/src/message.h index 124e9a16..ca2e3df1 100644 --- a/src/message.h +++ b/src/message.h @@ -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" @@ -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'