diff --git a/src/bar_manager.c b/src/bar_manager.c index 0f6c802..64a8444 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -99,6 +99,7 @@ void bar_manager_init(struct bar_manager *bar_manager) bar_manager->padding_right = 20; bar_item_init(&bar_manager->default_item, NULL); + custom_events_init(&bar_manager->custom_events); int shell_refresh_frequency = 1; @@ -159,11 +160,6 @@ struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, return NULL; } -uint32_t bar_manager_get_event_flag(struct bar_manager* bar_manager, char* event) { - return 0; -} - - void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager) { bar_manager_check_bar_items_for_update_pattern(bar_manager, UPDATE_FRONT_APP_SWITCHED); } diff --git a/src/bar_manager.h b/src/bar_manager.h index ceaddbb..5ca8435 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -26,7 +26,6 @@ struct bar_manager }; int bar_manager_get_item_index_for_name(struct bar_manager* bar_manager, char* name); -uint32_t bar_manager_get_event_flag(struct bar_manager* bar_manager, char* event); struct bar_item* bar_manager_create_item(struct bar_manager* bar_manager); diff --git a/src/custom_events.c b/src/custom_events.c new file mode 100644 index 0000000..3efcad0 --- /dev/null +++ b/src/custom_events.c @@ -0,0 +1,19 @@ +void custom_events_init(struct custom_events* custom_events) { + custom_events->flag_offset = 4; + custom_events->count = 0; +} + +void custom_event_append(struct custom_events* custom_events, char *name) { + custom_events->count++; + custom_events->names = (char**) realloc(custom_events->names, sizeof(char*) * custom_events->count); + custom_events->names[custom_events->count - 1] = name; +} + +uint32_t custom_events_get_flag_for_name(struct custom_events* custom_events, char* name) { + for (int i = 0; i < custom_events->count; i++) { + if (strcmp(name, custom_events->names[i])) { + return 1 << (i + custom_events->flag_offset); + } + } + return 0; +} diff --git a/src/custom_events.h b/src/custom_events.h index c484bb2..487048c 100644 --- a/src/custom_events.h +++ b/src/custom_events.h @@ -9,5 +9,7 @@ struct custom_events { char** names; }; -void custom_event_append(char* name); +void custom_events_init(struct custom_events* custom_events); +void custom_events_append(struct custom_events* custom_events, char* name); +uint32_t custom_events_get_flag_for_name(struct custom_events* custom_events, char* name); #endif diff --git a/src/manifest.m b/src/manifest.m index fc74f53..c18d7da 100644 --- a/src/manifest.m +++ b/src/manifest.m @@ -57,6 +57,7 @@ #include "bar.c" #include "graph_data.c" #include "bar_item.c" +#include "custom_events.c" #include "bar_manager.c" #include "sketchybar.c" diff --git a/src/message.c b/src/message.c index 1bd8a12..5f40861 100644 --- a/src/message.c +++ b/src/message.c @@ -180,7 +180,7 @@ static void handle_domain_subscribe(FILE* rsp, struct token domain, char* messag } else if (token_equals(event, COMMAND_SUBSCRIBE_FRONT_APP_SWITCHED)) { bar_item->update_mask |= UPDATE_FRONT_APP_SWITCHED; } else { - bar_item->update_mask |= bar_manager_get_event_flag(&g_bar_manager, token_to_string(event)); + bar_item->update_mask |= custom_events_get_flag_for_name(&g_bar_manager.custom_events, token_to_string(event)); } }