better tracking of bar property change

This commit is contained in:
Felix Kratz 2022-06-08 20:16:59 +02:00
parent 8ecc722b9c
commit c90d2cd8be
7 changed files with 23 additions and 36 deletions

View file

@ -113,8 +113,7 @@ bool animation_update(struct animation* animation) {
}
}
animation->needs_force_refresh = false;
if (!found_item && needs_update) animation->needs_force_refresh = true;
if (!found_item && needs_update) g_bar_manager.bar_needs_update = true;
return needs_update;
}
@ -183,12 +182,10 @@ void animator_remove(struct animator* animator, struct animation* animation) {
bool animator_update(struct animator* animator) {
bool removed = false;
bool needs_refresh = false;
animator->force_refresh = false;
for (uint32_t i = 0; i < animator->animation_count; i++) {
if (removed) i--;
removed = false;
needs_refresh |= animation_update(animator->animations[i]);
animator->force_refresh |= animator->animations[i]->needs_force_refresh;
if (animator->animations[i]->counter > animator->animations[i]->duration) {
animator_remove(animator, animator->animations[i]);
removed = true;

View file

@ -60,7 +60,6 @@ struct animation {
int final_value;
animation_function* interp_function;
bool needs_force_refresh;
void* target;
animator_function* update_function;
};
@ -79,7 +78,6 @@ typedef ANIMATOR_CALLBACK(animator_callback);
struct animator {
CFRunLoopTimerRef clock;
bool force_refresh;
uint32_t interp_function;
uint32_t duration;
struct animation** animations;

View file

@ -94,7 +94,7 @@ void bar_order_item_windows(struct bar* bar, int mode) {
}
void bar_draw(struct bar* bar) {
if (bar->needs_update) {
if (g_bar_manager.bar_needs_update) {
draw_rect(bar->window.context,
bar->window.frame,
&g_bar_manager.background.color,
@ -103,12 +103,11 @@ void bar_draw(struct bar* bar) {
&g_bar_manager.background.border_color,
true );
bar->needs_update = false;
CGContextFlush(bar->window.context);
}
if (g_bar_manager.background.image.enabled) {
image_draw(&g_bar_manager.background.image, bar->window.context);
}
if (g_bar_manager.background.image.enabled) {
image_draw(&g_bar_manager.background.image, bar->window.context);
CGContextFlush(bar->window.context);
}
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
@ -294,12 +293,11 @@ CGRect bar_get_frame(struct bar *bar) {
void bar_resize(struct bar* bar) {
if (bar->hidden) return;
window_set_frame(&bar->window, bar_get_frame(bar));
window_apply_frame(&bar->window);
SLSRemoveAllTrackingAreas(g_connection, bar->window.id);
SLSAddTrackingRect(g_connection, bar->window.id, bar->window.frame);
bar_calculate_bounds(bar);
bar->needs_update = true;
bar_draw(bar);
if (window_apply_frame(&bar->window)) {
SLSRemoveAllTrackingAreas(g_connection, bar->window.id);
SLSAddTrackingRect(g_connection, bar->window.id, bar->window.frame);
g_bar_manager.bar_needs_update = true;
}
}
void bar_set_hidden(struct bar* bar, bool hidden) {
@ -327,7 +325,7 @@ struct bar *bar_create(uint32_t did) {
bar->did = did;
bar->sid = mission_control_index(display_space_id(did));
bar->shown = true;
bar->needs_update = true;
g_bar_manager.bar_needs_update = true;
bar_create_window(bar);
return bar;
}

View file

@ -11,7 +11,6 @@
#define ALIGN_CENTER 5
struct bar {
bool needs_update;
bool shown;
bool hidden;

View file

@ -16,6 +16,7 @@ void bar_manager_init(struct bar_manager* bar_manager) {
bar_manager->font_smoothing = false;
bar_manager->any_bar_hidden = false;
bar_manager->needs_ordering = false;
bar_manager->bar_needs_update = false;
bar_manager->bars = NULL;
bar_manager->bar_count = 0;
bar_manager->bar_item_count = 0;
@ -278,7 +279,7 @@ uint32_t bar_manager_length_for_bar_side(struct bar_manager* bar_manager, struct
}
bool bar_manager_bar_needs_redraw(struct bar_manager* bar_manager, struct bar* bar) {
if (bar->needs_update) return true;
if (bar_manager->bar_needs_update) return true;
for (int i = 0; i < bar_manager->bar_item_count; i++) {
struct bar_item* bar_item = bar_manager->bar_items[i];
@ -298,6 +299,9 @@ bool bar_manager_bar_needs_redraw(struct bar_manager* bar_manager, struct bar* b
void bar_manager_clear_needs_update(struct bar_manager* bar_manager) {
for (int i = 0; i < bar_manager->bar_item_count; i++)
bar_item_clear_needs_update(bar_manager->bar_items[i]);
bar_manager->needs_ordering = false;
bar_manager->bar_needs_update = false;
}
void bar_manager_clear_association_for_bar(struct bar_manager* bar_manager, struct bar* bar) {
@ -329,8 +333,8 @@ void bar_manager_refresh(struct bar_manager* bar_manager, bool forced) {
}
}
}
bar_manager_clear_needs_update(bar_manager);
bar_manager->needs_ordering = false;
}
void bar_manager_resize(struct bar_manager* bar_manager) {
@ -400,16 +404,9 @@ void bar_manager_update_space_components(struct bar_manager* bar_manager, bool f
void bar_manager_animator_refresh(struct bar_manager* bar_manager) {
bar_manager_freeze(bar_manager);
if (animator_update(&bar_manager->animator)
|| bar_manager->animator.force_refresh) {
if (animator_update(&bar_manager->animator)) {
bar_manager->frozen = false;
if (bar_manager->animator.force_refresh) {
for (int i = 0; i < bar_manager->bar_count; i++) {
bar_manager->bars[i]->needs_update = true;
}
}
bar_manager_refresh(bar_manager, false);
}
bar_manager_unfreeze(bar_manager);

View file

@ -17,6 +17,7 @@ struct bar_manager {
bool font_smoothing;
bool any_bar_hidden;
bool needs_ordering;
bool bar_needs_update;
char display;
char position;

View file

@ -629,15 +629,12 @@ void handle_message_mach(struct mach_buffer* buffer) {
command = get_token(&message);
}
g_bar_manager.frozen = false;
if (bar_needs_refresh) bar_manager_resize(&g_bar_manager);
if (bar_needs_refresh) {
for (int i = 0; i < g_bar_manager.bar_count; i++) {
g_bar_manager.bars[i]->needs_update = true;
}
bar_manager_resize(&g_bar_manager);
g_bar_manager.bar_needs_update = true;
}
g_bar_manager.frozen = false;
bar_manager_refresh(&g_bar_manager, false);
bar_manager_unfreeze(&g_bar_manager);