diff --git a/src/bar_item.c b/src/bar_item.c index 96e39dc..6531a93 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -7,6 +7,7 @@ struct bar_item* bar_item_create() { } void bar_item_init(struct bar_item* bar_item) { + bar_item->counter = 0; bar_item->name = ""; bar_item->type = BAR_ITEM; bar_item->update_frequency = 5; @@ -28,6 +29,19 @@ void bar_item_init(struct bar_item* bar_item) { bar_item->label_color = rgba_color_from_hex(0xffffffff); } +void bar_item_script_update(struct bar_item* bar_item) { + if (strcmp(bar_item->script, "") != 0) { + if (bar_item->update_frequency <= bar_item->counter) { + bar_item->counter = 0; + } + else { + bar_item->counter++; + return; + } + fork_exec(bar_item->script, NULL); + } +} + void bar_item_update_component(struct bar_item* bar_item, uint32_t did, uint32_t sid) { if (bar_item->type == BAR_COMPONENT) { if (strcmp(bar_item->identifier, "title") == 0) { diff --git a/src/bar_item.h b/src/bar_item.h index ce22241..f3cc040 100644 --- a/src/bar_item.h +++ b/src/bar_item.h @@ -10,6 +10,7 @@ #define BAR_POSITION_CENTER 'c' struct bar_item { + int counter; char type; char* identifier; @@ -54,6 +55,7 @@ struct bar_item { }; struct bar_item* bar_item_create(); +void bar_item_script_update(struct bar_item* bar_item); void bar_item_update_component(struct bar_item* bar_item, uint32_t did, uint32_t sid); void bar_item_init(struct bar_item* bar_item); void bar_item_set_name(struct bar_item* bar_item, char* name); diff --git a/src/bar_manager.c b/src/bar_manager.c index 423eaaf..a0c876b 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -121,6 +121,12 @@ void bar_manager_update_components(struct bar_manager* bar_manager, uint32_t did } } +void bar_manager_script_update(struct bar_manager* bar_manager) { + for (int i = 0; i < bar_manager->bar_item_count; i++) { + bar_item_script_update(bar_manager->bar_items[i]); + } +} + void bar_manager_begin(struct bar_manager *bar_manager) { char * main = "main"; diff --git a/src/bar_manager.h b/src/bar_manager.h index c1e551c..d97d4ba 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -23,6 +23,7 @@ struct bar_manager int bar_manager_get_item_index_for_name(struct bar_manager* bar_manager, char* name); struct bar_item* bar_manager_create_item(struct bar_manager* bar_manager); +void bar_manager_script_update(struct bar_manager* bar_manager); void bar_manager_update_components(struct bar_manager* bar_manager, uint32_t did, uint32_t sid); void bar_manager_set_foreground_color(struct bar_manager *bar_manager, uint32_t color); void bar_manager_set_background_color(struct bar_manager *bar_manager, uint32_t color); diff --git a/src/event.c b/src/event.c index 0848482..cc749d7 100644 --- a/src/event.c +++ b/src/event.c @@ -213,6 +213,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_BAR_REFRESH) static EVENT_CALLBACK(EVENT_HANDLER_SHELL_REFRESH) { + bar_manager_script_update(&g_bar_manager); return EVENT_SUCCESS; }