mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-23 11:53:02 +00:00
fix performance
This commit is contained in:
parent
16ef8709f3
commit
2e3aac4c3e
7 changed files with 55 additions and 25 deletions
|
@ -25,7 +25,8 @@ double function_bounce(double x) {
|
|||
return alpha*alpha * x * x;
|
||||
}
|
||||
else {
|
||||
return beta * beta * (x - 1./2. + 1./alpha/2.) + 1. - beta*beta*(1./2. + 1./alpha/2.);
|
||||
return beta * beta * (x - 1./2. + 1./alpha/2.)
|
||||
+ 1. - beta*beta*(1./2. + 1./alpha/2.);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +100,23 @@ bool animation_update(struct animation* animation) {
|
|||
}
|
||||
|
||||
animation->counter++;
|
||||
return animation->update_function(animation->target, value);
|
||||
bool needs_update = animation->update_function(animation->target, value);
|
||||
|
||||
bool found_item = false;
|
||||
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
|
||||
if (needs_update
|
||||
&& (animation->target >= (void*)g_bar_manager.bar_items[i])
|
||||
&& (animation->target < ((void*)g_bar_manager.bar_items[i]
|
||||
+ sizeof(struct bar_item) ))) {
|
||||
bar_item_needs_update(g_bar_manager.bar_items[i]);
|
||||
found_item = true;
|
||||
}
|
||||
}
|
||||
|
||||
animation->needs_force_refresh = false;
|
||||
if (!found_item && needs_update) animation->needs_force_refresh = true;
|
||||
|
||||
return needs_update;
|
||||
}
|
||||
|
||||
void animator_init(struct animator* animator) {
|
||||
|
@ -166,10 +183,12 @@ 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;
|
||||
|
|
|
@ -60,6 +60,7 @@ struct animation {
|
|||
int final_value;
|
||||
animation_function* interp_function;
|
||||
|
||||
bool needs_force_refresh;
|
||||
void* target;
|
||||
animator_function* update_function;
|
||||
};
|
||||
|
@ -78,6 +79,7 @@ typedef ANIMATOR_CALLBACK(animator_callback);
|
|||
struct animator {
|
||||
CFRunLoopTimerRef clock;
|
||||
|
||||
bool force_refresh;
|
||||
uint32_t interp_function;
|
||||
uint32_t duration;
|
||||
struct animation** animations;
|
||||
|
|
34
src/bar.c
34
src/bar.c
|
@ -94,6 +94,8 @@ void bar_draw(struct bar* bar) {
|
|||
|
||||
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
|
||||
struct bar_item* bar_item = g_bar_manager.bar_items[i];
|
||||
|
||||
|
||||
struct window* window = bar_item_get_window(bar_item, bar->adid);
|
||||
|
||||
if (!(bar_item->position == POSITION_POPUP))
|
||||
|
@ -107,10 +109,7 @@ void bar_draw(struct bar* bar) {
|
|||
}
|
||||
|
||||
bar_item_append_associated_bar(bar_item, bar->adid);
|
||||
|
||||
if (!bar_item->needs_update)
|
||||
continue;
|
||||
|
||||
if (!bar_item->needs_update) continue;
|
||||
|
||||
if (bar_item->update_mask & UPDATE_MOUSE_ENTERED
|
||||
|| bar_item->update_mask & UPDATE_MOUSE_EXITED) {
|
||||
|
@ -127,28 +126,23 @@ void bar_draw(struct bar* bar) {
|
|||
bar->window.origin,
|
||||
bar->window.frame.size.height);
|
||||
|
||||
window_resize(window, (CGRect){{window->origin.x,
|
||||
window->origin.y },
|
||||
{window->frame.size.width,
|
||||
window->frame.size.height}});
|
||||
|
||||
if (bar_item->needs_update) {
|
||||
window_resize(window, (CGRect){{window->origin.x,
|
||||
window->origin.y },
|
||||
{window->frame.size.width,
|
||||
window->frame.size.height}});
|
||||
draw_rect(window->context, window->frame, &g_transparent,
|
||||
0,
|
||||
0,
|
||||
&g_transparent,
|
||||
true );
|
||||
|
||||
draw_rect(window->context, window->frame, &g_transparent,
|
||||
0,
|
||||
0,
|
||||
&g_transparent,
|
||||
true );
|
||||
|
||||
bar_item_draw(bar_item, window->context);
|
||||
CGContextFlush(window->context);
|
||||
}
|
||||
bar_item_draw(bar_item, window->context);
|
||||
CGContextFlush(window->context);
|
||||
|
||||
if (bar_item->popup.drawing && bar->adid == g_bar_manager.active_adid)
|
||||
popup_draw(&bar_item->popup);
|
||||
}
|
||||
|
||||
bar_order_item_windows(bar, 1);
|
||||
}
|
||||
|
||||
void bar_calculate_bounds(struct bar* bar) {
|
||||
|
|
|
@ -30,6 +30,7 @@ void bar_set_hidden(struct bar* bar, bool hidden);
|
|||
void bar_calculate_bounds(struct bar* bar);
|
||||
void bar_resize(struct bar* bar);
|
||||
void bar_draw(struct bar* bar);
|
||||
void bar_order_item_windows(struct bar* bar, int mode);
|
||||
|
||||
bool bar_draws_item(struct bar* bar, struct bar_item* bar_item);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ static CLOCK_CALLBACK(clock_handler) {
|
|||
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->bars = NULL;
|
||||
bar_manager->bar_count = 0;
|
||||
bar_manager->bar_item_count = 0;
|
||||
|
@ -327,9 +328,13 @@ void bar_manager_refresh(struct bar_manager* bar_manager, bool forced) {
|
|||
|| bar_manager_bar_needs_redraw(bar_manager, bar_manager->bars[i])) {
|
||||
bar_calculate_bounds(bar_manager->bars[i]);
|
||||
bar_draw(bar_manager->bars[i]);
|
||||
if (forced || bar_manager->needs_ordering) {
|
||||
bar_order_item_windows(bar_manager->bars[i], 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
bar_manager_clear_needs_update(bar_manager);
|
||||
bar_manager->needs_ordering = false;
|
||||
}
|
||||
|
||||
void bar_manager_resize(struct bar_manager* bar_manager) {
|
||||
|
@ -346,6 +351,7 @@ struct bar_item* bar_manager_create_item(struct bar_manager* bar_manager) {
|
|||
struct bar_item* bar_item = bar_item_create();
|
||||
bar_item_init(bar_item, &bar_manager->default_item);
|
||||
bar_manager->bar_items[bar_manager->bar_item_count - 1] = bar_item;
|
||||
bar_manager->needs_ordering = true;
|
||||
return bar_item;
|
||||
}
|
||||
|
||||
|
@ -398,9 +404,10 @@ 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)) {
|
||||
if (animator_update(&bar_manager->animator)
|
||||
|| bar_manager->animator.force_refresh) {
|
||||
bar_manager->frozen = false;
|
||||
bar_manager_refresh(bar_manager, true);
|
||||
bar_manager_refresh(bar_manager, bar_manager->animator.force_refresh);
|
||||
}
|
||||
bar_manager_unfreeze(bar_manager);
|
||||
}
|
||||
|
@ -415,6 +422,7 @@ void bar_manager_update(struct bar_manager* bar_manager, bool forced) {
|
|||
NULL );
|
||||
}
|
||||
bar_manager_freeze(bar_manager);
|
||||
bar_manager->frozen = false;
|
||||
if (needs_refresh) bar_manager_refresh(bar_manager, false);
|
||||
bar_manager_unfreeze(bar_manager);
|
||||
}
|
||||
|
@ -444,6 +452,8 @@ void bar_manager_begin(struct bar_manager *bar_manager) {
|
|||
bar_manager->bars[index - 1]->adid = index;
|
||||
}
|
||||
}
|
||||
|
||||
bar_manager->needs_ordering = true;
|
||||
}
|
||||
|
||||
struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t adid) {
|
||||
|
@ -537,10 +547,11 @@ void bar_manager_handle_space_change(struct bar_manager* bar_manager) {
|
|||
COMMAND_SUBSCRIBE_SPACE_CHANGE,
|
||||
&env_vars );
|
||||
|
||||
env_vars_destroy(&env_vars);
|
||||
bar_manager_freeze(bar_manager);
|
||||
bar_manager->frozen = false;
|
||||
bar_manager_refresh(bar_manager, true);
|
||||
bar_manager_unfreeze(bar_manager);
|
||||
env_vars_destroy(&env_vars);
|
||||
}
|
||||
|
||||
void bar_manager_handle_display_change(struct bar_manager* bar_manager) {
|
||||
|
@ -565,6 +576,7 @@ void bar_manager_handle_system_woke(struct bar_manager* bar_manager) {
|
|||
NULL );
|
||||
|
||||
bar_manager_freeze(bar_manager);
|
||||
bar_manager->frozen = false;
|
||||
bar_manager_refresh(bar_manager, true);
|
||||
bar_manager_unfreeze(bar_manager);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ struct bar_manager {
|
|||
bool picky_redraw;
|
||||
bool font_smoothing;
|
||||
bool any_bar_hidden;
|
||||
bool needs_ordering;
|
||||
|
||||
char display;
|
||||
char position;
|
||||
|
|
|
@ -463,6 +463,7 @@ static void handle_domain_order(FILE* rsp, struct token domain, char* message) {
|
|||
|
||||
bar_manager_sort(&g_bar_manager, ordering, count);
|
||||
bar_manager_freeze(&g_bar_manager);
|
||||
g_bar_manager.frozen = false;
|
||||
bar_manager_refresh(&g_bar_manager, false);
|
||||
bar_manager_unfreeze(&g_bar_manager);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue