mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-27 13:50:33 +00:00
sid -> adid bounding rect logic
This commit is contained in:
parent
ddd4a013df
commit
0f309c1608
6 changed files with 33 additions and 30 deletions
22
src/bar.c
22
src/bar.c
|
@ -146,11 +146,11 @@ void bar_draw_graph(struct bar* bar, struct bar_item* bar_item, uint32_t x, bool
|
|||
bar_draw_graph_line(bar, &bar_item->graph_data, x, g_bar_manager.border_width + 1, right_to_left);
|
||||
}
|
||||
|
||||
void bar_draw_item_background(struct bar* bar, struct bar_item* bar_item, uint32_t sid) {
|
||||
void bar_draw_item_background(struct bar* bar, struct bar_item* bar_item, uint32_t adid) {
|
||||
if (!bar_item->draws_background) return;
|
||||
bool custom_height = bar_item->background_height != 0;
|
||||
CGRect draw_region = {{bar_item->bounding_rects[sid - 1]->origin.x - bar->origin.x, custom_height ? ((bar->frame.size.height - bar_item->background_height)) / 2 : (g_bar_manager.border_width + 1)},
|
||||
{bar_item->bounding_rects[sid - 1]->size.width, custom_height ? bar_item->background_height : (bar->frame.size.height - 2*(g_bar_manager.border_width + 1))}};
|
||||
CGRect draw_region = {{bar_item->bounding_rects[adid - 1]->origin.x - bar->origin.x, custom_height ? ((bar->frame.size.height - bar_item->background_height)) / 2 : (g_bar_manager.border_width + 1)},
|
||||
{bar_item->bounding_rects[adid - 1]->size.width, custom_height ? bar_item->background_height : (bar->frame.size.height - 2*(g_bar_manager.border_width + 1))}};
|
||||
draw_region = CGRectInset(draw_region, bar_item->background_border_width / 2, bar_item->background_border_width / 2);
|
||||
draw_rect(bar->context, draw_region, &bar_item->background_color, bar_item->background_corner_radius, bar_item->background_border_width, &bar_item->background_border_color, false);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ void bar_draw_alias(struct bar* bar, struct bar_item* bar_item, uint32_t x) {
|
|||
|
||||
void bar_redraw(struct bar* bar) {
|
||||
if (bar->hidden) return;
|
||||
uint32_t did = bar->adid;
|
||||
uint32_t adid = bar->adid;
|
||||
uint32_t sid = bar->sid;
|
||||
if (sid == 0) return;
|
||||
|
||||
|
@ -179,7 +179,7 @@ void bar_redraw(struct bar* bar) {
|
|||
struct bar_item* bar_item = g_bar_manager.bar_items[i];
|
||||
|
||||
if (!bar_item->drawing) continue;
|
||||
if (bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << did))) continue;
|
||||
if (bar_item->associated_display > 0 && !(bar_item->associated_display & (1 << adid))) continue;
|
||||
if (bar_item->associated_space > 0 && !(bar_item->associated_space & (1 << sid)) && (bar_item->type != BAR_COMPONENT_SPACE)) continue;
|
||||
|
||||
struct bar_line* label = &bar_item->label_line;
|
||||
|
@ -238,10 +238,10 @@ void bar_redraw(struct bar* bar) {
|
|||
}
|
||||
bar_item->label_line.bounds.origin = label_position;
|
||||
bar_item->icon_line.bounds.origin = icon_position;
|
||||
bar_item_append_associated_bar(bar_item, (1 << (bar->adid - 1)));
|
||||
bar_item_set_bounding_rect_for_space(bar_item, sid, bar->origin);
|
||||
bar_item_append_associated_bar(bar_item, (1 << (adid - 1)));
|
||||
bar_item_set_bounding_rect_for_display(bar_item, adid, bar->origin);
|
||||
|
||||
bar_draw_item_background(bar, bar_item, sid);
|
||||
bar_draw_item_background(bar, bar_item, adid);
|
||||
bar_draw_line(bar, icon, icon_position.x, icon_position.y + bar_item->y_offset);
|
||||
bar_draw_line(bar, label, label_position.x, label_position.y + bar_item->y_offset);
|
||||
bar_draw_alias(bar, bar_item, icon_position.x);
|
||||
|
@ -263,9 +263,9 @@ void bar_create_frame(struct bar *bar, CFTypeRef *frame_region) {
|
|||
|
||||
if (0 == strcmp(g_bar_manager.position, BAR_POSITION_BOTTOM)) {
|
||||
origin.y = CGRectGetMaxY(bounds) - g_bar_manager.height - 2*g_bar_manager.y_offset;
|
||||
} else if (display_menu_bar_visible()) {
|
||||
//CGRect menu = display_menu_bar_rect(bar->did);
|
||||
//origin.y += menu.size.height;
|
||||
} else if (display_menu_bar_visible() && !g_bar_manager.topmost) {
|
||||
CGRect menu = display_menu_bar_rect(bar->did);
|
||||
origin.y += menu.size.height;
|
||||
}
|
||||
|
||||
bar->frame = (CGRect) {{0, 0},{bounds.size.width, g_bar_manager.height}};
|
||||
|
|
|
@ -345,20 +345,20 @@ CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) {
|
|||
return bounding_rect;
|
||||
}
|
||||
|
||||
void bar_item_set_bounding_rect_for_space(struct bar_item* bar_item, uint32_t sid, CGPoint bar_origin) {
|
||||
if (bar_item->num_rects < sid) {
|
||||
bar_item->bounding_rects = (CGRect**) realloc(bar_item->bounding_rects, sizeof(CGRect*) * sid);
|
||||
memset(bar_item->bounding_rects, 0, sizeof(CGRect*) * sid);
|
||||
bar_item->num_rects = sid;
|
||||
void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid, CGPoint bar_origin) {
|
||||
if (bar_item->num_rects < adid) {
|
||||
bar_item->bounding_rects = (CGRect**) realloc(bar_item->bounding_rects, sizeof(CGRect*) * adid);
|
||||
memset(bar_item->bounding_rects, 0, sizeof(CGRect*) * adid);
|
||||
bar_item->num_rects = adid;
|
||||
}
|
||||
if (!bar_item->bounding_rects[sid - 1]) {
|
||||
bar_item->bounding_rects[sid - 1] = malloc(sizeof(CGRect));
|
||||
memset(bar_item->bounding_rects[sid - 1], 0, sizeof(CGRect));
|
||||
if (!bar_item->bounding_rects[adid - 1]) {
|
||||
bar_item->bounding_rects[adid - 1] = malloc(sizeof(CGRect));
|
||||
memset(bar_item->bounding_rects[adid - 1], 0, sizeof(CGRect));
|
||||
}
|
||||
CGRect rect = bar_item_construct_bounding_rect(bar_item);
|
||||
bar_item->bounding_rects[sid - 1]->origin.x = rect.origin.x + bar_origin.x;
|
||||
bar_item->bounding_rects[sid - 1]->origin.y = rect.origin.y + bar_origin.y;
|
||||
bar_item->bounding_rects[sid - 1]->size = rect.size;
|
||||
bar_item->bounding_rects[adid - 1]->origin.x = rect.origin.x + bar_origin.x;
|
||||
bar_item->bounding_rects[adid - 1]->origin.y = rect.origin.y + bar_origin.y;
|
||||
bar_item->bounding_rects[adid - 1]->size = rect.size;
|
||||
}
|
||||
|
||||
void bar_item_destroy(struct bar_item* bar_item) {
|
||||
|
@ -417,7 +417,7 @@ void bar_item_serialize(struct bar_item* bar_item, FILE* rsp) {
|
|||
"\t\t\"drawing\": %d,\n"
|
||||
"\t\t\"updates\": %d,\n"
|
||||
"\t\t\"lazy\": %d,\n"
|
||||
"\t\t\"chache_scripts\": %d,\n"
|
||||
"\t\t\"cache_scripts\": %d,\n"
|
||||
"\t\t\"associated_bar_mask\": %u,\n"
|
||||
"\t\t\"associated_display_mask\": %u,\n"
|
||||
"\t\t\"associated_space_mask\": %u,\n"
|
||||
|
|
|
@ -131,6 +131,6 @@ void bar_item_clear_needs_update(struct bar_item* bar_item);
|
|||
void bar_item_on_click(struct bar_item* bar_item);
|
||||
|
||||
CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item);
|
||||
void bar_item_set_bounding_rect_for_space(struct bar_item* bar_item, uint32_t sid, CGPoint bar_origin);
|
||||
void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid, CGPoint bar_origin);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -287,11 +287,11 @@ void bar_manager_check_bar_items_for_update_pattern(struct bar_manager* bar_mana
|
|||
}
|
||||
}
|
||||
|
||||
struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t sid) {
|
||||
struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t adid) {
|
||||
for (int i = 0; i < bar_manager->bar_item_count; i++) {
|
||||
struct bar_item* bar_item = bar_manager->bar_items[i];
|
||||
if (!bar_item->drawing || bar_item->num_rects < sid || bar_item->bounding_rects[sid - 1] == NULL) continue;
|
||||
if (cgrect_contains_point(bar_item->bounding_rects[sid - 1], &point)) {
|
||||
if (!bar_item->drawing || bar_item->num_rects < adid || bar_item->bounding_rects[adid - 1] == NULL) continue;
|
||||
if (cgrect_contains_point(bar_item->bounding_rects[adid - 1], &point)) {
|
||||
return bar_item;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,9 @@ void bar_manager_set_topmost(struct bar_manager *bar_manager, bool topmost);
|
|||
void bar_manager_set_border_width(struct bar_manager* bar_manager, uint32_t width);
|
||||
void bar_manager_set_border_color(struct bar_manager* bar_manager, uint32_t color);
|
||||
void bar_manager_set_font_smoothing(struct bar_manager* bar_manager, bool smoothing);
|
||||
|
||||
struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t adid);
|
||||
|
||||
void bar_manager_freeze(struct bar_manager *bar_manager);
|
||||
void bar_manager_unfreeze(struct bar_manager *bar_manager);
|
||||
|
||||
|
|
|
@ -105,9 +105,9 @@ static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) {
|
|||
debug("%s\n", __FUNCTION__);
|
||||
CGPoint point = CGEventGetLocation(context);
|
||||
|
||||
uint32_t sid = mission_control_index(display_space_id(display_active_display_id()));
|
||||
debug("EVENT_HANDLER_MOUSE_UP: S#%d (x: %.0f, y: %.0f) -> ", sid, point.x, point.y);
|
||||
struct bar_item* bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, sid);
|
||||
uint32_t adid = display_arrangement(display_active_display_id());
|
||||
debug("EVENT_HANDLER_MOUSE_UP: D#%d (x: %.0f, y: %.0f) -> ", adid, point.x, point.y);
|
||||
struct bar_item* bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, adid);
|
||||
debug("item: %s\n", bar_item ? bar_item->name : "NULL");
|
||||
bar_item_on_click(bar_item);
|
||||
CFRelease(context);
|
||||
|
|
Loading…
Reference in a new issue