From 8e37e190abf77bcb13e9a4748e469e68537bb3d2 Mon Sep 17 00:00:00 2001 From: FelixKratz Date: Tue, 10 Aug 2021 01:10:31 +0200 Subject: [PATCH] scripting working --- src/bar.c | 4 ++-- src/bar_item.c | 14 +++++--------- src/bar_item.h | 2 +- src/bar_manager.c | 4 ++-- src/bar_manager.h | 2 +- src/event.c | 2 +- src/message.c | 4 ++++ 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/bar.c b/src/bar.c index f6fcc4b..cf262f0 100644 --- a/src/bar.c +++ b/src/bar.c @@ -310,8 +310,8 @@ struct bar *bar_create(uint32_t did) SLSSetWindowLevel(g_connection, bar->id, CGWindowLevelForKey(4)); bar->context = SLWindowContextCreate(g_connection, bar->id, 0); - int refresh_frequency = 5; - int shell_refresh_frequency = 5; + int refresh_frequency = 1; + int shell_refresh_frequency = 1; bar->power_source = IOPSNotificationCreateRunLoopSource(power_handler, NULL); bar->refresh_timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + refresh_frequency, refresh_frequency, 0, 0, timer_handler, NULL); bar->shell_refresh_timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + shell_refresh_frequency, shell_refresh_frequency, 0, 0, shell_timer_handler, NULL); diff --git a/src/bar_item.c b/src/bar_item.c index 6531a93..92256bc 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -10,7 +10,7 @@ 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; + bar_item->update_frequency = 10; bar_item->script = ""; bar_item->position = BAR_POSITION_RIGHT; bar_item->associated_display = 0; @@ -29,16 +29,13 @@ 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) { +void bar_item_script_update(struct bar_item* bar_item, bool forced) { if (strcmp(bar_item->script, "") != 0) { - if (bar_item->update_frequency <= bar_item->counter) { + bar_item->counter++; + if (bar_item->update_frequency < bar_item->counter || forced) { bar_item->counter = 0; + fork_exec(bar_item->script, NULL); } - else { - bar_item->counter++; - return; - } - fork_exec(bar_item->script, NULL); } } @@ -48,7 +45,6 @@ void bar_item_update_component(struct bar_item* bar_item, uint32_t did, uint32_t bar_item_set_label(bar_item, focused_window_title()); } else if (strcmp(bar_item->identifier, "space") == 0) { - printf("sid: %i did: %i \n", sid, did); if (sid == bar_item->associated_space && did == bar_item->associated_display) { bar_item->icon_color = g_bar_manager.space_icon_color; bar_item_set_icon(bar_item, bar_item->icon); diff --git a/src/bar_item.h b/src/bar_item.h index f3cc040..9d13d69 100644 --- a/src/bar_item.h +++ b/src/bar_item.h @@ -55,7 +55,7 @@ struct bar_item { }; struct bar_item* bar_item_create(); -void bar_item_script_update(struct bar_item* bar_item); +void bar_item_script_update(struct bar_item* bar_item, bool forced); 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 a0c876b..a5db4d7 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -121,9 +121,9 @@ void bar_manager_update_components(struct bar_manager* bar_manager, uint32_t did } } -void bar_manager_script_update(struct bar_manager* bar_manager) { +void bar_manager_script_update(struct bar_manager* bar_manager, bool forced) { for (int i = 0; i < bar_manager->bar_item_count; i++) { - bar_item_script_update(bar_manager->bar_items[i]); + bar_item_script_update(bar_manager->bar_items[i], forced); } } diff --git a/src/bar_manager.h b/src/bar_manager.h index d97d4ba..a2cdd91 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -23,7 +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_script_update(struct bar_manager* bar_manager, bool forced); 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 cc749d7..a7382db 100644 --- a/src/event.c +++ b/src/event.c @@ -213,7 +213,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_BAR_REFRESH) static EVENT_CALLBACK(EVENT_HANDLER_SHELL_REFRESH) { - bar_manager_script_update(&g_bar_manager); + bar_manager_script_update(&g_bar_manager, false); return EVENT_SUCCESS; } diff --git a/src/message.c b/src/message.c index 1d96377..2fd9c09 100644 --- a/src/message.c +++ b/src/message.c @@ -22,6 +22,8 @@ extern bool g_verbose; #define DOMAIN_SET "set" +#define DOMAIN_UPDATE "update" + /* --------------------------------DOMAIN SET-------------------------------- */ // Syntax: spacebar -m set @@ -365,6 +367,8 @@ void handle_message(FILE *rsp, char *message) } else if (token_equals(domain, DOMAIN_SET)){ printf("DOMAIN: SET \n"); handle_domain_set(rsp, domain, message); + } else if (token_equals(domain, DOMAIN_UPDATE)) { + bar_manager_script_update(&g_bar_manager, true); } else { daemon_fail(rsp, "unknown domain '%.*s'\n", domain.length, domain.text); }