mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-22 19:33:03 +00:00
scripting working
This commit is contained in:
parent
a6a5846f48
commit
8e37e190ab
7 changed files with 16 additions and 16 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ extern bool g_verbose;
|
|||
|
||||
#define DOMAIN_SET "set"
|
||||
|
||||
#define DOMAIN_UPDATE "update"
|
||||
|
||||
/* --------------------------------DOMAIN SET-------------------------------- */
|
||||
|
||||
// Syntax: spacebar -m set <name> <property> <value>
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue