mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-27 05:40:17 +00:00
added 'left of notch' and 'right of notch' item positions
This commit is contained in:
parent
83690a3015
commit
6fba6e343d
6 changed files with 31 additions and 13 deletions
20
src/bar.c
20
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue