diff --git a/src/bar.c b/src/bar.c index 7e68afc..1550825 100644 --- a/src/bar.c +++ b/src/bar.c @@ -258,7 +258,7 @@ void bar_refresh(struct bar *bar) bar_draw_line(bar, *label, label_position.x, label_position.y); bar_item->label_line.bounds.origin = label_position; bar_item->icon_line.bounds.origin = icon_position; - bar_item_set_bounding_rect_for_space(bar_item, sid); + bar_item_set_bounding_rect_for_space(bar_item, sid, bar->origin); } CGContextFlush(bar->context); @@ -266,7 +266,7 @@ void bar_refresh(struct bar *bar) SLSReenableUpdate(g_connection); } -static CGPoint bar_create_frame(struct bar *bar, CFTypeRef *frame_region) +void bar_create_frame(struct bar *bar, CFTypeRef *frame_region) { CGRect bounds = display_bounds(bar->did); CGPoint origin = bounds.origin; @@ -282,19 +282,18 @@ static CGPoint bar_create_frame(struct bar *bar, CFTypeRef *frame_region) } bar->frame = (CGRect) {{0, 0},{bounds.size.width, g_bar_manager.height}}; + bar->origin = origin; CGSNewRegionWithRect(&bar->frame, frame_region); - - return origin; } void bar_resize(struct bar *bar) { CFTypeRef frame_region; - CGPoint origin = bar_create_frame(bar, &frame_region); + bar_create_frame(bar, &frame_region); SLSDisableUpdate(g_connection); SLSOrderWindow(g_connection, bar->id, -1, 0); - SLSSetWindowShape(g_connection, bar->id, origin.x, origin.y, frame_region); + SLSSetWindowShape(g_connection, bar->id, bar->origin.x, bar->origin.y, frame_region); bar_refresh(bar); SLSOrderWindow(g_connection, bar->id, 1, 0); SLSReenableUpdate(g_connection); @@ -319,9 +318,9 @@ struct bar *bar_create(uint32_t did) *((int8_t *)(clear_tags) + 0x5) = 0x20; CFTypeRef frame_region; - CGPoint origin = bar_create_frame(bar, &frame_region); + bar_create_frame(bar, &frame_region); - SLSNewWindow(g_connection, 2, origin.x, origin.y, frame_region, &bar->id); + SLSNewWindow(g_connection, 2, bar->origin.x, bar->origin.y, frame_region, &bar->id); CFRelease(frame_region); SLSSetWindowResolution(g_connection, bar->id, 2.0f); diff --git a/src/bar.h b/src/bar.h index 3bbeb3d..8b4487c 100644 --- a/src/bar.h +++ b/src/bar.h @@ -46,6 +46,7 @@ struct bar CFRunLoopTimerRef refresh_timer; CFRunLoopTimerRef shell_refresh_timer; CGRect frame; + CGPoint origin; }; void bar_refresh(struct bar *bar); diff --git a/src/bar_item.c b/src/bar_item.c index f23d735..67032f7 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -137,10 +137,13 @@ CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) { bounding_rect.origin = bar_item->icon_line.bounds.origin; bounding_rect.size.width = CGRectGetMaxX(bar_item->label_line.bounds) - CGRectGetMinX(bar_item->icon_line.bounds); bounding_rect.size.height = CGRectGetMaxY(bar_item->label_line.bounds) > CGRectGetMaxY(bar_item->icon_line.bounds) ? CGRectGetMaxY(bar_item->label_line.bounds) : CGRectGetMaxY(bar_item->icon_line.bounds); + uint32_t max_y = CGRectGetMaxY(bar_item->label_line.bounds) > CGRectGetMaxY(bar_item->icon_line.bounds) ? CGRectGetMaxY(bar_item->label_line.bounds) : CGRectGetMaxY(bar_item->icon_line.bounds); + uint32_t min_y = CGRectGetMinY(bar_item->label_line.bounds) < CGRectGetMinY(bar_item->icon_line.bounds) ? CGRectGetMinY(bar_item->label_line.bounds) : CGRectGetMinY(bar_item->icon_line.bounds); + bounding_rect.size.height = max_y - min_y; return bounding_rect; } -void bar_item_set_bounding_rect_for_space(struct bar_item* bar_item, uint32_t sid) { +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); @@ -151,7 +154,7 @@ void bar_item_set_bounding_rect_for_space(struct bar_item* bar_item, uint32_t si memset(bar_item->bounding_rects[sid - 1], 0, sizeof(CGRect)); } CGRect rect = bar_item_construct_bounding_rect(bar_item); - - bar_item->bounding_rects[sid - 1]->origin = rect.origin; + 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; } diff --git a/src/bar_item.h b/src/bar_item.h index 5f12f3a..244a362 100644 --- a/src/bar_item.h +++ b/src/bar_item.h @@ -84,6 +84,6 @@ void bar_item_set_icon_font(struct bar_item* bar_item, char *font_string); 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); +void bar_item_set_bounding_rect_for_space(struct bar_item* bar_item, uint32_t sid, CGPoint bar_origin); #endif diff --git a/src/bar_manager.c b/src/bar_manager.c index 49c6b84..526caf3 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -159,6 +159,7 @@ struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, for (int i = 0; i < bar_manager->bar_item_count; i++) { struct bar_item* bar_item = bar_manager->bar_items[i]; if (bar_item->num_rects < sid || bar_item->bounding_rects[sid - 1] == NULL) continue; + printf("Bounding rect: %f %f \n", bar_item->bounding_rects[sid - 1]->origin.x, bar_item->bounding_rects[sid - 1]->origin.y); if (cgrect_contains_point(bar_item->bounding_rects[sid - 1], &point)) { return bar_item; }