core logic surgery -- hopefully fixes some bugs

This commit is contained in:
Felix Kratz 2021-11-23 23:36:36 +01:00
parent bbd967a868
commit dc0d6bf3ff
7 changed files with 54 additions and 93 deletions

115
src/bar.c
View file

@ -17,23 +17,6 @@ void bar_draw_graph(struct bar* bar, struct bar_item* bar_item, uint32_t x, bool
if (!bar_item->has_graph) return;
}
void bar_draw_group(struct bar* bar, struct bar_item* item, uint32_t adid) {
if (item->group && group_is_first_member(item->group, item)) {
struct bar_item* bar_item = item->group->members[0];
if (!bar_item->background.enabled) return;
bool custom_height = bar_item->background.bounds.size.height != 0;
uint32_t group_length = group_get_length(bar_item->group);
CGRect draw_region = {{item->bounding_rects[adid - 1]->origin.x - bar->origin.x - (item->position == POSITION_RIGHT ? group_length - bar_item_get_length(item) : 0), custom_height ? ((bar->frame.size.height - bar_item->background.bounds.size.height)) / 2 : (g_bar_manager.background.border_width + 1)},
{group_length, custom_height ? bar_item->background.bounds.size.height : (bar->frame.size.height - (g_bar_manager.background.border_width + 1))}};
bar_item->background.bounds.size.height = draw_region.size.height;
bar_item->background.bounds.size.width = group_get_length(bar_item->group);
bar_item->background.bounds.origin = draw_region.origin;
background_draw(&bar_item->background, bar->context);
}
}
bool bar_draws_item(struct bar* bar, struct bar_item* bar_item) {
if (!bar_item->drawing) return false;
if (bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << bar->adid))) return false;
@ -83,9 +66,11 @@ void bar_redraw(struct bar* bar) {
if (bar->hidden) return;
if (bar->sid == 0) return;
int bar_left_final_item_x = g_bar_manager.background.padding_left;
int bar_right_first_item_x = bar->frame.size.width - g_bar_manager.background.padding_right;
int bar_center_first_item_x = (bar->frame.size.width - bar_manager_get_center_length_for_bar(&g_bar_manager, bar)) / 2;
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 + 1;
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* next_position = NULL;
uint32_t y = bar->frame.size.height / 2;
@ -94,77 +79,38 @@ void bar_redraw(struct bar* bar) {
if (!bar_draws_item(bar, bar_item)) continue;
uint32_t bar_item_length = bar_item_get_length(bar_item, false);
uint32_t bar_item_display_length = bar_item_get_length(bar_item, true);
uint32_t icon_position = 0;
uint32_t label_position = 0;
uint32_t sandwich_position = 0;
bool rtl = false;
if (bar_item->position == POSITION_LEFT) {
icon_position = bar_left_final_item_x + bar_item->background.padding_left;
label_position = icon_position + text_get_length(&bar_item->icon);
if (!bar_item->has_const_width)
bar_left_final_item_x = label_position + text_get_length(&bar_item->label) + bar_item->background.padding_right;
else
bar_left_final_item_x += bar_item->custom_width;
sandwich_position = label_position;
if (bar_item->has_graph) {
if (!bar_item->has_const_width)
bar_left_final_item_x += graph_get_length(&bar_item->graph);
label_position += graph_get_length(&bar_item->graph);
} else if (bar_item->has_alias) {
if (!bar_item->has_const_width)
bar_left_final_item_x += alias_get_length(&bar_item->alias);
label_position += alias_get_length(&bar_item->alias);
}
}
else if (bar_item->position == POSITION_RIGHT) {
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;
label_position = bar_right_first_item_x - text_get_length(&bar_item->label) - bar_item->background.padding_right;
icon_position = label_position - text_get_length(&bar_item->icon);
if (!bar_item->has_const_width)
bar_right_first_item_x = icon_position - bar_item->background.padding_left;
else
bar_right_first_item_x -= bar_item->custom_width;
if (bar_item->has_graph) {
if (!bar_item->has_const_width)
bar_right_first_item_x -= graph_get_length(&bar_item->graph);
sandwich_position = icon_position + text_get_length(&bar_item->icon);
icon_position -= graph_get_length(&bar_item->graph);
} else if (bar_item->has_alias) {
if (!bar_item->has_const_width)
icon_position -= alias_get_length(&bar_item->alias);
bar_right_first_item_x -= alias_get_length(&bar_item->alias);
sandwich_position = icon_position + text_get_length(&bar_item->icon);
}
}
else if (bar_item->position == POSITION_CENTER) {
icon_position = bar_center_first_item_x + bar_item->background.padding_left;
label_position = icon_position + text_get_length(&bar_item->icon);
if (!bar_item->has_const_width)
bar_center_first_item_x = label_position + text_get_length(&bar_item->label) + bar_item->background.padding_right;
else
bar_center_first_item_x += bar_item->custom_width;
if (bar_item->position == POSITION_RIGHT)
*next_position -= bar_item_display_length + bar_item->background.padding_left + bar_item->background.padding_right;
sandwich_position = label_position;
if (bar_item->has_graph) {
if (!bar_item->has_const_width)
bar_center_first_item_x += graph_get_length(&bar_item->graph);
label_position += graph_get_length(&bar_item->graph);
} else if (bar_item->has_alias) {
if (!bar_item->has_const_width)
bar_center_first_item_x += alias_get_length(&bar_item->alias);
label_position += alias_get_length(&bar_item->alias);
}
icon_position = *next_position + bar_item->background.padding_left;
label_position = icon_position + text_get_length(&bar_item->icon);
sandwich_position = label_position;
if (bar_item->has_graph) {
label_position += graph_get_length(&bar_item->graph);
} else if (bar_item->has_alias) {
label_position += alias_get_length(&bar_item->alias);
}
if (bar_item->group && group_is_first_member(bar_item->group, bar_item))
group_calculate_bounds(bar_item->group, bar_item->position == POSITION_RIGHT ? (icon_position - group_get_length(bar_item->group) + bar_item_get_length(bar_item) + bar_item->icon.padding_left) : icon_position, y);
group_calculate_bounds(bar_item->group, bar_item->position == POSITION_RIGHT ?
(icon_position - group_get_length(bar_item->group) + bar_item->group->num_members - 1 + bar_item_length) :
icon_position, y);
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);
@ -181,8 +127,17 @@ void bar_redraw(struct bar* bar) {
bar_item->background.bounds.size.height = bar_item->background.overrides_height ? bar_item->background.bounds.size.height
: (bar->frame.size.height - (g_bar_manager.background.border_width + 1));
bar_item->background.bounds.size.width = bar_item_get_length(bar_item);
bar_item->background.bounds.size.width = bar_item_length;
background_calculate_bounds(&bar_item->background, icon_position, y + bar_item->y_offset);
if (bar_item->position == POSITION_RIGHT) {
*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);

View file

@ -263,13 +263,13 @@ void bar_item_set_yoffset(struct bar_item* bar_item, int offset) {
bar_item_needs_update(bar_item);
}
uint32_t bar_item_get_length(struct bar_item* bar_item) {
if (bar_item->has_const_width) return bar_item->custom_width + 1;
uint32_t bar_item_get_length(struct bar_item* bar_item, bool ignore_override) {
if (bar_item->has_const_width && !ignore_override) return bar_item->custom_width - bar_item->background.padding_left - bar_item->background.padding_right;
return text_get_length(&bar_item->icon)
+ text_get_length(&bar_item->label)
+ (bar_item->has_graph ? graph_get_length(&bar_item->graph) : 0)
+ (bar_item->has_alias ? alias_get_length(&bar_item->alias) : 0) + 1;
+ (bar_item->has_alias ? alias_get_length(&bar_item->alias) : 0);
}
uint32_t bar_item_get_height(struct bar_item* bar_item) {
@ -292,7 +292,7 @@ CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) {
CGRect bounding_rect;
bounding_rect.origin = bar_item->icon.bounds.origin;
bounding_rect.origin.y = bar_item->icon.bounds.origin.y < bar_item->label.bounds.origin.y ? bar_item->icon.bounds.origin.y : bar_item->label.bounds.origin.y + bar_item->y_offset;
bounding_rect.size.width = bar_item_get_length(bar_item);
bounding_rect.size.width = bar_item_get_length(bar_item, false);
bounding_rect.size.height = bar_item_get_height(bar_item);
return bounding_rect;
}

View file

@ -86,7 +86,7 @@ void bar_item_set_click_script(struct bar_item* bar_item, char* script);
void bar_item_set_drawing(struct bar_item* bar_item, bool state);
void bar_item_set_yoffset(struct bar_item* bar_item, int offset);
uint32_t bar_item_get_length(struct bar_item* bar_item);
uint32_t bar_item_get_length(struct bar_item* bar_item, bool ignore_override);
uint32_t bar_item_get_height(struct bar_item* bar_item);
void bar_item_needs_update(struct bar_item* bar_item);

View file

@ -201,15 +201,15 @@ void bar_manager_unfreeze(struct bar_manager *bar_manager) {
bar_manager->frozen = false;
}
uint32_t bar_manager_get_center_length_for_bar(struct bar_manager* bar_manager, struct bar* bar) {
uint32_t bar_manager_length_for_bar_side(struct bar_manager* bar_manager, struct bar* bar, char side) {
uint32_t total_length = 0;
for (int i = 0; i < bar_manager->bar_item_count; i++) {
struct bar_item* bar_item = bar_manager->bar_items[i];
bool is_associated_space_shown = (bar_item->associated_space & (1 << bar->sid)) || bar_item->associated_space == 0;
bool is_associated_display_shown = (bar_item->associated_display & (1 << bar->adid));
if (bar_item->position == POSITION_CENTER && bar_item->drawing && (is_associated_space_shown || is_associated_display_shown))
total_length += bar_item_get_length(bar_item);
if (bar_item->position == side && bar_item->drawing && (is_associated_space_shown || is_associated_display_shown))
total_length += bar_item_get_length(bar_item, false);
}
return total_length;
}

View file

@ -60,7 +60,7 @@ bool bar_manager_set_font_smoothing(struct bar_manager* bar_manager, bool smooth
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);
uint32_t bar_manager_get_center_length_for_bar(struct bar_manager* bar_manager, struct bar* bar);
uint32_t bar_manager_length_for_bar_side(struct bar_manager* bar_manager, struct bar* bar, char side);
void bar_manager_freeze(struct bar_manager* bar_manager);
void bar_manager_unfreeze(struct bar_manager* bar_manager);

View file

@ -44,7 +44,7 @@ void graph_calculate_bounds(struct graph* graph, uint32_t x, uint32_t y) {
}
void graph_draw(struct graph* graph, CGContextRef context) {
uint32_t x = graph->bounds.origin.x;
uint32_t x = graph->bounds.origin.x + (graph->rtl ? graph->width : 0);
uint32_t y = graph->bounds.origin.y;
uint32_t height = graph->bounds.size.height;

View file

@ -47,9 +47,15 @@ uint32_t group_get_length(struct group* group) {
uint32_t length = 0;
for (int i = 1; i < group->num_members; i++) {
if (group->members[i]->drawing) {
if (i > 1) length += group->members[i]->background.padding_left;
length += bar_item_get_length(group->members[i]);
if (i < group->num_members - 1) length += group->members[i]->background.padding_right;
if (group->members[i]->position == POSITION_RIGHT) {
if (i > 1) length += group->members[i]->background.padding_right;
if (i < group->num_members - 1) length += group->members[i]->background.padding_left;
}
else {
if (i > 1) length += group->members[i]->background.padding_left;
if (i < group->num_members - 1) length += group->members[i]->background.padding_right;
}
length += bar_item_get_length(group->members[i], false) + 1;
}
}
return length;