decouple update_freq of alias and scripts; introduces alias.update_freq

This commit is contained in:
Felix Kratz 2023-01-09 07:33:24 +01:00
parent 8ecc46acbe
commit edcc10f4b7
4 changed files with 35 additions and 13 deletions

View file

@ -79,6 +79,8 @@ void alias_init(struct alias* alias) {
alias->owner = NULL;
alias->color_override = false;
alias->color = rgba_color_from_hex(0xffff0000);
alias->update_frequency = 1;
alias->counter = 0;
window_init(&alias->window);
image_init(&alias->image);
@ -183,6 +185,19 @@ bool alias_update_image(struct alias* alias) {
return image_set_image(&alias->image, image_ref, alias->window.frame, false);
}
bool alias_update(struct alias* alias) {
if (alias->update_frequency == 0) return false;
alias->counter++;
if (alias->counter >= alias->update_frequency) {
alias->counter = 0;
if (alias_update_image(alias)) {
return true;
}
}
return false;
}
void alias_draw(struct alias* alias, CGContextRef context) {
if (alias->color_override) {
CGContextSaveGState(context);
@ -232,6 +247,9 @@ bool alias_parse_sub_domain(struct alias* alias, FILE* rsp, struct token propert
alias->color = rgba_color_from_hex(token_to_uint32t(get_token(&message)));
alias->color_override = true;
return true;
} else if (token_equals(property, PROPERTY_UPDATE_FREQ)) {
alias->update_frequency = token_to_uint32t(get_token(&message));
return false;
} else {
respond(rsp, "[!] Alias: Invalid property '%s' \n", property.text);
}

View file

@ -8,6 +8,8 @@
struct alias {
bool permission;
uint32_t update_frequency;
uint32_t counter;
char* name;
char* owner;
@ -29,6 +31,7 @@ uint32_t alias_get_height(struct alias* alias);
void alias_calculate_bounds(struct alias* alias, uint32_t x, uint32_t y);
void alias_draw(struct alias* alias, CGContextRef context);
bool alias_update(struct alias* alias);
void alias_destroy(struct alias* alias);
void print_all_menu_items(FILE* rsp);

View file

@ -157,12 +157,6 @@ bool bar_item_update(struct bar_item* bar_item, char* sender, bool forced, struc
mach_send_message(bar_item->event_port, message, len, false);
free(message);
}
// Alias Update
if (bar_item->has_alias && alias_update_image(&bar_item->alias)) {
bar_item_needs_update(bar_item);
return true;
}
}
return false;
}
@ -359,9 +353,7 @@ bool bar_item_set_type(struct bar_item* bar_item, char* type) {
string_copy("0") );
}
else if (bar_item->type == BAR_COMPONENT_ALIAS) {
bar_item->update_frequency = 1;
bar_item->has_alias = true;
bar_item->updates_only_when_shown = true;
}
else if (bar_item->type == BAR_COMPONENT_GRAPH) {
bar_item->has_graph = true;
@ -473,6 +465,10 @@ struct window* bar_item_get_window(struct bar_item* bar_item, uint32_t adid) {
window_set_blur_radius(bar_item->windows[adid - 1], bar_item->blur_radius);
context_set_font_smoothing(bar_item->windows[adid - 1]->context,
g_bar_manager.font_smoothing );
if (bar_item->parent)
bar_item->parent->popup.needs_ordering = true;
else
g_bar_manager.needs_ordering = true;
}

View file

@ -502,10 +502,15 @@ void bar_manager_update(struct bar_manager* bar_manager, bool forced) {
if ((bar_manager->frozen && !forced) || bar_manager->sleeps) return;
bool needs_refresh = false;
for (int i = 0; i < bar_manager->bar_item_count; i++) {
needs_refresh |= bar_item_update(bar_manager->bar_items[i],
NULL,
forced,
NULL );
struct bar_item* bar_item = bar_manager->bar_items[i];
needs_refresh |= bar_item_update(bar_item, NULL, forced, NULL);
if (bar_item->has_alias
&& bar_item_is_shown(bar_item)
&& alias_update(&bar_item->alias)) {
bar_item_needs_update(bar_item);
needs_refresh = true;
}
}
if (needs_refresh) bar_manager_refresh(bar_manager, false);