diff --git a/src/bar.c b/src/bar.c index 4e661dd..581af2a 100644 --- a/src/bar.c +++ b/src/bar.c @@ -200,7 +200,7 @@ 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 << (adid - 1))); - SLSAddTrackingRect(g_connection, bar->id, bar_item_construct_bounding_rect(bar_item)); + if (strlen(bar_item->click_script) > 0) SLSAddTrackingRect(g_connection, bar->id, CGRectInset(bar_item_construct_bounding_rect(bar_item), 1, 1)); bar_item_set_bounding_rect_for_display(bar_item, adid, bar->origin); bar_draw_group(bar, bar_item, adid); diff --git a/src/bar_item.c b/src/bar_item.c index f24009c..6d15e4c 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -101,16 +101,19 @@ bool bar_item_is_shown(struct bar_item* bar_item) { else return false; } -void bar_item_append_associated_bar(struct bar_item* bar_item, uint32_t bit) { - bar_item->associated_bar |= bit; +void bar_item_append_associated_bar(struct bar_item* bar_item, uint32_t adid) { + bar_item->associated_bar |= (1 << (adid - 1)); } -void bar_item_remove_associated_bar(struct bar_item* bar_item, uint32_t bit) { - bar_item->associated_bar &= ~bit; +void bar_item_remove_associated_bar(struct bar_item* bar_item, uint32_t adid) { + bar_item->associated_bar &= ~(1 << (adid - 1)); + bar_item_remove_bounding_rect_for_display(bar_item, adid); } void bar_item_reset_associated_bar(struct bar_item* bar_item) { bar_item->associated_bar = 0; + for (uint32_t adid = 1; adid <= bar_item->num_rects; adid++) + bar_item_remove_bounding_rect_for_display(bar_item, adid); } bool bar_item_update(struct bar_item* bar_item, bool forced) { @@ -233,6 +236,13 @@ uint32_t bar_item_get_height(struct bar_item* bar_item) { return label_height > icon_height ? label_height : icon_height; } +void bar_item_remove_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid) { + if (bar_item->num_rects >= adid && bar_item->bounding_rects[adid - 1]) { + free(bar_item->bounding_rects[adid - 1]); + bar_item->bounding_rects[adid - 1] = NULL; + } +} + CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) { CGRect bounding_rect; bounding_rect.origin = bar_item->icon.line.bounds.origin; diff --git a/src/bar_item.h b/src/bar_item.h index 27a1684..ccd29c1 100644 --- a/src/bar_item.h +++ b/src/bar_item.h @@ -88,8 +88,8 @@ bool bar_item_is_shown(struct bar_item* bar_item); void bar_item_append_associated_space(struct bar_item* bar_item, uint32_t bit); void bar_item_append_associated_display(struct bar_item* bar_item, uint32_t bit); -void bar_item_append_associated_bar(struct bar_item* bar_item, uint32_t bit); -void bar_item_remove_associated_bar(struct bar_item* bar_item, uint32_t bit); +void bar_item_append_associated_bar(struct bar_item* bar_item, uint32_t adid); +void bar_item_remove_associated_bar(struct bar_item* bar_item, uint32_t adid); void bar_item_reset_associated_bar(struct bar_item* bar_item); void bar_item_set_name(struct bar_item* bar_item, char* name); void bar_item_set_type(struct bar_item* bar_item, char type); @@ -106,6 +106,7 @@ void bar_item_clear_needs_update(struct bar_item* bar_item); void bar_item_on_click(struct bar_item* bar_item); +void bar_item_remove_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid); CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item); void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid, CGPoint bar_origin); diff --git a/src/event.c b/src/event.c index 9dde1cb..ee04226 100644 --- a/src/event.c +++ b/src/event.c @@ -110,14 +110,26 @@ static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) { return EVENT_SUCCESS; } -static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_MOVED) { +static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED) { debug("%s\n", __FUNCTION__); CGPoint point = CGEventGetLocation(context); uint32_t adid = display_arrangement(display_active_display_id()); - printf("EVENT_HANDLER_MOUSE_MOVED: D#%d (x: %.0f, y: %.0f) -> ", adid, point.x, point.y); + printf("EVENT_HANDLER_MOUSE_ENTERED: 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); + printf("item: %s\n", bar_item ? bar_item->name : "NULL"); + //bar_item_on_click(bar_item); + CFRelease(context); + return EVENT_SUCCESS; +} + +static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_EXITED) { + debug("%s\n", __FUNCTION__); + CGPoint point = CGEventGetLocation(context); + uint32_t adid = display_arrangement(display_active_display_id()); + printf("EVENT_HANDLER_MOUSE_EXITED: 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); + printf("item: %s\n", bar_item ? bar_item->name : "NULL"); + //bar_item_on_click(bar_item); CFRelease(context); return EVENT_SUCCESS; } diff --git a/src/event.h b/src/event.h index 3398c2f..5e744a4 100644 --- a/src/event.h +++ b/src/event.h @@ -18,7 +18,8 @@ static EVENT_CALLBACK(EVENT_HANDLER_SYSTEM_WOKE); static EVENT_CALLBACK(EVENT_HANDLER_SHELL_REFRESH); static EVENT_CALLBACK(EVENT_HANDLER_DAEMON_MESSAGE); static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP); -static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_MOVED); +static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED); +static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_EXITED); static EVENT_CALLBACK(EVENT_HANDLER_DISTRIBUTED_NOTIFICATION); #define EVENT_QUEUED 0x0 #define EVENT_PROCESSED 0x1 @@ -44,7 +45,8 @@ enum event_type { SHELL_REFRESH, DAEMON_MESSAGE, MOUSE_UP, - MOUSE_MOVED, + MOUSE_ENTERED, + MOUSE_EXITED, DISTRIBUTED_NOTIFICATION, EVENT_TYPE_COUNT @@ -65,7 +67,8 @@ static const char *event_type_str[] = { [SHELL_REFRESH] = "shell_refresh", [DAEMON_MESSAGE] = "daemon_message", [MOUSE_UP] = "mouse_up", - [MOUSE_MOVED] = "mouse_moved", + [MOUSE_ENTERED] = "mouse_entered", + [MOUSE_EXITED] = "mouse_exited", [DISTRIBUTED_NOTIFICATION] = "distributed_notification", [EVENT_TYPE_COUNT] = "event_type_count" @@ -80,7 +83,8 @@ static event_callback *event_handler[] = { [DISPLAY_RESIZED] = EVENT_HANDLER_DISPLAY_RESIZED, [DISPLAY_CHANGED] = EVENT_HANDLER_DISPLAY_CHANGED, [MOUSE_UP] = EVENT_HANDLER_MOUSE_UP, - [MOUSE_MOVED] = EVENT_HANDLER_MOUSE_MOVED, + [MOUSE_ENTERED] = EVENT_HANDLER_MOUSE_ENTERED, + [MOUSE_EXITED] = EVENT_HANDLER_MOUSE_EXITED, [DISTRIBUTED_NOTIFICATION] = EVENT_HANDLER_DISTRIBUTED_NOTIFICATION, [MENU_BAR_HIDDEN_CHANGED] = EVENT_HANDLER_MENU_BAR_HIDDEN_CHANGED, diff --git a/src/mouse.c b/src/mouse.c index 006a2c9..02677b6 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -8,11 +8,13 @@ static pascal OSStatus mouse_handler(EventHandlerCallRef next, EventRef e, void break; } case kEventMouseEntered: { - printf("entered event: %d \n", GetEventKind(e)); + struct event *event = event_create(&g_event_loop, MOUSE_ENTERED, (void *) CFRetain(CopyEventCGEvent(e))); + event_loop_post(&g_event_loop, event); break; } case kEventMouseExited: { - printf("xited event: %d \n", GetEventKind(e)); + struct event *event = event_create(&g_event_loop, MOUSE_EXITED, (void *) CFRetain(CopyEventCGEvent(e))); + event_loop_post(&g_event_loop, event); break; } default: