mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-23 20:03:10 +00:00
added custom event flag logic
This commit is contained in:
parent
d82d21eae5
commit
7aefb7c823
6 changed files with 25 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
19
src/custom_events.c
Normal file
19
src/custom_events.c
Normal file
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue