From b6b6bf759df491ee3d7e688cbd6d45af7908e2b9 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sat, 16 Apr 2022 23:09:18 +0200 Subject: [PATCH 01/27] started picky redrawing implementation --- src/bar.c | 54 ++++++++++++++++++++++++++++++++-- src/bar_item.c | 75 +++++++++++++++++++++++++++++++++++++---------- src/bar_item.h | 7 ++++- src/bar_manager.c | 12 ++++++-- src/window.c | 9 ++++-- src/window.h | 2 ++ 6 files changed, 134 insertions(+), 25 deletions(-) diff --git a/src/bar.c b/src/bar.c index d54c0cc..dc63422 100644 --- a/src/bar.c +++ b/src/bar.c @@ -3,8 +3,11 @@ #include "event.h" #include "event_loop.h" #include "display.h" +#include "misc/helpers.h" #include "window.h" +struct rgba_color g_transparent = { 0 }; + void bar_draw_graph(struct bar* bar, struct bar_item* bar_item, uint32_t x, bool right_to_left) { if (!bar_item->has_graph) return; } @@ -53,6 +56,7 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b void bar_draw(struct bar* bar) { SLSDisableUpdate(g_connection); + SLSOrderWindow(g_connection, bar->window.id, -1, 0); SLSRemoveAllTrackingAreas(g_connection, bar->window.id); @@ -73,10 +77,24 @@ void bar_draw(struct bar* bar) { if (!(bar_item->position == POSITION_POPUP)) bar_item_remove_associated_bar(bar_item, bar->adid); - if (!bar_draws_item(bar, bar_item)) continue; + + if (!bar_draws_item(bar, bar_item)) { + if (bar_item->lazy) { + struct window* window = bar_item_get_window(bar_item, bar->adid); + SLSRemoveFromOrderingGroup(g_connection, window->id); + SLSOrderWindow(g_connection, window->id, -1, 0); + window_set_level(window, 0); + } + + continue; + } bar_item_append_associated_bar(bar_item, bar->adid); + if (bar_item->lazy && !bar_item->needs_update) + continue; + + if (bar_item->update_mask & UPDATE_MOUSE_ENTERED || bar_item->update_mask & UPDATE_MOUSE_EXITED) { CGRect tracking_rect = cgrect_mirror_y(bar_item_construct_bounding_rect( @@ -93,7 +111,23 @@ void bar_draw(struct bar* bar) { bar->window.frame.size.height); - bar_item_draw(bar_item, bar->window.context); + if (bar_item->lazy) { + struct window* window = bar_item_get_window(bar_item, bar->adid); + + SLSOrderWindow(g_connection, window->id, -1, 0); + draw_rect(window->context, window->frame, &g_transparent, + 0, + 0, + &g_transparent, + true ); + + bar_item_draw(bar_item, window->context); + CGContextFlush(window->context); + SLSOrderWindow(g_connection, window->id, 1, bar->window.id); + } + else { + bar_item_draw(bar_item, bar->window.context); + } if (bar_item->popup.drawing && bar->adid == g_bar_manager.active_adid) popup_draw(&bar_item->popup); } @@ -131,7 +165,9 @@ void bar_calculate_bounds(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]; - if (!bar_draws_item(bar, bar_item)) continue; + if (!bar_draws_item(bar, bar_item)) { + continue; + } uint32_t bar_item_display_length = bar_item_get_length(bar_item, true); bool rtl = false; @@ -162,6 +198,18 @@ void bar_calculate_bounds(struct bar* bar) { *next_position, y ); + if (bar_item->lazy) { + struct window* window = bar_item_get_window(bar_item, bar->adid); + window_set_level(window, g_bar_manager.window_level); + SLSAddWindowToWindowOrderingGroup(g_connection, bar->window.id, window->id, 1); + window_resize(window, (CGRect){{bar->window.origin.x + *next_position, + bar->window.origin.y }, + {bar_item_display_length + + abs(bar_item->background.padding_left) + + abs(bar_item->background.padding_right), + bar->window.frame.size.height}}); + } + if (bar_item->popup.drawing) bar_calculate_popup_anchor_for_bar_item(bar, bar_item); diff --git a/src/bar_item.c b/src/bar_item.c index 05a9cff..1b9267a 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -153,13 +153,13 @@ void bar_item_append_associated_bar(struct bar_item* bar_item, uint32_t adid) { void bar_item_remove_associated_bar(struct bar_item* bar_item, uint32_t adid) { bar_item->associated_bar &= ~(1 << (adid - 1)); - bar_item_remove_bounding_rect_for_display(bar_item, adid); + bar_item_remove_bounding_rect(bar_item, adid); } void bar_item_reset_associated_bar(struct bar_item* bar_item) { bar_item->associated_bar = 0; for (uint32_t adid = 1; adid <= bar_item->num_rects; adid++) - bar_item_remove_bounding_rect_for_display(bar_item, adid); + bar_item_remove_bounding_rect(bar_item, adid); } bool bar_item_update(struct bar_item* bar_item, char* sender, bool forced, struct env_vars* env_vars) { @@ -399,7 +399,40 @@ uint32_t bar_item_get_height(struct bar_item* bar_item) { return item_height; } -void bar_item_remove_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid) { +struct window* bar_item_get_window(struct bar_item* bar_item, uint32_t adid) { + if (adid <= 0) return NULL; + if (bar_item->num_windows < adid) { + bar_item->windows = (struct window**) realloc(bar_item->windows, + sizeof(struct window*)*adid); + memset(bar_item->windows + bar_item->num_windows, + 0, + sizeof(struct window*) * (adid - bar_item->num_windows)); + + bar_item->num_windows = adid; + } + if (!bar_item->windows[adid - 1]) { + bar_item->windows[adid - 1] = malloc(sizeof(struct window)); + window_create(bar_item->windows[adid - 1], (CGRect){{0,0}, {1, 1}}); + window_disable_shadow(bar_item->windows[adid - 1]); + context_set_font_smoothing(bar_item->windows[adid - 1]->context, + g_bar_manager.font_smoothing ); + + window_set_level(bar_item->windows[adid - 1], + g_bar_manager.window_level + 1); + } + + return bar_item->windows[adid - 1]; +} + +void bar_item_remove_window(struct bar_item* bar_item, uint32_t adid) { + if (bar_item->num_windows >= adid && bar_item->windows[adid - 1]) { + window_close(bar_item->windows[adid - 1]); + free(bar_item->windows[adid - 1]); + bar_item->windows[adid - 1] = NULL; + } +} + +void bar_item_remove_bounding_rect(struct bar_item* bar_item, uint32_t adid) { if (bar_item->num_rects >= adid && bar_item->bounding_rects[adid - 1]) { free(bar_item->bounding_rects[adid - 1]); bar_item->bounding_rects[adid - 1] = NULL; @@ -451,7 +484,12 @@ void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t } uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_height, uint32_t x, uint32_t y) { + if (bar_item->lazy) { + x = 0; + } + uint32_t content_x = x; + uint32_t content_y = y; uint32_t bar_item_length = bar_item_get_length(bar_item, false); uint32_t bar_item_content_length = bar_item_get_content_length(bar_item); @@ -463,6 +501,9 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh } uint32_t icon_position = content_x + bar_item->background.padding_left; + if ((int)content_x + bar_item->background.padding_left < 0) + icon_position = 0; + uint32_t label_position = icon_position + text_get_length(&bar_item->icon, false ); @@ -481,22 +522,22 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh - group_get_length(bar_item->group) + bar_item_length ) : icon_position, - y, + content_y, bar_item->position == POSITION_RIGHT || bar_item->position == POSITION_CENTER_LEFT); text_calculate_bounds(&bar_item->icon, icon_position, - y + bar_item->y_offset); + content_y + bar_item->y_offset); text_calculate_bounds(&bar_item->label, label_position, - y + bar_item->y_offset); + content_y + bar_item->y_offset); if (bar_item->has_alias) alias_calculate_bounds(&bar_item->alias, sandwich_position, - y + bar_item->y_offset); + content_y + bar_item->y_offset); if (bar_item->has_graph) { bar_item->graph.bounds.size.height = bar_item->background.enabled @@ -505,7 +546,8 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh : (bar_height - (g_bar_manager.background.border_width + 1)); - graph_calculate_bounds(&bar_item->graph, sandwich_position, y + bar_item->y_offset); + graph_calculate_bounds(&bar_item->graph, sandwich_position, + content_y + bar_item->y_offset); } if (bar_item->background.enabled) { @@ -517,7 +559,7 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh bar_item->background.bounds.size.width = bar_item_length; background_calculate_bounds(&bar_item->background, x + bar_item->background.padding_left, - y + bar_item->y_offset ); + content_y + bar_item->y_offset ); } return bar_item_length; } @@ -544,12 +586,10 @@ void bar_item_destroy(struct bar_item* bar_item) { text_destroy(&bar_item->icon); text_destroy(&bar_item->label); - if (bar_item->bounding_rects) { - for (int j = 0; j < bar_item->num_rects; j++) { - free(bar_item->bounding_rects[j]); - } - free(bar_item->bounding_rects); + for (int j = 0; j < bar_item->num_rects; j++) { + bar_item_remove_bounding_rect(bar_item, j); } + if (bar_item->bounding_rects) free(bar_item->bounding_rects); if (bar_item->has_graph) { graph_destroy(&bar_item->graph); @@ -568,6 +608,11 @@ void bar_item_destroy(struct bar_item* bar_item) { popup_destroy(&bar_item->popup); background_destroy(&bar_item->background); + for (int j = 0; j < bar_item->num_windows; j++) { + bar_item_remove_window(bar_item, j); + } + if (bar_item->windows) free(bar_item->windows); + free(bar_item); } @@ -773,6 +818,7 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE* printf("cache_scripts property is deprecated.\n"); } else if (token_equals(property, PROPERTY_LAZY)) { bar_item->lazy = evaluate_boolean_state(get_token(&message), bar_item->lazy); + needs_update = true; } else if (token_equals(property, PROPERTY_IGNORE_ASSOCIATION)) { bar_item->ignore_association = evaluate_boolean_state(get_token(&message), bar_item->ignore_association); @@ -796,4 +842,3 @@ void bar_item_parse_subscribe_message(struct bar_item* bar_item, char* message) event = get_token(&message); } } - diff --git a/src/bar_item.h b/src/bar_item.h index 639e825..5e3d035 100644 --- a/src/bar_item.h +++ b/src/bar_item.h @@ -70,6 +70,10 @@ struct bar_item { uint32_t num_rects; CGRect** bounding_rects; + // Windows + uint32_t num_windows; + struct window** windows; + // Popup struct popup popup; }; @@ -105,7 +109,8 @@ void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t modifi void bar_item_mouse_entered(struct bar_item* bar_item); void bar_item_mouse_exited(struct bar_item* bar_item); -void bar_item_remove_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid); +struct window* bar_item_get_window(struct bar_item* bar_item, uint32_t adid); +void bar_item_remove_bounding_rect(struct bar_item* bar_item, uint32_t adid); CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item); void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid, CGPoint bar_origin, uint32_t height); diff --git a/src/bar_manager.c b/src/bar_manager.c index 4b65900..b2f2028 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -1,4 +1,5 @@ #include "bar_manager.h" +#include "bar_item.h" #include "event.h" #include "event_loop.h" #include "misc/env_vars.h" @@ -274,8 +275,7 @@ bool bar_manager_bar_needs_redraw(struct bar_manager* bar_manager, struct bar* b if ((bar_item->drawing || (!bar_item->drawing && bar_item->associated_bar != 0)) && bar_item->needs_update && (is_associated_space_shown - || is_associated_display_shown) - && (!bar_item->lazy || bar_manager->picky_redraw) ) { + || is_associated_display_shown)) { return true; } } @@ -299,7 +299,13 @@ void bar_manager_reset_bar_association(struct bar_manager* bar_manager) { void bar_manager_refresh(struct bar_manager* bar_manager, bool forced) { if (bar_manager->frozen) return; - if (forced) bar_manager_reset_bar_association(bar_manager); + if (forced) { + bar_manager_reset_bar_association(bar_manager); + for (int j = 0; j < bar_manager->bar_item_count; j++) { + bar_item_needs_update(bar_manager->bar_items[j]); + } + } + for (int i = 0; i < bar_manager->bar_count; ++i) { if (forced || bar_manager_bar_needs_redraw(bar_manager, bar_manager->bars[i])) { diff --git a/src/window.c b/src/window.c index b496b37..62f37ab 100644 --- a/src/window.c +++ b/src/window.c @@ -1,4 +1,5 @@ #include "window.h" +#include "alias.h" static CFTypeRef window_create_region(struct window *window, CGRect frame) { window->frame = (CGRect) {{0, 0},{frame.size.width, frame.size.height}}; @@ -30,8 +31,12 @@ void window_create(struct window* window, CGRect frame) { } void window_resize(struct window* window, CGRect frame) { + CGRect out; + SLSGetScreenRectForWindow(g_connection, window->id, &out); + + if (CGRectEqualToRect(frame, out)) return; + CFTypeRef frame_region = window_create_region(window, frame); - SLSDisableUpdate(g_connection); SLSOrderWindow(g_connection, window->id, -1, 0); SLSSetWindowShape(g_connection, window->id, @@ -43,8 +48,6 @@ void window_resize(struct window* window, CGRect frame) { SLSAddActivationRegion(g_connection, window->id, frame_region); SLSRemoveAllTrackingAreas(g_connection, window->id); - SLSOrderWindow(g_connection, window->id, 1, 0); - SLSReenableUpdate(g_connection); CFRelease(frame_region); } diff --git a/src/window.h b/src/window.h index add3c38..0cea1e4 100644 --- a/src/window.h +++ b/src/window.h @@ -21,6 +21,8 @@ extern CGError SLSClearActivationRegion(uint32_t cid, uint32_t wid); extern CGError SLSRemoveAllTrackingAreas(uint32_t cid, uint32_t wid); extern CGError SLSMoveWindow(int cid, uint32_t wid, CGPoint *point); extern CGError SLSWindowSetShadowProperties(uint32_t wid, CFDictionaryRef properties); +extern CGError SLSAddWindowToWindowOrderingGroup(int cid, uint32_t parent_wid, uint32_t child_wid, int order); +extern CGError SLSRemoveFromOrderingGroup(int cid, uint32_t wid); extern int SLSSpaceGetType(int cid, uint64_t sid); #define kCGSHighQualityResamplingTagBit (1ULL << 4) From b29c5561575565c34a6d332d4a2030f5243d6d3f Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sat, 16 Apr 2022 23:13:02 +0200 Subject: [PATCH 02/27] fix segfault --- src/bar_item.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bar_item.c b/src/bar_item.c index 1b9267a..0509e42 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -586,7 +586,7 @@ void bar_item_destroy(struct bar_item* bar_item) { text_destroy(&bar_item->icon); text_destroy(&bar_item->label); - for (int j = 0; j < bar_item->num_rects; j++) { + for (int j = 1; j < bar_item->num_rects; j++) { bar_item_remove_bounding_rect(bar_item, j); } if (bar_item->bounding_rects) free(bar_item->bounding_rects); @@ -608,7 +608,7 @@ void bar_item_destroy(struct bar_item* bar_item) { popup_destroy(&bar_item->popup); background_destroy(&bar_item->background); - for (int j = 0; j < bar_item->num_windows; j++) { + for (int j = 1; j < bar_item->num_windows; j++) { bar_item_remove_window(bar_item, j); } if (bar_item->windows) free(bar_item->windows); From 730a118008f6cdda1d4bccf5adb7998945dc511c Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Thu, 26 May 2022 13:37:30 +0200 Subject: [PATCH 03/27] this is not working --- src/bar.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/bar.c b/src/bar.c index 318a395..8609f24 100644 --- a/src/bar.c +++ b/src/bar.c @@ -110,18 +110,20 @@ void bar_draw(struct bar* bar) { if (bar_item->lazy) { - struct window* window = bar_item_get_window(bar_item, bar->adid); + if (bar_item->needs_update) { + struct window* window = bar_item_get_window(bar_item, bar->adid); - SLSOrderWindow(g_connection, window->id, -1, 0); - draw_rect(window->context, window->frame, &g_transparent, - 0, - 0, - &g_transparent, - true ); + SLSOrderWindow(g_connection, window->id, -1, 0); + draw_rect(window->context, window->frame, &g_transparent, + 0, + 0, + &g_transparent, + true ); - bar_item_draw(bar_item, window->context); - CGContextFlush(window->context); - SLSOrderWindow(g_connection, window->id, 1, bar->window.id); + bar_item_draw(bar_item, window->context); + CGContextFlush(window->context); + SLSOrderWindow(g_connection, window->id, 1, bar->window.id); + } } else { bar_item_draw(bar_item, bar->window.context); From 81f51b49e76c03c2aae8cea3c306c10410fab68d Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sat, 4 Jun 2022 13:45:26 +0200 Subject: [PATCH 04/27] still very buggy --- src/bar.c | 30 +++++++++++++++--------------- src/bar.h | 1 + src/bar_item.c | 7 ++++--- src/bar_manager.c | 11 +++++++++++ 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/bar.c b/src/bar.c index 8609f24..afbd788 100644 --- a/src/bar.c +++ b/src/bar.c @@ -6,8 +6,6 @@ #include "misc/helpers.h" #include "window.h" -struct rgba_color g_transparent = { 0 }; - void bar_draw_graph(struct bar* bar, struct bar_item* bar_item, uint32_t x, bool right_to_left) { if (!bar_item->has_graph) return; } @@ -55,16 +53,18 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b } void bar_draw(struct bar* bar) { - SLSOrderWindow(g_connection, bar->window.id, -1, 0); SLSRemoveAllTrackingAreas(g_connection, bar->window.id); - draw_rect(bar->window.context, - bar->window.frame, - &g_bar_manager.background.color, - g_bar_manager.background.corner_radius, - g_bar_manager.background.border_width, - &g_bar_manager.background.border_color, - true ); + if (bar->needs_update) { + draw_rect(bar->window.context, + bar->window.frame, + &g_bar_manager.background.color, + g_bar_manager.background.corner_radius, + g_bar_manager.background.border_width, + &g_bar_manager.background.border_color, + true ); + bar->needs_update = false; + } if (g_bar_manager.background.image.enabled) { image_draw(&g_bar_manager.background.image, bar->window.context); @@ -79,9 +79,8 @@ void bar_draw(struct bar* bar) { if (!bar_draws_item(bar, bar_item)) { if (bar_item->lazy) { struct window* window = bar_item_get_window(bar_item, bar->adid); - SLSRemoveFromOrderingGroup(g_connection, window->id); - SLSOrderWindow(g_connection, window->id, -1, 0); - window_set_level(window, 0); + // SLSRemoveFromOrderingGroup(g_connection, window->id); + SLSOrderWindow(g_connection, window->id, -1, bar->window.id); } continue; @@ -113,7 +112,6 @@ void bar_draw(struct bar* bar) { if (bar_item->needs_update) { struct window* window = bar_item_get_window(bar_item, bar->adid); - SLSOrderWindow(g_connection, window->id, -1, 0); draw_rect(window->context, window->frame, &g_transparent, 0, 0, @@ -133,7 +131,6 @@ void bar_draw(struct bar* bar) { } CGContextFlush(bar->window.context); - SLSOrderWindow(g_connection, bar->window.id, 1, bar->window.id); } void bar_calculate_bounds(struct bar* bar) { @@ -204,6 +201,7 @@ void bar_calculate_bounds(struct bar* bar) { struct window* window = bar_item_get_window(bar_item, bar->adid); window_set_level(window, g_bar_manager.window_level); SLSAddWindowToWindowOrderingGroup(g_connection, bar->window.id, window->id, 1); + // TODO: Fix for negative background paddings window_resize(window, (CGRect){{bar->window.origin.x + *next_position, bar->window.origin.y }, {bar_item_display_length @@ -256,6 +254,7 @@ void bar_resize(struct bar* bar) { if (bar->hidden) return; window_resize(&bar->window, bar_get_frame(bar)); bar_calculate_bounds(bar); + bar->needs_update = true; bar_draw(bar); } @@ -282,6 +281,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; bar_create_window(bar); return bar; } diff --git a/src/bar.h b/src/bar.h index 835bb66..8f4d571 100644 --- a/src/bar.h +++ b/src/bar.h @@ -11,6 +11,7 @@ #define ALIGN_CENTER 5 struct bar { + bool needs_update; bool shown; bool hidden; diff --git a/src/bar_item.c b/src/bar_item.c index 73ec30a..fad9e97 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -73,7 +73,7 @@ void bar_item_inherit_from_item(struct bar_item* bar_item, struct bar_item* ance void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item) { bar_item->needs_update = true; - bar_item->lazy = false; + bar_item->lazy = true; bar_item->drawing = true; bar_item->updates = true; bar_item->updates_only_when_shown = false; @@ -878,8 +878,9 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE* } else if (token_equals(property, PROPERTY_CACHE_SCRIPTS)) { printf("cache_scripts property is deprecated.\n"); } else if (token_equals(property, PROPERTY_LAZY)) { - bar_item->lazy = evaluate_boolean_state(get_token(&message), bar_item->lazy); - needs_refresh = true; + printf("lazy property is deprecated.\n"); + // bar_item->lazy = evaluate_boolean_state(get_token(&message), bar_item->lazy); + // needs_refresh = true; } else if (token_equals(property, PROPERTY_IGNORE_ASSOCIATION)) { bar_item->ignore_association = evaluate_boolean_state(get_token(&message), bar_item->ignore_association); diff --git a/src/bar_manager.c b/src/bar_manager.c index 8208d34..4f4e3e9 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -263,6 +263,12 @@ void bar_manager_freeze(struct bar_manager *bar_manager) { for (int i = 0; i < bar_manager->bar_count; i++) { window_freeze(&bar_manager->bars[i]->window); } + for (int i = 0; i < bar_manager->bar_item_count; i++) { + if (!bar_manager->bar_items[i]->needs_update) continue; + for (int j = 0; j < bar_manager->bar_items[i]->num_windows; j++) { + window_freeze(bar_manager->bar_items[i]->windows[j]); + } + } } void bar_manager_unfreeze(struct bar_manager *bar_manager) { @@ -270,6 +276,11 @@ void bar_manager_unfreeze(struct bar_manager *bar_manager) { for (int i = 0; i < bar_manager->bar_count; i++) { window_unfreeze(&bar_manager->bars[i]->window); } + for (int i = 0; i < bar_manager->bar_item_count; i++) { + for (int j = 0; j < bar_manager->bar_items[i]->num_windows; j++) { + window_unfreeze(bar_manager->bar_items[i]->windows[j]); + } + } } uint32_t bar_manager_length_for_bar_side(struct bar_manager* bar_manager, struct bar* bar, char side) { From ddfea5392c0cdfdddb1e45bced9bcf3e55f4f8ca Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sat, 4 Jun 2022 21:02:08 +0200 Subject: [PATCH 05/27] ... --- src/bar.c | 95 +++++++++++++++++++++++++++++--------------------- src/bar_item.c | 12 ++++--- src/window.c | 11 ++++-- 3 files changed, 70 insertions(+), 48 deletions(-) diff --git a/src/bar.c b/src/bar.c index afbd788..6f3dc97 100644 --- a/src/bar.c +++ b/src/bar.c @@ -72,23 +72,21 @@ 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)) bar_item_remove_associated_bar(bar_item, bar->adid); if (!bar_draws_item(bar, bar_item)) { - if (bar_item->lazy) { - struct window* window = bar_item_get_window(bar_item, bar->adid); - // SLSRemoveFromOrderingGroup(g_connection, window->id); - SLSOrderWindow(g_connection, window->id, -1, bar->window.id); - } + CGPoint nirvana = {-9999, -9999}; + SLSMoveWindow(g_connection, window->id, &nirvana); continue; } bar_item_append_associated_bar(bar_item, bar->adid); - if (bar_item->lazy && !bar_item->needs_update) + if (!bar_item->needs_update) continue; @@ -108,24 +106,18 @@ void bar_draw(struct bar* bar) { bar->window.frame.size.height); - if (bar_item->lazy) { - if (bar_item->needs_update) { - struct window* window = bar_item_get_window(bar_item, bar->adid); + if (bar_item->needs_update) { + 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); + // SLSOrderWindow(g_connection, window->id, 1, bar->window.id); + } - bar_item_draw(bar_item, window->context); - CGContextFlush(window->context); - SLSOrderWindow(g_connection, window->id, 1, bar->window.id); - } - } - else { - bar_item_draw(bar_item, bar->window.context); - } if (bar_item->popup.drawing && bar->adid == g_bar_manager.active_adid) popup_draw(&bar_item->popup); } @@ -161,6 +153,7 @@ void bar_calculate_bounds(struct bar* bar) { uint32_t* next_position = NULL; uint32_t y = bar->window.frame.size.height / 2; + struct window* previous_window = NULL; for (int i = 0; i < g_bar_manager.bar_item_count; i++) { struct bar_item* bar_item = g_bar_manager.bar_items[i]; @@ -187,8 +180,10 @@ void bar_calculate_bounds(struct bar* bar) { if (bar_item->position == POSITION_RIGHT || bar_item->position == POSITION_CENTER_LEFT) *next_position -= bar_item_display_length - + bar_item->background.padding_left + bar_item->background.padding_right; + else { + *next_position += bar_item->background.padding_left; + } bar_item->graph.rtl = rtl; uint32_t bar_item_length = bar_item_calculate_bounds(bar_item, @@ -197,18 +192,36 @@ void bar_calculate_bounds(struct bar* bar) { *next_position, y ); - if (bar_item->lazy) { - struct window* window = bar_item_get_window(bar_item, bar->adid); - window_set_level(window, g_bar_manager.window_level); - SLSAddWindowToWindowOrderingGroup(g_connection, bar->window.id, window->id, 1); - // TODO: Fix for negative background paddings - window_resize(window, (CGRect){{bar->window.origin.x + *next_position, - bar->window.origin.y }, - {bar_item_display_length - + abs(bar_item->background.padding_left) - + abs(bar_item->background.padding_right), - bar->window.frame.size.height}}); + struct window* window = bar_item_get_window(bar_item, bar->adid); + window_set_level(window, g_bar_manager.window_level); + // SLSRemoveFromOrderingGroup(g_connection, window->id); + if (previous_window) { + SLSOrderWindow(g_connection, window->id, 1, previous_window->id); + SLSAddWindowToWindowOrderingGroup(g_connection, + previous_window->id, + window->id, + 1 ); } + else { + SLSOrderWindow(g_connection, window->id, 1, bar->window.id); + SLSAddWindowToWindowOrderingGroup(g_connection, + bar->window.id, + window->id, + 1 ); + } + + uint32_t group_length = 0; + if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) { + group_length = group_get_length(bar_item->group); + } + + window_resize(window, (CGRect){{bar->window.origin.x + *next_position, + bar->window.origin.y }, + {bar_item_display_length + + group_length + + abs(bar_item->background.padding_left) + + abs(bar_item->background.padding_right), + bar->window.frame.size.height}}); if (bar_item->popup.drawing) bar_calculate_popup_anchor_for_bar_item(bar, bar_item); @@ -218,14 +231,15 @@ void bar_calculate_bounds(struct bar* bar) { *next_position += bar_item->has_const_width ? bar_item_display_length + bar_item->background.padding_left - + bar_item->background.padding_right - bar_item->custom_width - : 0; - } else + : bar_item->background.padding_right; + } else { *next_position += bar_item->has_const_width - ? bar_item->custom_width - : (bar_item_length + bar_item->background.padding_left - + bar_item->background.padding_right ); + ? bar_item->custom_width - bar_item->background.padding_left + : (bar_item_length + + bar_item->background.padding_right); + } + previous_window = window; } } @@ -271,6 +285,7 @@ void bar_create_window(struct bar* bar) { if (!g_bar_manager.shadow) window_disable_shadow(&bar->window); window_set_level(&bar->window, g_bar_manager.window_level); + SLSOrderWindow(g_connection, bar->window.id, 1, 0); context_set_font_smoothing(bar->window.context, g_bar_manager.font_smoothing); } diff --git a/src/bar_item.c b/src/bar_item.c index fad9e97..bd75c2d 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -16,6 +16,8 @@ void bar_item_clear_pointers(struct bar_item* bar_item) { bar_item->num_rects = 0; bar_item->signal_args.env_vars.vars = NULL; bar_item->signal_args.env_vars.count = 0; + bar_item->windows = NULL; + bar_item->num_windows = 0; text_clear_pointers(&bar_item->icon); text_clear_pointers(&bar_item->label); background_clear_pointers(&bar_item->background); @@ -509,10 +511,10 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh content_x += bar_item_length - bar_item_content_length; } - uint32_t icon_position = content_x + bar_item->background.padding_left; - if ((int)content_x + bar_item->background.padding_left < 0) - icon_position = 0; - + uint32_t icon_position = content_x; + // if ((int)content_x + bar_item->background.padding_left < 0) + // icon_position = 0; + // uint32_t label_position = icon_position + text_get_length(&bar_item->icon, false ); @@ -567,7 +569,7 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh bar_item->background.bounds.size.width = bar_item_length; background_calculate_bounds(&bar_item->background, - x + bar_item->background.padding_left, + x, content_y + bar_item->y_offset ); } return bar_item_length; diff --git a/src/window.c b/src/window.c index 6fc8e8a..9ee2180 100644 --- a/src/window.c +++ b/src/window.c @@ -60,15 +60,20 @@ void window_resize(struct window* window, CGRect frame) { SLSGetScreenRectForWindow(g_connection, window->id, &out); if (CGRectEqualToRect(frame, out)) return; + else if (CGSizeEqualToSize(frame.size, out.size)) { + window->origin = frame.origin; + SLSMoveWindow(g_connection, window->id, &window->origin); + return; + } CFTypeRef frame_region = window_create_region(window, frame); - SLSOrderWindow(g_connection, window->id, -1, 0); SLSSetWindowShape(g_connection, window->id, - window->origin.x, - window->origin.y, + 0, + 0, frame_region ); + SLSMoveWindow(g_connection, window->id, &window->origin); SLSClearActivationRegion(g_connection, window->id); SLSAddActivationRegion(g_connection, window->id, frame_region); SLSRemoveAllTrackingAreas(g_connection, window->id); From 8e066f5f3b7b850879acad2ada6629c676fb3d4d Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sun, 5 Jun 2022 14:50:55 +0200 Subject: [PATCH 06/27] fix geometry, groups and clicks still not working --- src/bar.c | 10 ++++++---- src/bar_item.c | 10 ++-------- src/bar_manager.c | 19 ++----------------- src/window.c | 4 ++-- src/window.h | 5 +++-- 5 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/bar.c b/src/bar.c index 6f3dc97..3960c5e 100644 --- a/src/bar.c +++ b/src/bar.c @@ -178,9 +178,10 @@ void bar_calculate_bounds(struct bar* bar) { continue; if (bar_item->position == POSITION_RIGHT - || bar_item->position == POSITION_CENTER_LEFT) + || bar_item->position == POSITION_CENTER_LEFT) { *next_position -= bar_item_display_length + bar_item->background.padding_right; + } else { *next_position += bar_item->background.padding_left; } @@ -230,12 +231,13 @@ void bar_calculate_bounds(struct bar* bar) { || bar_item->position == POSITION_CENTER_LEFT) { *next_position += bar_item->has_const_width ? bar_item_display_length - + bar_item->background.padding_left + + bar_item->background.padding_right - bar_item->custom_width - : bar_item->background.padding_right; + : - bar_item->background.padding_left; } else { *next_position += bar_item->has_const_width - ? bar_item->custom_width - bar_item->background.padding_left + ? bar_item->custom_width + - bar_item->background.padding_left : (bar_item_length + bar_item->background.padding_right); } diff --git a/src/bar_item.c b/src/bar_item.c index bd75c2d..4f7246a 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -495,11 +495,8 @@ void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t } uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_height, uint32_t x, uint32_t y) { - if (bar_item->lazy) { - x = 0; - } - - uint32_t content_x = x; + x = 0; + uint32_t content_x = 0; uint32_t content_y = y; uint32_t bar_item_length = bar_item_get_length(bar_item, false); @@ -512,9 +509,6 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh } uint32_t icon_position = content_x; - // if ((int)content_x + bar_item->background.padding_left < 0) - // icon_position = 0; - // uint32_t label_position = icon_position + text_get_length(&bar_item->icon, false ); diff --git a/src/bar_manager.c b/src/bar_manager.c index 4f4e3e9..116dfc9 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -260,27 +260,12 @@ bool bar_manager_set_topmost(struct bar_manager *bar_manager, bool topmost) { void bar_manager_freeze(struct bar_manager *bar_manager) { bar_manager->frozen = true; - for (int i = 0; i < bar_manager->bar_count; i++) { - window_freeze(&bar_manager->bars[i]->window); - } - for (int i = 0; i < bar_manager->bar_item_count; i++) { - if (!bar_manager->bar_items[i]->needs_update) continue; - for (int j = 0; j < bar_manager->bar_items[i]->num_windows; j++) { - window_freeze(bar_manager->bar_items[i]->windows[j]); - } - } + windows_freeze(); } void bar_manager_unfreeze(struct bar_manager *bar_manager) { bar_manager->frozen = false; - for (int i = 0; i < bar_manager->bar_count; i++) { - window_unfreeze(&bar_manager->bars[i]->window); - } - for (int i = 0; i < bar_manager->bar_item_count; i++) { - for (int j = 0; j < bar_manager->bar_items[i]->num_windows; j++) { - window_unfreeze(bar_manager->bar_items[i]->windows[j]); - } - } + windows_unfreeze(); } uint32_t bar_manager_length_for_bar_side(struct bar_manager* bar_manager, struct bar* bar, char side) { diff --git a/src/window.c b/src/window.c index 9ee2180..a2d4507 100644 --- a/src/window.c +++ b/src/window.c @@ -47,11 +47,11 @@ void window_create(struct window* window, CGRect frame) { } -void window_freeze(struct window* window) { +void windows_freeze() { SLSDisableUpdate(g_connection); } -void window_unfreeze(struct window* window) { +void windows_unfreeze() { SLSReenableUpdate(g_connection); } diff --git a/src/window.h b/src/window.h index a652ceb..6f8e597 100644 --- a/src/window.h +++ b/src/window.h @@ -50,11 +50,12 @@ struct window { void window_create(struct window* window, CGRect frame); void window_close(struct window* window); void window_resize(struct window* window, CGRect frame); -void window_freeze(struct window* window); -void window_unfreeze(struct window* window); void window_set_blur_radius(struct window* window, uint32_t blur_radius); void window_disable_shadow(struct window* window); void window_set_level(struct window* window, uint32_t level); void context_set_font_smoothing(CGContextRef context, bool smoothing); + +void windows_freeze(); +void windows_unfreeze(); From 16ef8709f3040b7ede3e97c8c7f5be3f4d52b1da Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sun, 5 Jun 2022 17:14:15 +0200 Subject: [PATCH 07/27] fix groups and flickering --- src/bar.c | 82 +++++++++++++++++++++++++++-------------------- src/bar_item.c | 9 ++++-- src/bar_manager.c | 8 +++++ src/group.c | 5 +++ src/group.h | 1 + src/message.c | 2 ++ src/window.c | 12 +++---- 7 files changed, 76 insertions(+), 43 deletions(-) diff --git a/src/bar.c b/src/bar.c index 3960c5e..9136f60 100644 --- a/src/bar.c +++ b/src/bar.c @@ -52,6 +52,26 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b popup_set_anchor(&bar_item->popup, anchor, bar->adid); } +void bar_order_item_windows(struct bar* bar, int mode) { + struct window* previous_window = NULL; + for (int i = 0; i < g_bar_manager.bar_item_count; i++) { + struct bar_item* bar_item = g_bar_manager.bar_items[i]; + + if (!bar_draws_item(bar, bar_item)) continue; + + struct window* window = bar_item_get_window(bar_item, bar->adid); + window_set_level(window, g_bar_manager.window_level); + + if (previous_window) { + SLSOrderWindow(g_connection, window->id, mode, previous_window->id); + } + else { + SLSOrderWindow(g_connection, window->id, mode, bar->window.id); + } + previous_window = window; + } +} + void bar_draw(struct bar* bar) { SLSRemoveAllTrackingAreas(g_connection, bar->window.id); @@ -63,7 +83,9 @@ void bar_draw(struct bar* bar) { g_bar_manager.background.border_width, &g_bar_manager.background.border_color, true ); + bar->needs_update = false; + CGContextFlush(bar->window.context); } if (g_bar_manager.background.image.enabled) { @@ -107,6 +129,11 @@ void bar_draw(struct bar* bar) { 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, @@ -115,14 +142,13 @@ void bar_draw(struct bar* bar) { bar_item_draw(bar_item, window->context); CGContextFlush(window->context); - // SLSOrderWindow(g_connection, window->id, 1, bar->window.id); } if (bar_item->popup.drawing && bar->adid == g_bar_manager.active_adid) popup_draw(&bar_item->popup); } - CGContextFlush(bar->window.context); + bar_order_item_windows(bar, 1); } void bar_calculate_bounds(struct bar* bar) { @@ -153,7 +179,6 @@ void bar_calculate_bounds(struct bar* bar) { uint32_t* next_position = NULL; uint32_t y = bar->window.frame.size.height / 2; - struct window* previous_window = NULL; for (int i = 0; i < g_bar_manager.bar_item_count; i++) { struct bar_item* bar_item = g_bar_manager.bar_items[i]; @@ -186,43 +211,31 @@ void bar_calculate_bounds(struct bar* bar) { *next_position += bar_item->background.padding_left; } + uint32_t group_length = 0; + uint32_t group_offset = 0; + if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) { + group_length = group_get_length(bar_item->group); + group_offset = (bar_item->position == POSITION_RIGHT + || bar_item->position == POSITION_CENTER_LEFT) + ? group_length - bar_item_get_length(bar_item, false) + : 0; + } + bar_item->graph.rtl = rtl; uint32_t bar_item_length = bar_item_calculate_bounds(bar_item, bar->window.frame.size.height - (g_bar_manager.background.border_width + 1), - *next_position, + group_offset, y ); struct window* window = bar_item_get_window(bar_item, bar->adid); - window_set_level(window, g_bar_manager.window_level); - // SLSRemoveFromOrderingGroup(g_connection, window->id); - if (previous_window) { - SLSOrderWindow(g_connection, window->id, 1, previous_window->id); - SLSAddWindowToWindowOrderingGroup(g_connection, - previous_window->id, - window->id, - 1 ); - } - else { - SLSOrderWindow(g_connection, window->id, 1, bar->window.id); - SLSAddWindowToWindowOrderingGroup(g_connection, - bar->window.id, - window->id, - 1 ); - } - - uint32_t group_length = 0; - if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) { - group_length = group_get_length(bar_item->group); - } - - window_resize(window, (CGRect){{bar->window.origin.x + *next_position, - bar->window.origin.y }, - {bar_item_display_length - + group_length - + abs(bar_item->background.padding_left) - + abs(bar_item->background.padding_right), - bar->window.frame.size.height}}); + window->origin.x = bar->window.origin.x + *next_position - group_offset; + window->origin.y = bar->window.origin.y; + window->frame.size.width = bar_item_display_length + + group_length + + abs(bar_item->background.padding_left) + + abs(bar_item->background.padding_right); + window->frame.size.height = bar->window.frame.size.height; if (bar_item->popup.drawing) bar_calculate_popup_anchor_for_bar_item(bar, bar_item); @@ -241,7 +254,6 @@ void bar_calculate_bounds(struct bar* bar) { : (bar_item_length + bar_item->background.padding_right); } - previous_window = window; } } @@ -298,7 +310,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; + bar->needs_update = false; bar_create_window(bar); return bar; } diff --git a/src/bar_item.c b/src/bar_item.c index 4f7246a..7660dc1 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -216,6 +216,12 @@ bool bar_item_update(struct bar_item* bar_item, char* sender, bool forced, struc } void bar_item_needs_update(struct bar_item* bar_item) { + if (bar_item->group) { + struct bar_item* first_member = group_get_first_member(bar_item->group); + if (first_member && first_member != bar_item) + bar_item_needs_update(first_member); + } + bar_item->needs_update = true; } @@ -495,8 +501,7 @@ void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t } uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_height, uint32_t x, uint32_t y) { - x = 0; - uint32_t content_x = 0; + uint32_t content_x = x; uint32_t content_y = y; uint32_t bar_item_length = bar_item_get_length(bar_item, false); diff --git a/src/bar_manager.c b/src/bar_manager.c index 116dfc9..6bef5f0 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -414,7 +414,9 @@ void bar_manager_update(struct bar_manager* bar_manager, bool forced) { forced, NULL ); } + bar_manager_freeze(bar_manager); if (needs_refresh) bar_manager_refresh(bar_manager, false); + bar_manager_unfreeze(bar_manager); } void bar_manager_begin(struct bar_manager *bar_manager) { @@ -477,7 +479,9 @@ void bar_manager_display_changed(struct bar_manager* bar_manager) { bar_destroy(bar_manager->bars[i]); bar_manager_begin(bar_manager); + bar_manager_freeze(bar_manager); bar_manager_refresh(bar_manager, true); + bar_manager_unfreeze(bar_manager); } void bar_manager_handle_mouse_entered(struct bar_manager* bar_manager, struct bar_item* bar_item) { @@ -534,7 +538,9 @@ void bar_manager_handle_space_change(struct bar_manager* bar_manager) { &env_vars ); env_vars_destroy(&env_vars); + bar_manager_freeze(bar_manager); bar_manager_refresh(bar_manager, true); + bar_manager_unfreeze(bar_manager); } void bar_manager_handle_display_change(struct bar_manager* bar_manager) { @@ -558,7 +564,9 @@ void bar_manager_handle_system_woke(struct bar_manager* bar_manager) { COMMAND_SUBSCRIBE_SYSTEM_WOKE, NULL ); + bar_manager_freeze(bar_manager); bar_manager_refresh(bar_manager, true); + bar_manager_unfreeze(bar_manager); } void bar_manager_handle_notification(struct bar_manager* bar_manager, struct notification* notification) { diff --git a/src/group.c b/src/group.c index 8d08937..c150094 100644 --- a/src/group.c +++ b/src/group.c @@ -32,6 +32,11 @@ void group_add_member(struct group* group, struct bar_item* item) { } } +struct bar_item* group_get_first_member(struct group* group) { + if (group->num_members > 1) return group->members[1]; + return NULL; +} + bool group_is_first_member(struct group* group, struct bar_item* item) { if (!group_is_item_member(group, item)) return false; if (group->num_members > 1) {return group->members[1] == item; } diff --git a/src/group.h b/src/group.h index 27cee0b..1ff0e25 100644 --- a/src/group.h +++ b/src/group.h @@ -14,6 +14,7 @@ void group_add_member(struct group* group, struct bar_item* item); void group_remove_member(struct group* group, struct bar_item* bar_item); uint32_t group_get_length(struct group* group); bool group_is_first_member(struct group* group, struct bar_item* item); +struct bar_item* group_get_first_member(struct group* group); uint32_t group_count_members_drawn(struct group* group); void group_calculate_bounds(struct group* group, uint32_t x, uint32_t y, bool rtl); diff --git a/src/message.c b/src/message.c index 84871f5..cf164e1 100644 --- a/src/message.c +++ b/src/message.c @@ -462,7 +462,9 @@ 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); bar_manager_refresh(&g_bar_manager, false); + bar_manager_unfreeze(&g_bar_manager); } void handle_message_mach(struct mach_buffer* buffer) { diff --git a/src/window.c b/src/window.c index a2d4507..5449d60 100644 --- a/src/window.c +++ b/src/window.c @@ -1,5 +1,6 @@ #include "window.h" #include "alias.h" +#include "bar_manager.h" static CFTypeRef window_create_region(struct window *window, CGRect frame) { window->frame = (CGRect) {{0, 0},{frame.size.width, frame.size.height}}; @@ -69,14 +70,13 @@ void window_resize(struct window* window, CGRect frame) { CFTypeRef frame_region = window_create_region(window, frame); SLSSetWindowShape(g_connection, window->id, - 0, - 0, + window->origin.x, + window->origin.y, frame_region ); - SLSMoveWindow(g_connection, window->id, &window->origin); - SLSClearActivationRegion(g_connection, window->id); - SLSAddActivationRegion(g_connection, window->id, frame_region); - SLSRemoveAllTrackingAreas(g_connection, window->id); + // SLSClearActivationRegion(g_connection, window->id); + // SLSAddActivationRegion(g_connection, window->id, frame_region); + // SLSRemoveAllTrackingAreas(g_connection, window->id); CFRelease(frame_region); } From 2e3aac4c3e904613a4b8828ad10249e8e42c951d Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sun, 5 Jun 2022 21:18:50 +0200 Subject: [PATCH 08/27] fix performance --- src/animation.c | 23 +++++++++++++++++++++-- src/animation.h | 2 ++ src/bar.c | 34 ++++++++++++++-------------------- src/bar.h | 1 + src/bar_manager.c | 18 +++++++++++++++--- src/bar_manager.h | 1 + src/message.c | 1 + 7 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/animation.c b/src/animation.c index 2507078..77c1ffa 100644 --- a/src/animation.c +++ b/src/animation.c @@ -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; diff --git a/src/animation.h b/src/animation.h index 37a63c9..ef54137 100644 --- a/src/animation.h +++ b/src/animation.h @@ -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; diff --git a/src/bar.c b/src/bar.c index 9136f60..a42f22f 100644 --- a/src/bar.c +++ b/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) { diff --git a/src/bar.h b/src/bar.h index 8f4d571..5088ebf 100644 --- a/src/bar.h +++ b/src/bar.h @@ -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); diff --git a/src/bar_manager.c b/src/bar_manager.c index 6bef5f0..cfc2eea 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -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); } diff --git a/src/bar_manager.h b/src/bar_manager.h index fa751ff..57aff16 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -16,6 +16,7 @@ struct bar_manager { bool picky_redraw; bool font_smoothing; bool any_bar_hidden; + bool needs_ordering; char display; char position; diff --git a/src/message.c b/src/message.c index cf164e1..5ba4da4 100644 --- a/src/message.c +++ b/src/message.c @@ -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); } From f9b2395e20aabb70b19891acbcd3af029dbd3ebb Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Sun, 5 Jun 2022 22:17:15 +0200 Subject: [PATCH 09/27] clicks still not working --- src/bar.c | 13 ++++++------- src/bar_manager.c | 4 ++++ src/event.c | 11 ++++++----- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/bar.c b/src/bar.c index a42f22f..9b6c3a0 100644 --- a/src/bar.c +++ b/src/bar.c @@ -73,7 +73,7 @@ void bar_order_item_windows(struct bar* bar, int mode) { } void bar_draw(struct bar* bar) { - SLSRemoveAllTrackingAreas(g_connection, bar->window.id); + // SLSRemoveAllTrackingAreas(g_connection, bar->window.id); if (bar->needs_update) { draw_rect(bar->window.context, @@ -113,12 +113,11 @@ void bar_draw(struct bar* bar) { if (bar_item->update_mask & UPDATE_MOUSE_ENTERED || bar_item->update_mask & UPDATE_MOUSE_EXITED) { - CGRect tracking_rect = cgrect_mirror_y(bar_item_construct_bounding_rect( - bar_item), - bar->window.frame.size.height / 2.); + CGRect tracking_rect = window->frame; - tracking_rect.origin.y -= tracking_rect.size.height; - SLSAddTrackingRect(g_connection, bar->window.id, tracking_rect); + // tracking_rect.origin.y -= tracking_rect.size.height; + SLSRemoveAllTrackingAreas(g_connection, window->id); + SLSAddTrackingRect(g_connection, window->id, tracking_rect); } bar_item_set_bounding_rect_for_display(bar_item, @@ -304,7 +303,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 = false; + bar->needs_update = true; bar_create_window(bar); return bar; } diff --git a/src/bar_manager.c b/src/bar_manager.c index cfc2eea..05b483c 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -80,6 +80,7 @@ void bar_manager_sort(struct bar_manager* bar_manager, struct bar_item** orderin } } } + bar_manager->needs_ordering = true; } int bar_manager_get_item_index_for_name(struct bar_manager* bar_manager, char* name) { @@ -124,6 +125,8 @@ void bar_manager_move_item(struct bar_manager* bar_manager, struct bar_item* ite memcpy(bar_manager->bar_items, tmp, sizeof(struct bar_item*)*bar_manager->bar_item_count); + + bar_manager->needs_ordering = true; } void bar_manager_remove_item(struct bar_manager* bar_manager, struct bar_item* bar_item) { @@ -490,6 +493,7 @@ void bar_manager_display_changed(struct bar_manager* bar_manager) { bar_manager_begin(bar_manager); bar_manager_freeze(bar_manager); + bar_manager->frozen = false; bar_manager_refresh(bar_manager, true); bar_manager_unfreeze(bar_manager); } diff --git a/src/event.c b/src/event.c index 2c3acd1..96aa2a2 100644 --- a/src/event.c +++ b/src/event.c @@ -117,7 +117,7 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) { CGEventType type = CGEventGetType(context); uint32_t modifier_keys = CGEventGetFlags(context); uint32_t adid = display_arrangement(display_active_display_id()); - debug("EVENT_HANDLER_MOUSE_UP: D#%d (x: %.0f, y: %.0f) -> ", + printf("EVENT_HANDLER_MOUSE_UP: D#%d (x: %.0f, y: %.0f) -> ", adid, point.x, point.y ); @@ -125,7 +125,7 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) { point, adid ); - debug("item: %s\n", bar_item ? bar_item->name : "NULL"); + printf("item: %s\n", bar_item ? bar_item->name : "NULL"); bar_item_on_click(bar_item, type, modifier_keys); CFRelease(context); return EVENT_SUCCESS; @@ -135,7 +135,8 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED) { debug("%s\n", __FUNCTION__); CGPoint point = CGEventGetLocation(context); uint32_t adid = display_arrangement(display_active_display_id()); - debug("EVENT_HANDLER_MOUSE_ENTERED: D#%d (x: %.0f, y: %.0f) -> ", + + printf("EVENT_HANDLER_MOUSE_ENTERED: D#%d (x: %.0f, y: %.0f) -> ", adid, point.x, point.y ); @@ -143,7 +144,7 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED) { point, adid ); - debug("item: %s\n", bar_item ? bar_item->name : "NULL"); + printf("item: %s\n", bar_item ? bar_item->name : "NULL"); bar_manager_handle_mouse_entered(&g_bar_manager, bar_item); CFRelease(context); return EVENT_SUCCESS; @@ -151,7 +152,7 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED) { EVENT_CALLBACK(EVENT_HANDLER_MOUSE_EXITED) { debug("%s\n", __FUNCTION__); - debug("EVENT_HANDLER_MOUSE_EXITED \n"); + printf("EVENT_HANDLER_MOUSE_EXITED \n"); bar_manager_handle_mouse_exited(&g_bar_manager); CFRelease(context); return EVENT_SUCCESS; From 721770373fdf6bd6d6432b081b845f24511d3413 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Mon, 6 Jun 2022 10:14:10 +0200 Subject: [PATCH 10/27] restructuring --- src/alias.h | 4 +--- src/bar.c | 2 -- src/window.c | 29 ++++++++++++++--------------- src/window.h | 3 +++ 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/alias.h b/src/alias.h index 478a5e0..706617b 100644 --- a/src/alias.h +++ b/src/alias.h @@ -1,13 +1,11 @@ #pragma once #include #include "misc/helpers.h" +#include "window.h" #include "image.h" #define MENUBAR_LAYER 0x19 -extern void SLSCaptureWindowsContentsToRectWithOptions(uint32_t cid, uint64_t* wid, bool meh, CGRect bounds, uint32_t flags, CGImageRef* image); -extern int SLSGetScreenRectForWindow(uint32_t cid, uint32_t wid, CGRect* out); - struct alias { bool permission; diff --git a/src/bar.c b/src/bar.c index 9b6c3a0..b274d17 100644 --- a/src/bar.c +++ b/src/bar.c @@ -73,8 +73,6 @@ void bar_order_item_windows(struct bar* bar, int mode) { } void bar_draw(struct bar* bar) { - // SLSRemoveAllTrackingAreas(g_connection, bar->window.id); - if (bar->needs_update) { draw_rect(bar->window.context, bar->window.frame, diff --git a/src/window.c b/src/window.c index 5449d60..9ece6db 100644 --- a/src/window.c +++ b/src/window.c @@ -1,6 +1,4 @@ #include "window.h" -#include "alias.h" -#include "bar_manager.h" static CFTypeRef window_create_region(struct window *window, CGRect frame) { window->frame = (CGRect) {{0, 0},{frame.size.width, frame.size.height}}; @@ -28,18 +26,19 @@ void window_create(struct window* window, CGRect frame) { SLSClearWindowTags(g_connection, window->id, &clear_tags, 64); SLSSetWindowOpacity(g_connection, window->id, 0); - // const void* keys[] = { CFSTR("CGWindowContextShouldUseCA") }; - // const void* values[] = { kCFBooleanTrue }; - // CFDictionaryRef dict = CFDictionaryCreate(NULL, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - // CGContextRef context = SLWindowContextCreate(g_connection, window->id, dict); - window->context = SLWindowContextCreate(g_connection, window->id, 0); - // CFRelease(dict); + const void* keys[] = { CFSTR("CGWindowContextShouldUseCA") }; + const void* values[] = { kCFBooleanTrue }; + CFDictionaryRef dict = CFDictionaryCreate(NULL, + keys, + values, + 1, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + + window->context = SLWindowContextCreate(g_connection, window->id, dict); + CFRelease(dict); CGContextSetInterpolationQuality(window->context, kCGInterpolationNone); - // CGLayerRef layer = CGLayerCreateWithContext(context, window->frame.size, 0); - - // window->context = CGLayerGetContext(layer); - // SLSAddSurface(g_connection, window->id, &window->surface_id); // SLSSetSurfaceBounds(g_connection, window->id, window->surface_id, window->frame); @@ -74,9 +73,9 @@ void window_resize(struct window* window, CGRect frame) { window->origin.y, frame_region ); - // SLSClearActivationRegion(g_connection, window->id); - // SLSAddActivationRegion(g_connection, window->id, frame_region); - // SLSRemoveAllTrackingAreas(g_connection, window->id); + SLSClearActivationRegion(g_connection, window->id); + SLSAddActivationRegion(g_connection, window->id, frame_region); + SLSRemoveAllTrackingAreas(g_connection, window->id); CFRelease(frame_region); } diff --git a/src/window.h b/src/window.h index 6f8e597..d2062e7 100644 --- a/src/window.h +++ b/src/window.h @@ -25,6 +25,9 @@ extern CGError SLSAddWindowToWindowOrderingGroup(int cid, uint32_t parent_wid, u extern CGError SLSRemoveFromOrderingGroup(int cid, uint32_t wid); extern int SLSSpaceGetType(int cid, uint64_t sid); +extern void SLSCaptureWindowsContentsToRectWithOptions(uint32_t cid, uint64_t* wid, bool meh, CGRect bounds, uint32_t flags, CGImageRef* image); +extern int SLSGetScreenRectForWindow(uint32_t cid, uint32_t wid, CGRect* out); + extern CGError SLSAddSurface(int cid, uint32_t wid, uint32_t* outSID); extern CGError SLSRemoveSurface(int cid, uint32_t wid, uint32_t sid); extern CGError SLSBindSurface(int cid, uint32_t wid, uint32_t sid, int x, int y, CGContextRef ctx); From cbacd0d5e265b75f9fda96cd9bfdac5012001890 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Mon, 6 Jun 2022 10:19:52 +0200 Subject: [PATCH 11/27] properly add subwindows to window ordering groups --- src/bar.c | 18 +++++++++++++----- src/window.c | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bar.c b/src/bar.c index b274d17..3ae2483 100644 --- a/src/bar.c +++ b/src/bar.c @@ -64,9 +64,17 @@ void bar_order_item_windows(struct bar* bar, int mode) { if (previous_window) { SLSOrderWindow(g_connection, window->id, mode, previous_window->id); + SLSAddWindowToWindowOrderingGroup(g_connection, + previous_window->id, + window->id, + 1 ); } else { SLSOrderWindow(g_connection, window->id, mode, bar->window.id); + SLSAddWindowToWindowOrderingGroup(g_connection, + bar->window.id, + window->id, + 1 ); } previous_window = window; } @@ -111,11 +119,11 @@ void bar_draw(struct bar* bar) { if (bar_item->update_mask & UPDATE_MOUSE_ENTERED || bar_item->update_mask & UPDATE_MOUSE_EXITED) { - CGRect tracking_rect = window->frame; - - // tracking_rect.origin.y -= tracking_rect.size.height; - SLSRemoveAllTrackingAreas(g_connection, window->id); - SLSAddTrackingRect(g_connection, window->id, tracking_rect); + // CGRect tracking_rect = window->frame; + // tracking_rect.origin = window->origin; + // + // SLSRemoveAllTrackingAreas(g_connection, window->id); + // SLSAddTrackingRect(g_connection, window->id, tracking_rect); } bar_item_set_bounding_rect_for_display(bar_item, diff --git a/src/window.c b/src/window.c index 9ece6db..4a9101e 100644 --- a/src/window.c +++ b/src/window.c @@ -44,7 +44,6 @@ void window_create(struct window* window, CGRect frame) { // SLSSetSurfaceBounds(g_connection, window->id, window->surface_id, window->frame); // SLSBindSurface(g_connection, window->id, window->surface_id, 0, 0, window->context); // SLSOrderSurface(g_connection, window->id, window->surface_id, 0, 1); - } void windows_freeze() { From c64e242419a4e10f66fbdf2b2c100ee854dda68b Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Mon, 6 Jun 2022 10:21:11 +0200 Subject: [PATCH 12/27] properly remove subwindows from window ordering groups --- src/bar.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bar.c b/src/bar.c index 3ae2483..82ab4df 100644 --- a/src/bar.c +++ b/src/bar.c @@ -60,6 +60,7 @@ void bar_order_item_windows(struct bar* bar, int mode) { if (!bar_draws_item(bar, bar_item)) continue; struct window* window = bar_item_get_window(bar_item, bar->adid); + SLSRemoveFromOrderingGroup(g_connection, window->id); window_set_level(window, g_bar_manager.window_level); if (previous_window) { From 09d8f6b05434f647496904f2e2e1bd06eb73dfec Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Mon, 6 Jun 2022 11:43:54 +0200 Subject: [PATCH 13/27] remove bounding rects, fix popup anchor, groups need fixing --- src/bar.c | 73 ++++++++++++++++++++++++---------------------- src/bar_item.c | 67 +++++------------------------------------- src/bar_item.h | 6 ---- src/bar_manager.c | 9 ++++-- src/event.c | 1 + src/group.c | 9 +++--- src/misc/helpers.h | 1 + src/popup.c | 8 ++--- 8 files changed, 63 insertions(+), 111 deletions(-) diff --git a/src/bar.c b/src/bar.c index 82ab4df..756e474 100644 --- a/src/bar.c +++ b/src/bar.c @@ -28,27 +28,24 @@ bool bar_draws_item(struct bar* bar, struct bar_item* bar_item) { void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* bar_item) { if (bar->adid != g_bar_manager.active_adid) return; + struct window* window = bar_item_get_window(bar_item, bar->adid); if (!bar_item->popup.overrides_cell_size) - bar_item->popup.cell_size = bar->window.frame.size.height; + bar_item->popup.cell_size = window->frame.size.height; popup_calculate_bounds(&bar_item->popup); - CGPoint anchor = bar->window.origin; + CGPoint anchor = window->origin; if (bar_item->popup.align == POSITION_CENTER) { - anchor.x += bar_item->icon.bounds.origin.x - + bar_item->background.padding_left / 2 - + (bar_item_get_length(bar_item, false) - - bar_item->popup.background.bounds.size.width) / 2; + anchor.x += (window->frame.size.width + - bar_item->popup.background.bounds.size.width) / 2; } else if (bar_item->popup.align == POSITION_LEFT) { - anchor.x += bar_item->icon.bounds.origin.x - - bar_item->background.padding_left; + anchor.x -= bar_item->background.padding_left; } else { - anchor.x += bar_item->icon.bounds.origin.x - + bar_item_get_length(bar_item, false) + anchor.x += window->frame.size.width - bar_item->popup.background.bounds.size.width; } anchor.y += (g_bar_manager.position == POSITION_BOTTOM - ? (-bar->window.frame.size.height + ? (-window->frame.size.height - bar_item->popup.background.bounds.size.height) - : bar->window.frame.size.height); + : window->frame.size.height); popup_set_anchor(&bar_item->popup, anchor, bar->adid); } @@ -109,13 +106,13 @@ void bar_draw(struct bar* bar) { bar_item_remove_associated_bar(bar_item, bar->adid); if (!bar_draws_item(bar, bar_item)) { - CGPoint nirvana = {-9999, -9999}; - SLSMoveWindow(g_connection, window->id, &nirvana); + SLSMoveWindow(g_connection, window->id, &g_nirvana); continue; } bar_item_append_associated_bar(bar_item, bar->adid); + SLSMoveWindow(g_connection, window->id, &window->origin); if (!bar_item->needs_update) continue; if (bar_item->update_mask & UPDATE_MOUSE_ENTERED @@ -127,11 +124,6 @@ void bar_draw(struct bar* bar) { // SLSAddTrackingRect(g_connection, window->id, tracking_rect); } - bar_item_set_bounding_rect_for_display(bar_item, - bar->adid, - bar->window.origin, - bar->window.frame.size.height); - window_resize(window, (CGRect){{window->origin.x, window->origin.y }, {window->frame.size.width, @@ -143,6 +135,12 @@ void bar_draw(struct bar* bar) { &g_transparent, true ); + if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) { + group_draw(bar_item->group, + bar_item_get_window(bar_item->group->members[0], + bar->adid )->context); + } + bar_item_draw(bar_item, window->context); CGContextFlush(window->context); @@ -211,32 +209,37 @@ void bar_calculate_bounds(struct bar* bar) { *next_position += bar_item->background.padding_left; } - uint32_t group_length = 0; - uint32_t group_offset = 0; - if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) { - group_length = group_get_length(bar_item->group); - group_offset = (bar_item->position == POSITION_RIGHT - || bar_item->position == POSITION_CENTER_LEFT) - ? group_length - bar_item_get_length(bar_item, false) - : 0; - } - bar_item->graph.rtl = rtl; uint32_t bar_item_length = bar_item_calculate_bounds(bar_item, bar->window.frame.size.height - (g_bar_manager.background.border_width + 1), - group_offset, + 0, y ); struct window* window = bar_item_get_window(bar_item, bar->adid); - window->origin.x = bar->window.origin.x + *next_position - group_offset; + window->origin.x = bar->window.origin.x + *next_position; window->origin.y = bar->window.origin.y; - window->frame.size.width = bar_item_display_length - + group_length - + abs(bar_item->background.padding_left) - + abs(bar_item->background.padding_right); + window->frame.size.width = bar_item_display_length; window->frame.size.height = bar->window.frame.size.height; + // if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) { + // uint32_t group_length = group_get_length(bar_item->group); + // uint32_t group_offset = (bar_item->position == POSITION_RIGHT + // || bar_item->position == POSITION_CENTER_LEFT) + // ? group_length + // - bar_item_get_length(bar_item, false) + // : 0; + // + // struct window* group_window = bar_item_get_window( + // bar_item->group->members[0], + // bar->adid ); + // + // group_window->origin = window->origin; + // group_window->origin.x -= group_offset; + // group_window->frame.size = window->frame.size; + // group_window->frame.size.width = group_length; + // } + if (bar_item->popup.drawing) bar_calculate_popup_anchor_for_bar_item(bar, bar_item); diff --git a/src/bar_item.c b/src/bar_item.c index 7660dc1..45935db 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -11,9 +11,7 @@ void bar_item_clear_pointers(struct bar_item* bar_item) { bar_item->name = NULL; bar_item->script = NULL; bar_item->click_script = NULL; - bar_item->bounding_rects = NULL; bar_item->group = NULL; - bar_item->num_rects = 0; bar_item->signal_args.env_vars.vars = NULL; bar_item->signal_args.env_vars.count = 0; bar_item->windows = NULL; @@ -95,8 +93,6 @@ void bar_item_init(struct bar_item* bar_item, struct bar_item* default_item) { bar_item->custom_width = 0; bar_item->y_offset = 0; - bar_item->num_rects = 0; - bar_item->bounding_rects = NULL; bar_item->group = NULL; @@ -155,13 +151,10 @@ void bar_item_append_associated_bar(struct bar_item* bar_item, uint32_t adid) { void bar_item_remove_associated_bar(struct bar_item* bar_item, uint32_t adid) { bar_item->associated_bar &= ~(1 << (adid - 1)); - bar_item_remove_bounding_rect(bar_item, adid); } void bar_item_reset_associated_bar(struct bar_item* bar_item) { bar_item->associated_bar = 0; - for (uint32_t adid = 1; adid <= bar_item->num_rects; adid++) - bar_item_remove_bounding_rect(bar_item, adid); } bool bar_item_update(struct bar_item* bar_item, char* sender, bool forced, struct env_vars* env_vars) { @@ -449,13 +442,6 @@ void bar_item_remove_window(struct bar_item* bar_item, uint32_t adid) { } } -void bar_item_remove_bounding_rect(struct bar_item* bar_item, uint32_t adid) { - if (bar_item->num_rects >= adid && bar_item->bounding_rects[adid - 1]) { - free(bar_item->bounding_rects[adid - 1]); - bar_item->bounding_rects[adid - 1] = NULL; - } -} - CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) { CGRect bounding_rect; bounding_rect.origin = bar_item->icon.bounds.origin; @@ -475,31 +461,6 @@ CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) { return bounding_rect; } -void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid, CGPoint bar_origin, uint32_t height) { - if (adid <= 0) return; - if (bar_item->num_rects < adid) { - bar_item->bounding_rects = (CGRect**) realloc(bar_item->bounding_rects, - sizeof(CGRect*) * adid ); - memset(bar_item->bounding_rects + bar_item->num_rects, - 0, - sizeof(CGRect*) * (adid - bar_item->num_rects) ); - - bar_item->num_rects = adid; - } - if (!bar_item->bounding_rects[adid - 1]) { - bar_item->bounding_rects[adid - 1] = malloc(sizeof(CGRect)); - memset(bar_item->bounding_rects[adid - 1], 0, sizeof(CGRect)); - } - CGRect rect = CGRectInset(bar_item_construct_bounding_rect(bar_item), -1,-1); - bar_item->bounding_rects[adid - 1]->origin.x = rect.origin.x + bar_origin.x; - bar_item->bounding_rects[adid - 1]->origin.y = -rect.origin.y - - rect.size.height - + bar_origin.y - + height; - - bar_item->bounding_rects[adid - 1]->size = rect.size; -} - uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_height, uint32_t x, uint32_t y) { uint32_t content_x = x; uint32_t content_y = y; @@ -528,9 +489,8 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh group_calculate_bounds(bar_item->group, (bar_item->position == POSITION_RIGHT || bar_item->position == POSITION_CENTER_LEFT) - ? (icon_position - - group_get_length(bar_item->group) - + bar_item_length ) + ? (x - group_get_length(bar_item->group) + + bar_item_length ) : icon_position, content_y, bar_item->position == POSITION_RIGHT @@ -575,9 +535,6 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh } void bar_item_draw(struct bar_item* bar_item, CGContextRef context) { - if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) - group_draw(bar_item->group, context); - background_draw(&bar_item->background, context); text_draw(&bar_item->icon, context); text_draw(&bar_item->label, context); @@ -596,14 +553,6 @@ void bar_item_destroy(struct bar_item* bar_item) { text_destroy(&bar_item->icon); text_destroy(&bar_item->label); - if (bar_item->bounding_rects) { - for (int adid = 1; adid <= bar_item->num_rects; adid++) { - bar_item_remove_bounding_rect(bar_item, adid); - } - free(bar_item->bounding_rects); - } - if (bar_item->bounding_rects) free(bar_item->bounding_rects); - if (bar_item->has_graph) { graph_destroy(&bar_item->graph); } @@ -704,17 +653,17 @@ void bar_item_serialize(struct bar_item* bar_item, FILE* rsp) { bar_item->update_mask); int counter = 0; - for (int i = 0; i < bar_item->num_rects; i++) { - if (!bar_item->bounding_rects[i]) continue; + for (int i = 0; i < bar_item->num_windows; i++) { + if (!bar_item->windows[i]) continue; if (counter++ > 0) fprintf(rsp, ",\n"); fprintf(rsp, "\t\t\"display-%d\": {\n" "\t\t\t\"origin\": [ %f, %f ],\n" "\t\t\t\"size\": [ %f, %f ]\n\t\t}", i + 1, - bar_item->bounding_rects[i]->origin.x, - bar_item->bounding_rects[i]->origin.y, - bar_item->bounding_rects[i]->size.width, - bar_item->bounding_rects[i]->size.height); + bar_item->windows[i]->origin.x, + bar_item->windows[i]->origin.y, + bar_item->windows[i]->frame.size.width, + bar_item->windows[i]->frame.size.height); } fprintf(rsp, "\n\t}"); diff --git a/src/bar_item.h b/src/bar_item.h index 7e18b37..bd9e328 100644 --- a/src/bar_item.h +++ b/src/bar_item.h @@ -66,10 +66,6 @@ struct bar_item { // Update Events uint64_t update_mask; - // Bounding Boxes for click events and background drawing (individual per display) - uint32_t num_rects; - CGRect** bounding_rects; - // Windows uint32_t num_windows; struct window** windows; @@ -111,9 +107,7 @@ void bar_item_mouse_entered(struct bar_item* bar_item); void bar_item_mouse_exited(struct bar_item* bar_item); struct window* bar_item_get_window(struct bar_item* bar_item, uint32_t adid); -void bar_item_remove_bounding_rect(struct bar_item* bar_item, uint32_t adid); CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item); -void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid, CGPoint bar_origin, uint32_t height); uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_height, uint32_t x, uint32_t y); void bar_item_draw(struct bar_item* bar_item, CGContextRef context); diff --git a/src/bar_manager.c b/src/bar_manager.c index 05b483c..c8ec748 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -462,12 +462,15 @@ void bar_manager_begin(struct bar_manager *bar_manager) { struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t adid) { for (int i = 0; i < bar_manager->bar_item_count; i++) { struct bar_item* bar_item = bar_manager->bar_items[i]; - if (!bar_item->drawing || bar_item->num_rects < adid - || bar_item->bounding_rects[adid - 1] == NULL) { + if (!bar_item->drawing || bar_item->num_windows < adid + || bar_item->windows[adid - 1] == NULL) { continue; } - if (cgrect_contains_point(bar_item->bounding_rects[adid - 1], &point)) { + struct window* window = bar_item_get_window(bar_item, adid); + CGRect frame = window->frame; + frame.origin = window->origin; + if (cgrect_contains_point(&frame, &point)) { return bar_item; } } diff --git a/src/event.c b/src/event.c index 96aa2a2..ffd1013 100644 --- a/src/event.c +++ b/src/event.c @@ -117,6 +117,7 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) { CGEventType type = CGEventGetType(context); uint32_t modifier_keys = CGEventGetFlags(context); uint32_t adid = display_arrangement(display_active_display_id()); + printf("EVENT_HANDLER_MOUSE_UP: D#%d (x: %.0f, y: %.0f) -> ", adid, point.x, diff --git a/src/group.c b/src/group.c index c150094..844f638 100644 --- a/src/group.c +++ b/src/group.c @@ -64,7 +64,7 @@ uint32_t group_get_length(struct group* group) { length += bar_item_get_length(group->members[i], false); } } - return length; + return length + group_count_members_drawn(group); } uint32_t group_count_members_drawn(struct group* group) { @@ -101,9 +101,10 @@ void group_destroy(struct group* group) { void group_calculate_bounds(struct group* group, uint32_t x, uint32_t y, bool rtl) { background_calculate_bounds(&group->members[0]->background, x, y); group->members[0]->background.bounds.size.width = group_get_length(group) - + (rtl - ? 0 - : group_count_members_drawn(group)); + - (rtl + ? group_count_members_drawn(group) + : 0 ); + group->members[0]->background.bounds.origin.x = x; group->members[0]->background.bounds.origin.y = y - group->members[0]->background.bounds.size.height / 2 + group->members[0]->y_offset; diff --git a/src/misc/helpers.h b/src/misc/helpers.h index f187107..ac95559 100644 --- a/src/misc/helpers.h +++ b/src/misc/helpers.h @@ -28,6 +28,7 @@ struct rgba_color { }; static struct rgba_color g_transparent = { 0 }; +static CGPoint g_nirvana = {-9999, -9999}; struct token { char *text; diff --git a/src/popup.c b/src/popup.c index f14031c..db6c439 100644 --- a/src/popup.c +++ b/src/popup.c @@ -197,10 +197,10 @@ void popup_draw(struct popup* popup) { SLSAddTrackingRect(g_connection, popup->window.id, tracking_rect); } - bar_item_set_bounding_rect_for_display(bar_item, - popup->adid, - popup->anchor, - popup->background.bounds.size.height); + // bar_item_set_bounding_rect_for_display(bar_item, + // popup->adid, + // popup->anchor, + // popup->background.bounds.size.height); bool state = bar_item->popup.drawing; bar_item->popup.drawing = false; From e139f31898717f98714ccc9a3e8660637cb55866 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Mon, 6 Jun 2022 12:22:07 +0200 Subject: [PATCH 14/27] fix up popup logic --- src/bar.c | 13 +++++++++++-- src/group.c | 17 ++++++++++------- src/popup.c | 10 +++++++++- src/popup.h | 1 + 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/bar.c b/src/bar.c index 756e474..12745ee 100644 --- a/src/bar.c +++ b/src/bar.c @@ -31,7 +31,10 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b struct window* window = bar_item_get_window(bar_item, bar->adid); if (!bar_item->popup.overrides_cell_size) bar_item->popup.cell_size = window->frame.size.height; + + bool needs_recalculation = bar_item->popup.adid != bar->adid; popup_calculate_bounds(&bar_item->popup); + CGPoint anchor = window->origin; if (bar_item->popup.align == POSITION_CENTER) { anchor.x += (window->frame.size.width @@ -46,7 +49,11 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b ? (-window->frame.size.height - bar_item->popup.background.bounds.size.height) : window->frame.size.height); + popup_set_anchor(&bar_item->popup, anchor, bar->adid); + if (needs_recalculation) { + popup_calculate_bounds(&bar_item->popup); + } } void bar_order_item_windows(struct bar* bar, int mode) { @@ -113,6 +120,10 @@ void bar_draw(struct bar* bar) { bar_item_append_associated_bar(bar_item, bar->adid); SLSMoveWindow(g_connection, window->id, &window->origin); + + if (bar_item->popup.drawing && bar->adid == g_bar_manager.active_adid) + popup_draw(&bar_item->popup); + if (!bar_item->needs_update) continue; if (bar_item->update_mask & UPDATE_MOUSE_ENTERED @@ -144,8 +155,6 @@ void bar_draw(struct bar* bar) { 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); } } diff --git a/src/group.c b/src/group.c index 844f638..981c526 100644 --- a/src/group.c +++ b/src/group.c @@ -26,7 +26,8 @@ void group_add_member(struct group* group, struct bar_item* item) { } } else { group->num_members++; - group->members = realloc(group->members, sizeof(struct bar_item*)*group->num_members); + group->members = realloc(group->members, + sizeof(struct bar_item*)*group->num_members); group->members[group->num_members - 1] = item; item->group = group; } @@ -86,7 +87,8 @@ void group_remove_member(struct group* group, struct bar_item* bar_item) { tmp[count++] = group->members[i]; } group->num_members--; - group->members = realloc(group->members, sizeof(struct bar_item*)*group->num_members); + group->members = realloc(group->members, + sizeof(struct bar_item*)*group->num_members); memcpy(group->members, tmp, sizeof(struct bar_item*)*group->num_members); } @@ -101,13 +103,14 @@ void group_destroy(struct group* group) { void group_calculate_bounds(struct group* group, uint32_t x, uint32_t y, bool rtl) { background_calculate_bounds(&group->members[0]->background, x, y); group->members[0]->background.bounds.size.width = group_get_length(group) - - (rtl - ? group_count_members_drawn(group) - : 0 ); + - (rtl + ? group_count_members_drawn(group) + : 0 ); group->members[0]->background.bounds.origin.x = x; - group->members[0]->background.bounds.origin.y = y - group->members[0]->background.bounds.size.height / 2 - + group->members[0]->y_offset; + group->members[0]->background.bounds.origin.y = y + - group->members[0]->background.bounds.size.height / 2 + + group->members[0]->y_offset; } void group_draw(struct group* group, CGContextRef context) { diff --git a/src/popup.c b/src/popup.c index db6c439..24d452b 100644 --- a/src/popup.c +++ b/src/popup.c @@ -77,6 +77,14 @@ void popup_calculate_bounds(struct popup* popup) { ? height : cell_height) / 2); + if (popup->adid > 0) { + struct window* window = bar_item_get_window(bar_item, popup->adid); + window->origin.x = x + popup->anchor.x; + window->origin.y = y + popup->anchor.y; + window->frame.size.height = popup->horizontal ? height : cell_height; + window->frame.size.width = item_width; + } + if (item_width > width && !popup->horizontal) width = item_width; if (popup->horizontal) x += item_width; else y += cell_height; @@ -171,7 +179,7 @@ void popup_set_drawing(struct popup* popup, bool drawing) { } void popup_draw(struct popup* popup) { - if (!popup->drawing) return; + if (!popup->drawing || popup->adid <= 0) return; SLSOrderWindow(g_connection, popup->window.id, -1, 0); window_resize(&popup->window, (CGRect){{popup->anchor.x, popup->anchor.y}, diff --git a/src/popup.h b/src/popup.h index 07d9b27..ca396e8 100644 --- a/src/popup.h +++ b/src/popup.h @@ -32,6 +32,7 @@ void popup_add_item(struct popup* popup, struct bar_item* item); void popup_set_drawing(struct popup* popup, bool drawing); void popup_remove_item(struct popup* popup, struct bar_item* bar_item); +uint32_t popup_get_width(struct popup* popup); void popup_calculate_bounds(struct popup* popup); void popup_draw(struct popup* popup); void popup_destroy(struct popup* popup); From af5f11d06a1e3d48b0cdd802a485bfe53bf83a6a Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Mon, 6 Jun 2022 12:51:08 +0200 Subject: [PATCH 15/27] fix mirrored bounding rects for popups --- src/bar_item.c | 8 ++++++++ src/bar_item.h | 1 + src/popup.c | 9 ++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/bar_item.c b/src/bar_item.c index 45935db..381e60e 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -461,6 +461,14 @@ CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) { return bounding_rect; } +void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid, CGPoint bar_origin, uint32_t height) { + if (adid <= 0) return; + CGRect rect = CGRectInset(bar_item_construct_bounding_rect(bar_item), -1,-1); + struct window* window = bar_item_get_window(bar_item, adid); + window->origin.x = rect.origin.x + bar_origin.x; + window->origin.y = -rect.origin.y - rect.size.height + bar_origin.y + height; + window->frame.size = rect.size; +} uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_height, uint32_t x, uint32_t y) { uint32_t content_x = x; uint32_t content_y = y; diff --git a/src/bar_item.h b/src/bar_item.h index bd9e328..04f6cfd 100644 --- a/src/bar_item.h +++ b/src/bar_item.h @@ -108,6 +108,7 @@ void bar_item_mouse_exited(struct bar_item* bar_item); struct window* bar_item_get_window(struct bar_item* bar_item, uint32_t adid); CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item); +void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid, CGPoint bar_origin, uint32_t height); uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_height, uint32_t x, uint32_t y); void bar_item_draw(struct bar_item* bar_item, CGContextRef context); diff --git a/src/popup.c b/src/popup.c index 24d452b..7e074e4 100644 --- a/src/popup.c +++ b/src/popup.c @@ -78,11 +78,10 @@ void popup_calculate_bounds(struct popup* popup) { : cell_height) / 2); if (popup->adid > 0) { - struct window* window = bar_item_get_window(bar_item, popup->adid); - window->origin.x = x + popup->anchor.x; - window->origin.y = y + popup->anchor.y; - window->frame.size.height = popup->horizontal ? height : cell_height; - window->frame.size.width = item_width; + bar_item_set_bounding_rect_for_display(bar_item, + popup->adid, + popup->anchor, + popup->background.bounds.size.height); } if (item_width > width && !popup->horizontal) width = item_width; From 8eb65c844ad528073a134f629e12f08ec65b21ad Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Tue, 7 Jun 2022 08:41:01 +0200 Subject: [PATCH 16/27] fix flickering on startup --- src/bar.c | 2 ++ src/sketchybar.m | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/bar.c b/src/bar.c index 12745ee..bda6dda 100644 --- a/src/bar.c +++ b/src/bar.c @@ -313,6 +313,8 @@ void bar_create_window(struct bar* bar) { window_set_level(&bar->window, g_bar_manager.window_level); SLSOrderWindow(g_connection, bar->window.id, 1, 0); context_set_font_smoothing(bar->window.context, g_bar_manager.font_smoothing); + CGContextClearRect(bar->window.context, bar->window.frame); + CGContextFlush(bar->window.context); } struct bar *bar_create(uint32_t did) { diff --git a/src/sketchybar.m b/src/sketchybar.m index ab477fe..4c3b75e 100644 --- a/src/sketchybar.m +++ b/src/sketchybar.m @@ -172,7 +172,10 @@ int main(int argc, char **argv) { mouse_begin(); display_begin(); workspace_event_handler_begin(&g_workspace_context); + + windows_freeze(); bar_manager_begin(&g_bar_manager); + windows_unfreeze(); if (!mach_server_begin(&g_mach_server, mach_message_handler)) error("sketchybar: could not initialize daemon! abort..\n"); From c07d302f2ba4f3bd6446ac714ccf6007a3e6a2cf Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Tue, 7 Jun 2022 10:48:50 +0200 Subject: [PATCH 17/27] fix popup anchor for bottom bar layout --- src/bar.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bar.c b/src/bar.c index bda6dda..0230e1c 100644 --- a/src/bar.c +++ b/src/bar.c @@ -46,8 +46,7 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b - bar_item->popup.background.bounds.size.width; } anchor.y += (g_bar_manager.position == POSITION_BOTTOM - ? (-window->frame.size.height - - bar_item->popup.background.bounds.size.height) + ? (- bar_item->popup.background.bounds.size.height) : window->frame.size.height); popup_set_anchor(&bar_item->popup, anchor, bar->adid); From 3129a49cd6a14cfbef9bfeb075e85b8d2fe27c76 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Tue, 7 Jun 2022 15:06:29 +0200 Subject: [PATCH 18/27] much better performance and misc fixes --- src/bar.c | 102 ++++++++++++++++++++++----------------------- src/bar_item.c | 28 ++++--------- src/bar_item.h | 1 + src/bar_manager.c | 54 +++++++++++++++--------- src/bar_manager.h | 1 + src/misc/helpers.h | 2 + src/popup.c | 52 +++++++++++------------ src/window.c | 74 +++++++++++++++++++------------- src/window.h | 13 ++++-- 9 files changed, 178 insertions(+), 149 deletions(-) diff --git a/src/bar.c b/src/bar.c index 0230e1c..d5a8a6a 100644 --- a/src/bar.c +++ b/src/bar.c @@ -56,16 +56,25 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b } void bar_order_item_windows(struct bar* bar, int mode) { + SLSOrderWindow(g_connection, bar->window.id, 1, 0); + struct window* previous_window = NULL; for (int i = 0; i < g_bar_manager.bar_item_count; i++) { struct bar_item* bar_item = g_bar_manager.bar_items[i]; - if (!bar_draws_item(bar, bar_item)) continue; - struct window* window = bar_item_get_window(bar_item, bar->adid); SLSRemoveFromOrderingGroup(g_connection, window->id); window_set_level(window, g_bar_manager.window_level); + if (bar_item->type == BAR_COMPONENT_GROUP) { + SLSOrderWindow(g_connection, window->id, mode, bar->window.id); + SLSAddWindowToWindowOrderingGroup(g_connection, + bar->window.id, + window->id, + 1 ); + continue; + } + if (previous_window) { SLSOrderWindow(g_connection, window->id, mode, previous_window->id); SLSAddWindowToWindowOrderingGroup(g_connection, @@ -111,19 +120,25 @@ void bar_draw(struct bar* bar) { if (!(bar_item->position == POSITION_POPUP)) bar_item_remove_associated_bar(bar_item, bar->adid); - if (!bar_draws_item(bar, bar_item)) { - SLSMoveWindow(g_connection, window->id, &g_nirvana); + if (!bar_draws_item(bar, bar_item) + || (bar_item->type == BAR_COMPONENT_GROUP + && !bar_draws_item(bar, group_get_first_member(bar_item->group)))){ + + if (!CGPointEqualToPoint(window->origin, g_nirvana)) { + window->origin = g_nirvana; + SLSMoveWindow(g_connection, window->id, &g_nirvana); + } continue; } bar_item_append_associated_bar(bar_item, bar->adid); - SLSMoveWindow(g_connection, window->id, &window->origin); if (bar_item->popup.drawing && bar->adid == g_bar_manager.active_adid) popup_draw(&bar_item->popup); - if (!bar_item->needs_update) continue; + // SLSMoveWindow(g_connection, window->id, &window->origin); + if (!window_apply_frame(window) && !bar_item->needs_update) continue; if (bar_item->update_mask & UPDATE_MOUSE_ENTERED || bar_item->update_mask & UPDATE_MOUSE_EXITED) { @@ -134,26 +149,10 @@ void bar_draw(struct bar* bar) { // SLSAddTrackingRect(g_connection, window->id, tracking_rect); } - 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 ); - - if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) { - group_draw(bar_item->group, - bar_item_get_window(bar_item->group->members[0], - bar->adid )->context); - } + CGContextClearRect(window->context, window->frame); bar_item_draw(bar_item, window->context); CGContextFlush(window->context); - } } @@ -188,7 +187,8 @@ void bar_calculate_bounds(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]; - if (!bar_draws_item(bar, bar_item)) { + if (!bar_draws_item(bar, bar_item) + || bar_item->type == BAR_COMPONENT_GROUP) { continue; } @@ -224,29 +224,31 @@ void bar_calculate_bounds(struct bar* bar) { 0, y ); - struct window* window = bar_item_get_window(bar_item, bar->adid); - window->origin.x = bar->window.origin.x + *next_position; - window->origin.y = bar->window.origin.y; - window->frame.size.width = bar_item_display_length; - window->frame.size.height = bar->window.frame.size.height; + CGRect frame = {{bar->window.origin.x + *next_position, + bar->window.origin.y }, + {bar_item_display_length, + bar->window.frame.size.height} }; - // if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) { - // uint32_t group_length = group_get_length(bar_item->group); - // uint32_t group_offset = (bar_item->position == POSITION_RIGHT - // || bar_item->position == POSITION_CENTER_LEFT) - // ? group_length - // - bar_item_get_length(bar_item, false) - // : 0; - // - // struct window* group_window = bar_item_get_window( - // bar_item->group->members[0], - // bar->adid ); - // - // group_window->origin = window->origin; - // group_window->origin.x -= group_offset; - // group_window->frame.size = window->frame.size; - // group_window->frame.size.width = group_length; - // } + window_set_frame(bar_item_get_window(bar_item, bar->adid), frame); + + if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) { + uint32_t group_length = group_get_length(bar_item->group); + uint32_t group_offset = (bar_item->position == POSITION_RIGHT + || bar_item->position == POSITION_CENTER_LEFT) + ? group_length + - bar_item_get_length(bar_item, false) + - group_count_members_drawn(bar_item->group) + : 0; + + CGRect group_frame = {{frame.origin.x - group_offset, + frame.origin.y }, + {group_length, + frame.size.height} }; + + window_set_frame(bar_item_get_window(bar_item->group->members[0], + bar->adid ), + group_frame ); + } if (bar_item->popup.drawing) bar_calculate_popup_anchor_for_bar_item(bar, bar_item); @@ -291,7 +293,8 @@ CGRect bar_get_frame(struct bar *bar) { void bar_resize(struct bar* bar) { if (bar->hidden) return; - window_resize(&bar->window, bar_get_frame(bar)); + window_set_frame(&bar->window, bar_get_frame(bar)); + window_apply_frame(&bar->window); bar_calculate_bounds(bar); bar->needs_update = true; bar_draw(bar); @@ -306,14 +309,11 @@ void bar_set_hidden(struct bar* bar, bool hidden) { void bar_create_window(struct bar* bar) { window_create(&bar->window, bar_get_frame(bar)); + window_set_level(&bar->window, g_bar_manager.window_level); window_set_blur_radius(&bar->window, g_bar_manager.blur_radius); if (!g_bar_manager.shadow) window_disable_shadow(&bar->window); - window_set_level(&bar->window, g_bar_manager.window_level); - SLSOrderWindow(g_connection, bar->window.id, 1, 0); context_set_font_smoothing(bar->window.context, g_bar_manager.font_smoothing); - CGContextClearRect(bar->window.context, bar->window.frame); - CGContextFlush(bar->window.context); } struct bar *bar_create(uint32_t did) { diff --git a/src/bar_item.c b/src/bar_item.c index 381e60e..a662fb7 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -269,7 +269,6 @@ void bar_item_set_type(struct bar_item* bar_item, char type) { bar_item->has_graph = true; } else if (type == BAR_COMPONENT_GROUP) { - bar_item->drawing = false; bar_item->group = group_create(); group_init(bar_item->group); group_add_member(bar_item->group, bar_item); @@ -369,7 +368,7 @@ uint32_t bar_item_get_content_length(struct bar_item* bar_item) { + (bar_item->has_graph ? graph_get_length(&bar_item->graph) : 0) + (bar_item->has_alias ? alias_get_length(&bar_item->alias) : 0); - return length > 0 ? length : 0; + return max(length, 0); } uint32_t bar_item_get_length(struct bar_item* bar_item, bool ignore_override) { @@ -393,13 +392,9 @@ uint32_t bar_item_get_height(struct bar_item* bar_item) { uint32_t icon_height = text_get_height(&bar_item->icon); uint32_t alias_height = alias_get_height(&bar_item->alias); - uint32_t text_height = label_height > icon_height - ? label_height - : icon_height; + uint32_t text_height = max(label_height, icon_height); - uint32_t item_height = text_height > alias_height - ? text_height - : alias_height; + uint32_t item_height = max(text_height, alias_height); if (bar_item->background.enabled && bar_item->background.image.enabled && bar_item->background.image.bounds.size.height > item_height ) { @@ -428,7 +423,7 @@ struct window* bar_item_get_window(struct bar_item* bar_item, uint32_t adid) { g_bar_manager.font_smoothing ); window_set_level(bar_item->windows[adid - 1], - g_bar_manager.window_level + 1); + g_bar_manager.window_level); } return bar_item->windows[adid - 1]; @@ -445,10 +440,7 @@ void bar_item_remove_window(struct bar_item* bar_item, uint32_t adid) { CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item) { CGRect bounding_rect; bounding_rect.origin = bar_item->icon.bounds.origin; - bounding_rect.origin.y = bar_item->icon.bounds.origin.y - < bar_item->label.bounds.origin.y - ? bar_item->icon.bounds.origin.y - : bar_item->label.bounds.origin.y; + bounding_rect.origin.y = min(bar_item->icon.bounds.origin.y, bar_item->label.bounds.origin.y); if (bar_item->has_alias && bounding_rect.origin.y > bar_item->alias.image.bounds.origin.y) { @@ -469,6 +461,7 @@ void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t window->origin.y = -rect.origin.y - rect.size.height + bar_origin.y + height; window->frame.size = rect.size; } + uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_height, uint32_t x, uint32_t y) { uint32_t content_x = x; uint32_t content_y = y; @@ -495,12 +488,8 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh if (bar_item->group && group_is_first_member(bar_item->group, bar_item)) group_calculate_bounds(bar_item->group, - (bar_item->position == POSITION_RIGHT - || bar_item->position == POSITION_CENTER_LEFT) - ? (x - group_get_length(bar_item->group) - + bar_item_length ) - : icon_position, - content_y, + x, + y, bar_item->position == POSITION_RIGHT || bar_item->position == POSITION_CENTER_LEFT); @@ -539,6 +528,7 @@ uint32_t bar_item_calculate_bounds(struct bar_item* bar_item, uint32_t bar_heigh x, content_y + bar_item->y_offset ); } + return bar_item_length; } diff --git a/src/bar_item.h b/src/bar_item.h index 04f6cfd..64cde80 100644 --- a/src/bar_item.h +++ b/src/bar_item.h @@ -107,6 +107,7 @@ void bar_item_mouse_entered(struct bar_item* bar_item); void bar_item_mouse_exited(struct bar_item* bar_item); struct window* bar_item_get_window(struct bar_item* bar_item, uint32_t adid); +void bar_item_remove_window(struct bar_item* bar_item, uint32_t adid); CGRect bar_item_construct_bounding_rect(struct bar_item* bar_item); void bar_item_set_bounding_rect_for_display(struct bar_item* bar_item, uint32_t adid, CGPoint bar_origin, uint32_t height); diff --git a/src/bar_manager.c b/src/bar_manager.c index c8ec748..c4ecea8 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -198,20 +198,14 @@ bool bar_manager_set_display(struct bar_manager* bar_manager, char display) { if (bar_manager->display == display) return false; bar_manager->display = display; - for (int i = 0; i < bar_manager->bar_count; ++i) - bar_destroy(bar_manager->bars[i]); - - bar_manager_begin(bar_manager); + bar_manager_reset(bar_manager); return true; } bool bar_manager_set_shadow(struct bar_manager* bar_manager, bool shadow) { if (bar_manager->shadow == shadow) return false; bar_manager->shadow = shadow; - for (int i = 0; i < bar_manager->bar_count; ++i) - bar_destroy(bar_manager->bars[i]); - - bar_manager_begin(bar_manager); + bar_manager_reset(bar_manager); return true; } @@ -252,12 +246,9 @@ bool bar_manager_set_hidden(struct bar_manager *bar_manager, uint32_t adid, bool } bool bar_manager_set_topmost(struct bar_manager *bar_manager, bool topmost) { - for (int i = 0; i < bar_manager->bar_count; i++) - bar_destroy(bar_manager->bars[i]); - if (topmost) bar_manager->window_level = kCGScreenSaverWindowLevel; else bar_manager->window_level = kCGNormalWindowLevel; - bar_manager_begin(bar_manager); + bar_manager_reset(bar_manager); bar_manager->topmost = topmost; return true; } @@ -331,7 +322,7 @@ 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) { + if (bar_manager->needs_ordering) { bar_order_item_windows(bar_manager->bars[i], 1); } } @@ -430,7 +421,22 @@ void bar_manager_update(struct bar_manager* bar_manager, bool forced) { bar_manager_unfreeze(bar_manager); } -void bar_manager_begin(struct bar_manager *bar_manager) { +void bar_manager_reset(struct bar_manager* bar_manager) { + for (int i = 0; i < bar_manager->bar_count; i++) { + for (int j = 0; j < bar_manager->bar_item_count; j++) { + struct bar_item* bar_item = bar_manager->bar_items[j]; + bar_item_remove_window(bar_item, bar_manager->bars[i]->adid); + } + + bar_destroy(bar_manager->bars[i]); + bar_manager->bars[i] = NULL; + } + bar_manager->bar_count = 0; + + bar_manager_begin(bar_manager); +} + +void bar_manager_begin(struct bar_manager* bar_manager) { if (bar_manager->display == DISPLAY_MAIN) { uint32_t did = display_main_display_id(); bar_manager->bar_count = 1; @@ -491,10 +497,7 @@ void bar_manager_custom_events_trigger(struct bar_manager* bar_manager, char* na void bar_manager_display_changed(struct bar_manager* bar_manager) { bar_manager->active_adid = display_arrangement(display_active_display_id()); - for (int i = 0; i < bar_manager->bar_count; ++i) - bar_destroy(bar_manager->bars[i]); - - bar_manager_begin(bar_manager); + bar_manager_reset(bar_manager); bar_manager_freeze(bar_manager); bar_manager->frozen = false; bar_manager_refresh(bar_manager, true); @@ -532,6 +535,7 @@ void bar_manager_handle_space_change(struct bar_manager* bar_manager) { info[1] = '\n'; uint32_t cursor = 2; for (int i = 0; i < bar_manager->bar_count; i++) { + // uint32_t previous_sid = bar_manager->bars[i]->sid; bar_manager->bars[i]->sid = mission_control_index( display_space_id(bar_manager->bars[i]->did)); @@ -544,6 +548,17 @@ void bar_manager_handle_space_change(struct bar_manager* bar_manager) { bar_manager->bars[i]->adid, bar_manager->bars[i]->sid ); cursor = strlen(info); + + // if (bar_manager->bars[i]->shown) { + // for (int j = 0; j < bar_manager->bar_item_count; j++) { + // struct bar_item* bar_item = bar_manager->bar_items[j]; + // if ((bar_item->associated_space & (1 << previous_sid)) + // || (bar_item->associated_space & (1 << bar_manager->bars[i]->sid))) + // { + // bar_item_needs_update(bar_item); + // } + // } + // } } info[cursor] = '}'; info[cursor + 1] = '\0'; @@ -554,9 +569,10 @@ void bar_manager_handle_space_change(struct bar_manager* bar_manager) { COMMAND_SUBSCRIBE_SPACE_CHANGE, &env_vars ); + bar_manager_freeze(bar_manager); bar_manager->frozen = false; - bar_manager_refresh(bar_manager, true); + bar_manager_refresh(bar_manager, false); bar_manager_unfreeze(bar_manager); env_vars_destroy(&env_vars); } diff --git a/src/bar_manager.h b/src/bar_manager.h index 57aff16..5055b20 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -44,6 +44,7 @@ struct bar_manager { struct bar_manager g_bar_manager; void bar_manager_init(struct bar_manager* bar_manager); void bar_manager_begin(struct bar_manager* bar_manager); +void bar_manager_reset(struct bar_manager* bar_manager); struct bar_item* bar_manager_create_item(struct bar_manager* bar_manager); void bar_manager_remove_item(struct bar_manager* bar_manager, struct bar_item* bar_item); diff --git a/src/misc/helpers.h b/src/misc/helpers.h index ac95559..a1cab25 100644 --- a/src/misc/helpers.h +++ b/src/misc/helpers.h @@ -7,6 +7,8 @@ #include "defines.h" #define array_count(a) (sizeof((a)) / sizeof(*(a))) +#define max(a, b) a > b ? a : b +#define min(a, b) a < b ? a : b #define MAXLEN 512 #define FORK_TIMEOUT 60 diff --git a/src/popup.c b/src/popup.c index 7e074e4..e359397 100644 --- a/src/popup.c +++ b/src/popup.c @@ -19,6 +19,12 @@ void popup_init(struct popup* popup) { popup->background.color = rgba_color_from_hex(0x44000000); } +CGRect popup_get_frame(struct popup* popup) { + return (CGRect){{popup->anchor.x, popup->anchor.y}, + {popup->background.bounds.size.width, + popup->background.bounds.size.height}}; +} + void popup_calculate_bounds(struct popup* popup) { uint32_t y = popup->background.border_width; uint32_t x = 0; @@ -36,9 +42,8 @@ void popup_calculate_bounds(struct popup* popup) { for (int j = 0; j < popup->num_items; j++) { struct bar_item* bar_item = popup->items[j]; if (!bar_item->drawing) continue; - uint32_t cell_height = bar_item_get_height(bar_item) > popup->cell_size - ? bar_item_get_height(bar_item) - : popup->cell_size; + uint32_t cell_height = max(bar_item_get_height(bar_item), + popup->cell_size ); total_item_width += bar_item->background.padding_right + bar_item->background.padding_left @@ -54,7 +59,6 @@ void popup_calculate_bounds(struct popup* popup) { x = (width - total_item_width) / 2; } - } for (int j = 0; j < popup->num_items; j++) { @@ -62,27 +66,20 @@ void popup_calculate_bounds(struct popup* popup) { if (popup->horizontal) bar_item = popup->items[j]; else bar_item = popup->items[popup->num_items - 1 - j]; if (!bar_item->drawing) continue; - uint32_t cell_height = bar_item_get_height(bar_item) > popup->cell_size - ? bar_item_get_height(bar_item) - : popup->cell_size; + + uint32_t cell_height = max(bar_item_get_height(bar_item), + popup->cell_size ); + + uint32_t item_x = x + bar_item->background.padding_left; + uint32_t item_y = y + y + (popup->horizontal ? height : cell_height) / 2; + uint32_t item_height = popup->horizontal ? height : cell_height; uint32_t item_width = bar_item->background.padding_right + bar_item->background.padding_left + bar_item_calculate_bounds(bar_item, - popup->horizontal - ? height - : cell_height, - x, - y + (popup->horizontal - ? height - : cell_height) / 2); - - if (popup->adid > 0) { - bar_item_set_bounding_rect_for_display(bar_item, - popup->adid, - popup->anchor, - popup->background.bounds.size.height); - } + item_height, + item_x, + item_y ); if (item_width > width && !popup->horizontal) width = item_width; if (popup->horizontal) x += item_width; @@ -181,9 +178,8 @@ void popup_draw(struct popup* popup) { if (!popup->drawing || popup->adid <= 0) return; SLSOrderWindow(g_connection, popup->window.id, -1, 0); - window_resize(&popup->window, (CGRect){{popup->anchor.x, popup->anchor.y}, - {popup->background.bounds.size.width, - popup->background.bounds.size.height}}); + window_set_frame(&popup->window, popup_get_frame(popup)); + window_apply_frame(&popup->window); CGContextClearRect(popup->window.context, popup->background.bounds); @@ -204,10 +200,10 @@ void popup_draw(struct popup* popup) { SLSAddTrackingRect(g_connection, popup->window.id, tracking_rect); } - // bar_item_set_bounding_rect_for_display(bar_item, - // popup->adid, - // popup->anchor, - // popup->background.bounds.size.height); + bar_item_set_bounding_rect_for_display(bar_item, + popup->adid, + popup->anchor, + popup->background.bounds.size.height); bool state = bar_item->popup.drawing; bar_item->popup.drawing = false; diff --git a/src/window.c b/src/window.c index 4a9101e..71503ee 100644 --- a/src/window.c +++ b/src/window.c @@ -1,11 +1,8 @@ #include "window.h" static CFTypeRef window_create_region(struct window *window, CGRect frame) { - window->frame = (CGRect) {{0, 0},{frame.size.width, frame.size.height}}; - window->origin = frame.origin; - CFTypeRef frame_region; - CGSNewRegionWithRect(&window->frame, &frame_region); + CGSNewRegionWithRect(&frame, &frame_region); return frame_region; } @@ -13,12 +10,17 @@ void window_create(struct window* window, CGRect frame) { uint64_t set_tags = kCGSStickyTagBit | kCGSHighQualityResamplingTagBit; uint64_t clear_tags = kCGSSuperStickyTagBit; + window->origin = frame.origin; + window->frame.origin = (CGPoint){0, 0}; + window->frame.size = frame.size; + + frame.origin = (CGPoint){0, 0}; CFTypeRef frame_region = window_create_region(window, frame); SLSNewWindow(g_connection, 2, window->origin.x, window->origin.y, frame_region, &window->id ); - SLSAddActivationRegion(g_connection, window->id, frame_region); + // SLSAddActivationRegion(g_connection, window->id, frame_region); CFRelease(frame_region); SLSSetWindowResolution(g_connection, window->id, 2.0f); @@ -39,11 +41,8 @@ void window_create(struct window* window, CGRect frame) { CFRelease(dict); CGContextSetInterpolationQuality(window->context, kCGInterpolationNone); - - // SLSAddSurface(g_connection, window->id, &window->surface_id); - // SLSSetSurfaceBounds(g_connection, window->id, window->surface_id, window->frame); - // SLSBindSurface(g_connection, window->id, window->surface_id, 0, 0, window->context); - // SLSOrderSurface(g_connection, window->id, window->surface_id, 0, 1); + window->needs_move = false; + window->needs_resize = false; } void windows_freeze() { @@ -54,29 +53,42 @@ void windows_unfreeze() { SLSReenableUpdate(g_connection); } -void window_resize(struct window* window, CGRect frame) { - CGRect out; - SLSGetScreenRectForWindow(g_connection, window->id, &out); - - if (CGRectEqualToRect(frame, out)) return; - else if (CGSizeEqualToSize(frame.size, out.size)) { +void window_set_frame(struct window* window, CGRect frame) { + if (!CGPointEqualToPoint(window->origin, frame.origin)) { + window->needs_move = true; window->origin = frame.origin; - SLSMoveWindow(g_connection, window->id, &window->origin); - return; } - - CFTypeRef frame_region = window_create_region(window, frame); - SLSSetWindowShape(g_connection, - window->id, - window->origin.x, - window->origin.y, - frame_region ); - SLSClearActivationRegion(g_connection, window->id); - SLSAddActivationRegion(g_connection, window->id, frame_region); - SLSRemoveAllTrackingAreas(g_connection, window->id); + if (!CGSizeEqualToSize(window->frame.size, frame.size)) { + window->needs_resize = true; + window->frame.size = frame.size; + } +} - CFRelease(frame_region); +bool window_apply_frame(struct window* window) { + if (window->needs_resize) { + CFTypeRef frame_region = window_create_region(window, window->frame); + SLSSetWindowShape(g_connection, + window->id, + window->origin.x, + window->origin.y, + frame_region ); + + // SLSClearActivationRegion(g_connection, window->id); + // SLSAddActivationRegion(g_connection, window->id, frame_region); + SLSRemoveAllTrackingAreas(g_connection, window->id); + + CFRelease(frame_region); + window->needs_move = false; + window->needs_resize = false; + return true; + } else if (window->needs_move) { + CGPoint origin = window->origin; + SLSMoveWindow(g_connection, window->id, &origin); + window->needs_move = false; + return false; + } + return false; } void window_close(struct window* window) { @@ -85,6 +97,10 @@ void window_close(struct window* window) { window->context = NULL; window->id = 0; + window->origin = CGPointZero; + window->frame = CGRectNull; + window->needs_move = false; + window->needs_resize = false; } void window_set_level(struct window* window, uint32_t level) { diff --git a/src/window.h b/src/window.h index d2062e7..f92bb2c 100644 --- a/src/window.h +++ b/src/window.h @@ -3,13 +3,14 @@ extern CGError SLSDisableUpdate(int cid); extern CGError SLSReenableUpdate(int cid); -extern CGError SLSNewWindow(int cid, int type, float x, float y, CFTypeRef region, uint32_t *wid); +extern CGError SLSNewWindow(int cid, int type, float x, float y, CFTypeRef region, uint64_t *wid); extern CGError SLSReleaseWindow(int cid, uint32_t wid); extern CGError SLSSetWindowTags(int cid, uint32_t wid, uint64_t* tags, int tag_size); extern CGError SLSClearWindowTags(int cid, uint32_t wid, uint64_t* tags, int tag_size); extern CGError SLSSetWindowShape(int cid, uint32_t wid, float x_offset, float y_offset, CFTypeRef shape); extern CGError SLSSetWindowResolution(int cid, uint32_t wid, double res); extern CGError SLSSetWindowOpacity(int cid, uint32_t wid, bool isOpaque); +extern CGError SLSSetWindowAlpha(int cid, uint32_t wid, float alpha); extern CGError SLSSetWindowBackgroundBlurRadius(int cid, uint32_t wid, uint32_t radius); extern CGError SLSOrderWindow(int cid, uint32_t wid, int mode, uint32_t relativeToWID); extern CGError SLSSetWindowLevel(int cid, uint32_t wid, int level); @@ -42,7 +43,10 @@ extern CGError SLSFlushSurface(int cid, uint32_t wid, uint32_t surface, int para #define kCGSSuperStickyTagBit (1ULL << 45) struct window { - uint32_t id; + bool needs_move; + bool needs_resize; + + uint64_t id; uint32_t surface_id; CGRect frame; @@ -52,7 +56,10 @@ struct window { void window_create(struct window* window, CGRect frame); void window_close(struct window* window); -void window_resize(struct window* window, CGRect frame); + + +void window_set_frame(struct window* window, CGRect frame); +bool window_apply_frame(struct window* window); void window_set_blur_radius(struct window* window, uint32_t blur_radius); void window_disable_shadow(struct window* window); From 0892e1323e48005ca656687fa55e05434f8caf99 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Tue, 7 Jun 2022 15:56:35 +0200 Subject: [PATCH 19/27] fix mouse entered and exited event logic --- src/bar.c | 20 ++++++++------ src/bar_item.c | 2 +- src/bar_manager.c | 36 ++++++++++++++++++++++--- src/bar_manager.h | 4 ++- src/event.c | 69 +++++++++++++++++++++++++++++++++-------------- src/event.h | 2 +- src/popup.c | 4 +-- src/workspace.h | 2 ++ src/workspace.m | 5 ++++ 9 files changed, 108 insertions(+), 36 deletions(-) diff --git a/src/bar.c b/src/bar.c index d5a8a6a..3707fe2 100644 --- a/src/bar.c +++ b/src/bar.c @@ -114,11 +114,13 @@ 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]; + if (bar_item->position == POSITION_POPUP) { + continue; + } struct window* window = bar_item_get_window(bar_item, bar->adid); - if (!(bar_item->position == POSITION_POPUP)) - bar_item_remove_associated_bar(bar_item, bar->adid); + bar_item_remove_associated_bar(bar_item, bar->adid); if (!bar_draws_item(bar, bar_item) || (bar_item->type == BAR_COMPONENT_GROUP @@ -137,16 +139,14 @@ void bar_draw(struct bar* bar) { if (bar_item->popup.drawing && bar->adid == g_bar_manager.active_adid) popup_draw(&bar_item->popup); - // SLSMoveWindow(g_connection, window->id, &window->origin); if (!window_apply_frame(window) && !bar_item->needs_update) continue; if (bar_item->update_mask & UPDATE_MOUSE_ENTERED || bar_item->update_mask & UPDATE_MOUSE_EXITED) { - // CGRect tracking_rect = window->frame; - // tracking_rect.origin = window->origin; - // - // SLSRemoveAllTrackingAreas(g_connection, window->id); - // SLSAddTrackingRect(g_connection, window->id, tracking_rect); + CGRect tracking_rect = window->frame; + + SLSRemoveAllTrackingAreas(g_connection, window->id); + SLSAddTrackingRect(g_connection, window->id, tracking_rect); } CGContextClearRect(window->context, window->frame); @@ -295,6 +295,8 @@ 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); @@ -309,6 +311,8 @@ void bar_set_hidden(struct bar* bar, bool hidden) { void bar_create_window(struct bar* bar) { window_create(&bar->window, bar_get_frame(bar)); + SLSRemoveAllTrackingAreas(g_connection, bar->window.id); + SLSAddTrackingRect(g_connection, bar->window.id, bar->window.frame); window_set_level(&bar->window, g_bar_manager.window_level); window_set_blur_radius(&bar->window, g_bar_manager.blur_radius); if (!g_bar_manager.shadow) window_disable_shadow(&bar->window); diff --git a/src/bar_item.c b/src/bar_item.c index a662fb7..5b3d309 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -568,7 +568,7 @@ void bar_item_destroy(struct bar_item* bar_item) { popup_destroy(&bar_item->popup); background_destroy(&bar_item->background); - for (int j = 1; j < bar_item->num_windows; j++) { + for (int j = 1; j <= bar_item->num_windows; j++) { bar_item_remove_window(bar_item, j); } if (bar_item->windows) free(bar_item->windows); diff --git a/src/bar_manager.c b/src/bar_manager.c index c4ecea8..5cd8a36 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -483,6 +483,32 @@ struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, return NULL; } +struct bar_item* bar_manager_get_item_by_wid(struct bar_manager* bar_manager, uint32_t wid, uint32_t adid) { + for (int i = 0; i < bar_manager->bar_item_count; i++) { + struct bar_item* bar_item = bar_manager->bar_items[i]; + if (!bar_item->drawing || bar_item->num_windows < adid + || bar_item->windows[adid - 1] == NULL) { + continue; + } + + struct window* window = bar_item_get_window(bar_item, adid); + + if (window->id == wid) { + return bar_item; + } + } + return NULL; +} + +struct bar* bar_manager_get_bar_by_wid(struct bar_manager* bar_manager, uint32_t wid) { + for (int i = 0; i < bar_manager->bar_count; i++) { + if (bar_manager->bars[i]->window.id == wid) { + return bar_manager->bars[i]; + } + } + return NULL; +} + void bar_manager_custom_events_trigger(struct bar_manager* bar_manager, char* name, struct env_vars* env_vars) { uint64_t flag = custom_events_get_flag_for_name(&bar_manager->custom_events, name ); @@ -512,9 +538,13 @@ void bar_manager_handle_mouse_entered(struct bar_manager* bar_manager, struct ba bar_item_mouse_entered(bar_item); } -void bar_manager_handle_mouse_exited(struct bar_manager* bar_manager) { - for (int i = 0; i < bar_manager->bar_item_count; i++) - bar_item_mouse_exited(bar_manager->bar_items[i]); +void bar_manager_handle_mouse_exited(struct bar_manager* bar_manager, struct bar_item* bar_item) { + if (!bar_item) { + for (int i = 0; i < bar_manager->bar_item_count; i++) + bar_item_mouse_exited(bar_manager->bar_items[i]); + } else { + bar_item_mouse_exited(bar_item); + } } void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager, char* info) { diff --git a/src/bar_manager.h b/src/bar_manager.h index 5055b20..161db70 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -69,6 +69,8 @@ bool bar_manager_set_notch_width(struct bar_manager* bar_manager, uint32_t width void bar_manager_sort(struct bar_manager* bar_manager, struct bar_item** ordering, uint32_t count); struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t adid); +struct bar_item* bar_manager_get_item_by_wid(struct bar_manager* bar_manager, uint32_t wid, uint32_t adid); +struct bar* bar_manager_get_bar_by_wid(struct bar_manager* bar_manager, uint32_t wid); int bar_manager_get_item_index_for_name(struct bar_manager* bar_manager, char* name); uint32_t bar_manager_length_for_bar_side(struct bar_manager* bar_manager, struct bar* bar, char side); @@ -80,7 +82,7 @@ void bar_manager_refresh(struct bar_manager* bar_manager, bool forced); void bar_manager_resize(struct bar_manager* bar_manager); void bar_manager_handle_mouse_entered(struct bar_manager* bar_manager, struct bar_item* bar_item); -void bar_manager_handle_mouse_exited(struct bar_manager* bar_manager); +void bar_manager_handle_mouse_exited(struct bar_manager* bar_manager, struct bar_item* bar_item); void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager, char* info); void bar_manager_handle_space_change(struct bar_manager* bar_manager); void bar_manager_handle_display_change(struct bar_manager* bar_manager); diff --git a/src/event.c b/src/event.c index ffd1013..69913a3 100644 --- a/src/event.c +++ b/src/event.c @@ -113,20 +113,23 @@ EVENT_CALLBACK(EVENT_HANDLER_MACH_MESSAGE) { EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) { debug("%s\n", __FUNCTION__); - CGPoint point = CGEventGetLocation(context); + debug("EVENT_HANDLER_MOUSE_UP\n"); + + uint32_t wid = get_window_id_from_cg_event(context); CGEventType type = CGEventGetType(context); uint32_t modifier_keys = CGEventGetFlags(context); uint32_t adid = display_arrangement(display_active_display_id()); - printf("EVENT_HANDLER_MOUSE_UP: D#%d (x: %.0f, y: %.0f) -> ", - adid, - point.x, - point.y ); - struct bar_item* bar_item = bar_manager_get_item_by_point(&g_bar_manager, - point, - adid ); + struct bar_item* bar_item = bar_manager_get_item_by_wid(&g_bar_manager, + wid, + adid ); + if (!bar_item) { + CGPoint point = CGEventGetLocation(context); + bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, adid); + } - printf("item: %s\n", bar_item ? bar_item->name : "NULL"); + + debug("item: %s\n", bar_item ? bar_item->name : "NULL"); bar_item_on_click(bar_item, type, modifier_keys); CFRelease(context); return EVENT_SUCCESS; @@ -134,18 +137,28 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) { EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED) { debug("%s\n", __FUNCTION__); - CGPoint point = CGEventGetLocation(context); + debug("EVENT_HANDLER_MOUSE_ENTERED\n"); + uint32_t wid = get_window_id_from_cg_event(context); + uint32_t adid = display_arrangement(display_active_display_id()); - printf("EVENT_HANDLER_MOUSE_ENTERED: D#%d (x: %.0f, y: %.0f) -> ", - adid, - point.x, - point.y ); - struct bar_item* bar_item = bar_manager_get_item_by_point(&g_bar_manager, - point, - adid ); + struct bar* bar = bar_manager_get_bar_by_wid(&g_bar_manager, wid); + if (bar) { + // Handle global mouse entered event + + CFRelease(context); + return EVENT_SUCCESS; + } - printf("item: %s\n", bar_item ? bar_item->name : "NULL"); + struct bar_item* bar_item = bar_manager_get_item_by_wid(&g_bar_manager, + wid, + adid ); + if (!bar_item) { + CGPoint point = CGEventGetLocation(context); + bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, adid); + } + + debug("item: %s\n", bar_item ? bar_item->name : "NULL"); bar_manager_handle_mouse_entered(&g_bar_manager, bar_item); CFRelease(context); return EVENT_SUCCESS; @@ -153,8 +166,24 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED) { EVENT_CALLBACK(EVENT_HANDLER_MOUSE_EXITED) { debug("%s\n", __FUNCTION__); - printf("EVENT_HANDLER_MOUSE_EXITED \n"); - bar_manager_handle_mouse_exited(&g_bar_manager); + debug("EVENT_HANDLER_MOUSE_EXITED\n"); + uint32_t adid = display_arrangement(display_active_display_id()); + uint32_t wid = get_window_id_from_cg_event(context); + + struct bar* bar = bar_manager_get_bar_by_wid(&g_bar_manager, wid); + if (bar) { + // Handle global mouse exited event + + CFRelease(context); + return EVENT_SUCCESS; + } + + struct bar_item* bar_item = bar_manager_get_item_by_wid(&g_bar_manager, + wid, + adid ); + + debug("item: %s\n", bar_item ? bar_item->name : "NULL"); + bar_manager_handle_mouse_exited(&g_bar_manager, bar_item); CFRelease(context); return EVENT_SUCCESS; } diff --git a/src/event.h b/src/event.h index 792c2fd..495a3cf 100644 --- a/src/event.h +++ b/src/event.h @@ -8,7 +8,7 @@ struct event_loop; -extern OSStatus SLSFindWindowByGeometry(int cid, int zero, int one, int zero_again, CGPoint *screen_point, CGPoint *window_point, uint32_t *wid, int *wcid); +extern uint32_t get_window_id_from_cg_event(CGEventRef cgevent); #define EVENT_CALLBACK(name) uint32_t name(void *context) typedef EVENT_CALLBACK(event_callback); diff --git a/src/popup.c b/src/popup.c index e359397..358fcec 100644 --- a/src/popup.c +++ b/src/popup.c @@ -70,8 +70,8 @@ void popup_calculate_bounds(struct popup* popup) { uint32_t cell_height = max(bar_item_get_height(bar_item), popup->cell_size ); - uint32_t item_x = x + bar_item->background.padding_left; - uint32_t item_y = y + y + (popup->horizontal ? height : cell_height) / 2; + uint32_t item_x = max((int)x + bar_item->background.padding_left, 0); + uint32_t item_y = y + (popup->horizontal ? height : cell_height) / 2; uint32_t item_height = popup->horizontal ? height : cell_height; uint32_t item_width = bar_item->background.padding_right diff --git a/src/workspace.h b/src/workspace.h index 72a67be..8d6c81e 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -14,3 +14,5 @@ void workspace_create_custom_observer (void **context, char* notification); void workspace_event_handler_init(void **context); void workspace_event_handler_begin(void **context); void workspace_event_handler_end(void *context); + +uint32_t get_window_id_from_cg_event(CGEventRef cgevent); diff --git a/src/workspace.m b/src/workspace.m index f5d1ad8..0cc6811 100644 --- a/src/workspace.m +++ b/src/workspace.m @@ -23,6 +23,11 @@ void workspace_create_custom_observer (void **context, char* notification) { [ws_context addCustomObserver:@(notification)]; } +uint32_t get_window_id_from_cg_event(CGEventRef cgevent) { + NSEvent *nsEvent = [NSEvent eventWithCGEvent:cgevent]; + return [nsEvent windowNumber]; +} + @implementation workspace_context - (id)init { if ((self = [super init])) { From 96876921c89d109da3b14ed10be8f64f61497ad6 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Tue, 7 Jun 2022 17:39:04 +0200 Subject: [PATCH 20/27] even more aggressive performance optimizations --- src/bar_manager.c | 11 ++++++++++- src/message.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/bar_manager.c b/src/bar_manager.c index 5cd8a36..f87198f 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -278,6 +278,8 @@ 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; + for (int i = 0; i < bar_manager->bar_item_count; i++) { struct bar_item* bar_item = bar_manager->bar_items[i]; bool is_associated_space_shown = (bar_item->associated_space & (1 << bar->sid)) @@ -401,7 +403,14 @@ void bar_manager_animator_refresh(struct bar_manager* bar_manager) { if (animator_update(&bar_manager->animator) || bar_manager->animator.force_refresh) { bar_manager->frozen = false; - bar_manager_refresh(bar_manager, bar_manager->animator.force_refresh); + + 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); } diff --git a/src/message.c b/src/message.c index 5ba4da4..0651e3e 100644 --- a/src/message.c +++ b/src/message.c @@ -628,9 +628,17 @@ void handle_message_mach(struct mach_buffer* buffer) { } command = get_token(&message); } - if (bar_needs_refresh) bar_manager_resize(&g_bar_manager); + g_bar_manager.frozen = false; - bar_manager_refresh(&g_bar_manager, bar_needs_refresh); + 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_refresh(&g_bar_manager, false); bar_manager_unfreeze(&g_bar_manager); if (rsp) fclose(rsp); From 8ecc722b9cd2f0320e540e2d75eeedf1d7bae0b2 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Wed, 8 Jun 2022 10:36:57 +0200 Subject: [PATCH 21/27] initialize new windows off screen --- src/bar_item.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bar_item.c b/src/bar_item.c index 5b3d309..b3aeb2d 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -417,7 +417,8 @@ struct window* bar_item_get_window(struct bar_item* bar_item, uint32_t adid) { } if (!bar_item->windows[adid - 1]) { bar_item->windows[adid - 1] = malloc(sizeof(struct window)); - window_create(bar_item->windows[adid - 1], (CGRect){{0,0}, {1, 1}}); + window_create(bar_item->windows[adid - 1], + (CGRect){{g_nirvana.x,g_nirvana.y}, {1, 1}}); window_disable_shadow(bar_item->windows[adid - 1]); context_set_font_smoothing(bar_item->windows[adid - 1]->context, g_bar_manager.font_smoothing ); From c90d2cd8be8036c50972e49fa40e5d2f2d012ad3 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Wed, 8 Jun 2022 20:16:59 +0200 Subject: [PATCH 22/27] better tracking of bar property change --- src/animation.c | 5 +---- src/animation.h | 2 -- src/bar.c | 24 +++++++++++------------- src/bar.h | 1 - src/bar_manager.c | 17 +++++++---------- src/bar_manager.h | 1 + src/message.c | 9 +++------ 7 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/animation.c b/src/animation.c index 77c1ffa..0feb7df 100644 --- a/src/animation.c +++ b/src/animation.c @@ -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; diff --git a/src/animation.h b/src/animation.h index ef54137..37a63c9 100644 --- a/src/animation.h +++ b/src/animation.h @@ -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; diff --git a/src/bar.c b/src/bar.c index 3707fe2..b084e9f 100644 --- a/src/bar.c +++ b/src/bar.c @@ -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; } diff --git a/src/bar.h b/src/bar.h index 5088ebf..209093f 100644 --- a/src/bar.h +++ b/src/bar.h @@ -11,7 +11,6 @@ #define ALIGN_CENTER 5 struct bar { - bool needs_update; bool shown; bool hidden; diff --git a/src/bar_manager.c b/src/bar_manager.c index f87198f..3b79acf 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -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); diff --git a/src/bar_manager.h b/src/bar_manager.h index 161db70..af92176 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -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; diff --git a/src/message.c b/src/message.c index 0651e3e..dbb534e 100644 --- a/src/message.c +++ b/src/message.c @@ -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); From e9c60a83a967d59685cad7f1f79ee3deb694233d Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Wed, 8 Jun 2022 22:36:29 +0200 Subject: [PATCH 23/27] cleanup --- src/animation.c | 6 +++--- src/bar_item.c | 2 -- src/bar_manager.c | 13 +------------ src/message.c | 15 --------------- src/window.c | 4 +--- 5 files changed, 5 insertions(+), 35 deletions(-) diff --git a/src/animation.c b/src/animation.c index 0feb7df..c4c11a7 100644 --- a/src/animation.c +++ b/src/animation.c @@ -26,7 +26,7 @@ double function_bounce(double x) { } else { return beta * beta * (x - 1./2. + 1./alpha/2.) - + 1. - beta*beta*(1./2. + 1./alpha/2.); + + 1. - beta*beta* (1./2. + 1./alpha/2.); } } @@ -96,7 +96,7 @@ bool animation_update(struct animation* animation) { } else { value = (1. - slider) * animation->initial_value - + slider * animation->final_value; + + slider * animation->final_value; } animation->counter++; @@ -108,6 +108,7 @@ bool animation_update(struct animation* animation) { && (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; } @@ -132,7 +133,6 @@ void animator_add(struct animator* animator, struct animation* animation) { animator->animations[animator->animation_count - 1] = animation; if (animator->animation_count == 1) { - animator->clock = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent()+1./60., 1./60., diff --git a/src/bar_item.c b/src/bar_item.c index b3aeb2d..fb479e6 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -828,8 +828,6 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE* printf("cache_scripts property is deprecated.\n"); } else if (token_equals(property, PROPERTY_LAZY)) { printf("lazy property is deprecated.\n"); - // bar_item->lazy = evaluate_boolean_state(get_token(&message), bar_item->lazy); - // needs_refresh = true; } else if (token_equals(property, PROPERTY_IGNORE_ASSOCIATION)) { bar_item->ignore_association = evaluate_boolean_state(get_token(&message), bar_item->ignore_association); diff --git a/src/bar_manager.c b/src/bar_manager.c index 3b79acf..43591af 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -571,7 +571,6 @@ void bar_manager_handle_space_change(struct bar_manager* bar_manager) { info[1] = '\n'; uint32_t cursor = 2; for (int i = 0; i < bar_manager->bar_count; i++) { - // uint32_t previous_sid = bar_manager->bars[i]->sid; bar_manager->bars[i]->sid = mission_control_index( display_space_id(bar_manager->bars[i]->did)); @@ -584,18 +583,8 @@ void bar_manager_handle_space_change(struct bar_manager* bar_manager) { bar_manager->bars[i]->adid, bar_manager->bars[i]->sid ); cursor = strlen(info); - - // if (bar_manager->bars[i]->shown) { - // for (int j = 0; j < bar_manager->bar_item_count; j++) { - // struct bar_item* bar_item = bar_manager->bar_items[j]; - // if ((bar_item->associated_space & (1 << previous_sid)) - // || (bar_item->associated_space & (1 << bar_manager->bars[i]->sid))) - // { - // bar_item_needs_update(bar_item); - // } - // } - // } } + info[cursor] = '}'; info[cursor + 1] = '\0'; env_vars_set(&env_vars, string_copy("INFO"), string_copy(info)); diff --git a/src/message.c b/src/message.c index dbb534e..8b7ab71 100644 --- a/src/message.c +++ b/src/message.c @@ -5,7 +5,6 @@ extern struct event_loop g_event_loop; extern struct bar_manager g_bar_manager; extern bool g_verbose; -// Syntax: sketchybar -m --subscribe static void handle_domain_subscribe(FILE* rsp, struct token domain, char* message) { struct token name = get_token(&message); @@ -17,7 +16,6 @@ static void handle_domain_subscribe(FILE* rsp, struct token domain, char* messag bar_item_parse_subscribe_message(bar_item, message); } -// Syntax: sketchybar -m --trigger static void handle_domain_trigger(FILE* rsp, struct token domain, char* message) { struct token event = get_token(&message); struct env_vars env_vars; @@ -38,7 +36,6 @@ static void handle_domain_trigger(FILE* rsp, struct token domain, char* message) env_vars_destroy(&env_vars); } -// Syntax: sketchybar -m --push static void handle_domain_push(FILE* rsp, struct token domain, char* message) { struct token name = get_token(&message); struct token y = get_token(&message); @@ -51,7 +48,6 @@ static void handle_domain_push(FILE* rsp, struct token domain, char* message) { bar_item_needs_update(bar_item); } -// Syntax sketchybar -m --rename static void handle_domain_rename(FILE* rsp, struct token domain, char* message) { struct token old_name = get_token(&message); struct token new_name = get_token(&message); @@ -71,7 +67,6 @@ static void handle_domain_rename(FILE* rsp, struct token domain, char* message) token_to_string(new_name) ); } -// Syntax: sketchybar -m --clone static void handle_domain_clone(FILE* rsp, struct token domain, char* message) { struct token name = get_token(&message); struct token parent = get_token(&message); @@ -103,7 +98,6 @@ static void handle_domain_clone(FILE* rsp, struct token domain, char* message) { bar_item_needs_update(bar_item); } -// Syntax: sketchybar -m --add [:parent] [] static void handle_domain_add(FILE* rsp, struct token domain, char* message) { struct token command = get_token(&message); @@ -192,13 +186,10 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) { bar_item_needs_update(bar_item); } -// Syntax: sketchybar -m --set = ... = -// Syntax: sketchybar -m --default = ... = static void handle_domain_default(FILE* rsp, struct token domain, char* message) { bar_item_parse_set_message(&g_bar_manager.default_item, message, rsp); } -// Syntax: sketchybar -m --bar = ... = static bool handle_domain_bar(FILE *rsp, struct token domain, char *message) { struct token command = get_token(&message); bool needs_refresh = false; @@ -320,10 +311,6 @@ static char* get_batch_line(char** message) { return rbr_msg; } -// Syntax: sketchybar -m --query bar -// Syntax: sketchybar -m --query item -// Syntax: sketchybar -m --query defaults -// Syntax: sketchybar -m --query events static void handle_domain_query(FILE* rsp, struct token domain, char* message) { struct token token = get_token(&message); @@ -358,7 +345,6 @@ static void handle_domain_query(FILE* rsp, struct token domain, char* message) { } } -// Syntax: sketchybar -m --remove static void handle_domain_remove(FILE* rsp, struct token domain, char* message) { struct token name = get_token(&message); uint32_t count = 0; @@ -419,7 +405,6 @@ static void handle_domain_remove(FILE* rsp, struct token domain, char* message) if (bar_items) free(bar_items); } -// Syntax: sketchybar -m --move static void handle_domain_move(FILE* rsp, struct token domain, char* message) { struct token name = get_token(&message); struct token direction = get_token(&message); diff --git a/src/window.c b/src/window.c index 71503ee..70a801a 100644 --- a/src/window.c +++ b/src/window.c @@ -20,7 +20,6 @@ void window_create(struct window* window, CGRect frame) { frame_region, &window->id ); - // SLSAddActivationRegion(g_connection, window->id, frame_region); CFRelease(frame_region); SLSSetWindowResolution(g_connection, window->id, 2.0f); @@ -74,8 +73,6 @@ bool window_apply_frame(struct window* window) { window->origin.y, frame_region ); - // SLSClearActivationRegion(g_connection, window->id); - // SLSAddActivationRegion(g_connection, window->id, frame_region); SLSRemoveAllTrackingAreas(g_connection, window->id); CFRelease(frame_region); @@ -120,6 +117,7 @@ void window_disable_shadow(struct window* window) { CFNumberRef shadow_density_cf = CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &shadow_density ); + const void *keys[1] = { CFSTR("com.apple.WindowShadowDensity") }; const void *values[1] = { shadow_density_cf }; CFDictionaryRef shadow_props_cf = CFDictionaryCreate(NULL, From b41c8a9dda409071fe66a2bcc0c99986e8eb60ad Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Thu, 9 Jun 2022 17:44:30 +0200 Subject: [PATCH 24/27] fix some bugs --- sketchybarrc | 2 +- src/alias.c | 9 +++++---- src/bar_item.c | 4 ---- src/bar_item.h | 1 - src/bar_manager.c | 2 +- src/message.c | 43 +++++++++++++++++++++++++------------------ 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/sketchybarrc b/sketchybarrc index 2dc3569..305f4f2 100755 --- a/sketchybarrc +++ b/sketchybarrc @@ -31,7 +31,7 @@ sketchybar --default updates=when_shown \ label.padding_left=4 \ label.padding_right=4 \ icon.padding_left=8 \ - label.padding_right=8 + icon.padding_right=8 ##### Adding Mission Control Space Indicators ##### # Now we add some space components: diff --git a/src/alias.c b/src/alias.c index 0c3a0ad..90ce47b 100644 --- a/src/alias.c +++ b/src/alias.c @@ -155,14 +155,12 @@ bool alias_update_image(struct alias* alias) { if (alias->wid == 0) return false; CGRect bounds = CGRectNull; - SLSGetScreenRectForWindow(g_connection, alias->wid, &bounds); - bounds.size.width = (uint32_t) (bounds.size.width + 0.5); - CGImageRef tmp_ref = NULL; + SLSCaptureWindowsContentsToRectWithOptions(g_connection, &alias->wid, true, - CGRectNull, + bounds, 1 << 8, &tmp_ref ); @@ -171,6 +169,9 @@ bool alias_update_image(struct alias* alias) { return false; } + SLSGetScreenRectForWindow(g_connection, alias->wid, &bounds); + bounds.size.width = (uint32_t) (bounds.size.width + 0.5); + return image_set_image(&alias->image, tmp_ref, bounds, false); } diff --git a/src/bar_item.c b/src/bar_item.c index fb479e6..a8a4c21 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -218,10 +218,6 @@ void bar_item_needs_update(struct bar_item* bar_item) { bar_item->needs_update = true; } -void bar_item_clear_needs_update(struct bar_item* bar_item) { - bar_item->needs_update = false; -} - void bar_item_set_name(struct bar_item* bar_item, char* name) { if (!name) return; diff --git a/src/bar_item.h b/src/bar_item.h index 64cde80..f6d6bef 100644 --- a/src/bar_item.h +++ b/src/bar_item.h @@ -100,7 +100,6 @@ uint32_t bar_item_get_length(struct bar_item* bar_item, bool ignore_override); uint32_t bar_item_get_height(struct bar_item* bar_item); void bar_item_needs_update(struct bar_item* bar_item); -void bar_item_clear_needs_update(struct bar_item* bar_item); void bar_item_on_click(struct bar_item* bar_item, uint32_t type, uint32_t modifier); void bar_item_mouse_entered(struct bar_item* bar_item); diff --git a/src/bar_manager.c b/src/bar_manager.c index 43591af..bb6d3c7 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -298,7 +298,7 @@ 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->bar_items[i]->needs_update = false; bar_manager->needs_ordering = false; bar_manager->bar_needs_update = false; diff --git a/src/message.c b/src/message.c index 8b7ab71..0101f21 100644 --- a/src/message.c +++ b/src/message.c @@ -124,24 +124,6 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) { bar_item_set_type(bar_item, command.text[0]); bar_item_set_position(bar_item, position.text[0]); - if (position.text[0] == POSITION_POPUP) { - char* pair = string_copy(position.text); - struct key_value_pair key_value_pair = get_key_value_pair(pair, '.'); - if (key_value_pair.key && key_value_pair.value) { - int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, - key_value_pair.value); - if (item_index_for_name < 0) { - fprintf(rsp, "Name: %s not found in bar items \n", key_value_pair.value); - printf("Name: %s not found in bar items \n", key_value_pair.value); - free(pair); - return; - } - struct bar_item* target_item = g_bar_manager.bar_items[item_index_for_name]; - popup_add_item(&target_item->popup, bar_item); - } - free(pair); - } - bar_item_set_name(bar_item, token_to_string(name)); if (token_equals(command, COMMAND_ADD_ITEM)) { @@ -183,6 +165,31 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) { return; } + if (position.text[0] == POSITION_POPUP) { + char* pair = string_copy(position.text); + struct key_value_pair key_value_pair = get_key_value_pair(pair, '.'); + if (key_value_pair.key && key_value_pair.value) { + int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, + key_value_pair.value); + if (item_index_for_name < 0) { + fprintf(rsp, + "Parent Name: %s for %s not found in bar items. Placing left instead\n", + key_value_pair.value, + bar_item->name ); + printf("Parent Name: %s for %s not found in bar items. Placing left instead\n", + key_value_pair.value, + bar_item->name ); + + free(pair); + bar_item_set_position(bar_item, POSITION_LEFT); + return; + } + struct bar_item* target_item = g_bar_manager.bar_items[item_index_for_name]; + popup_add_item(&target_item->popup, bar_item); + } + free(pair); + } + bar_item_needs_update(bar_item); } From 553158206793a14eaa265371dd3d3153953497b7 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Thu, 9 Jun 2022 18:05:50 +0200 Subject: [PATCH 25/27] added global mouse entered and exited events --- src/bar.c | 1 + src/bar.h | 1 + src/bar_manager.c | 12 ++++++++++++ src/bar_manager.h | 2 ++ src/custom_events.c | 2 ++ src/custom_events.h | 9 --------- src/event.c | 11 +++++++++++ src/misc/defines.h | 2 ++ 8 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/bar.c b/src/bar.c index b084e9f..85f7142 100644 --- a/src/bar.c +++ b/src/bar.c @@ -322,6 +322,7 @@ struct bar *bar_create(uint32_t did) { struct bar *bar = malloc(sizeof(struct bar)); memset(bar, 0, sizeof(struct bar)); bar->hidden = false; + bar->mouse_over = false; bar->did = did; bar->sid = mission_control_index(display_space_id(did)); bar->shown = true; diff --git a/src/bar.h b/src/bar.h index 209093f..78802ee 100644 --- a/src/bar.h +++ b/src/bar.h @@ -13,6 +13,7 @@ struct bar { bool shown; bool hidden; + bool mouse_over; uint32_t did; uint32_t sid; diff --git a/src/bar_manager.c b/src/bar_manager.c index bb6d3c7..2869ca0 100644 --- a/src/bar_manager.c +++ b/src/bar_manager.c @@ -536,6 +536,18 @@ void bar_manager_display_changed(struct bar_manager* bar_manager) { bar_manager_unfreeze(bar_manager); } +void bar_manager_handle_mouse_entered_global(struct bar_manager* bar_manager) { + bar_manager_custom_events_trigger(bar_manager, + COMMAND_SUBSCRIBE_MOUSE_ENTERED_GLOBAL, + NULL ); +} + +void bar_manager_handle_mouse_exited_global(struct bar_manager* bar_manager) { + bar_manager_custom_events_trigger(bar_manager, + COMMAND_SUBSCRIBE_MOUSE_EXITED_GLOBAL, + NULL ); +} + void bar_manager_handle_mouse_entered(struct bar_manager* bar_manager, struct bar_item* bar_item) { if (!bar_item || bar_item->mouse_over) return; for (int i = 0; i < bar_manager->bar_item_count; i++) diff --git a/src/bar_manager.h b/src/bar_manager.h index af92176..22a07bc 100644 --- a/src/bar_manager.h +++ b/src/bar_manager.h @@ -82,6 +82,8 @@ void bar_manager_display_changed(struct bar_manager* bar_manager); void bar_manager_refresh(struct bar_manager* bar_manager, bool forced); void bar_manager_resize(struct bar_manager* bar_manager); +void bar_manager_handle_mouse_entered_global(struct bar_manager* bar_manager); +void bar_manager_handle_mouse_exited_global(struct bar_manager* bar_manager); void bar_manager_handle_mouse_entered(struct bar_manager* bar_manager, struct bar_item* bar_item); void bar_manager_handle_mouse_exited(struct bar_manager* bar_manager, struct bar_item* bar_item); void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager, char* info); diff --git a/src/custom_events.c b/src/custom_events.c index b310e00..8e692a8 100644 --- a/src/custom_events.c +++ b/src/custom_events.c @@ -25,6 +25,8 @@ void custom_events_init(struct custom_events* custom_events) { custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_SYSTEM_WOKE), NULL); custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_ENTERED), NULL); custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_EXITED), NULL); + custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_ENTERED_GLOBAL), NULL); + custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_EXITED_GLOBAL), NULL); custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_CLICKED), NULL); custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_SYSTEM_WILL_SLEEP), NULL); } diff --git a/src/custom_events.h b/src/custom_events.h index 5136fb6..6dc01a9 100644 --- a/src/custom_events.h +++ b/src/custom_events.h @@ -1,15 +1,6 @@ #pragma once #include "misc/helpers.h" -#define UPDATE_FRONT_APP_SWITCHED 1ULL -#define UPDATE_SPACE_CHANGE 1ULL << 1 -#define UPDATE_DISPLAY_CHANGE 1ULL << 2 -#define UPDATE_SYSTEM_WOKE 1ULL << 3 -#define UPDATE_MOUSE_ENTERED 1ULL << 4 -#define UPDATE_MOUSE_EXITED 1ULL << 5 -#define UPDATE_MOUSE_CLICKED 1ULL << 6 -#define UPDATE_SYSTEM_WILL_SLEEP 1ULL << 7 - extern void* g_workspace_context; extern void workspace_create_custom_observer(void** context, char* name); diff --git a/src/event.c b/src/event.c index 69913a3..ee69612 100644 --- a/src/event.c +++ b/src/event.c @@ -145,6 +145,10 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_ENTERED) { struct bar* bar = bar_manager_get_bar_by_wid(&g_bar_manager, wid); if (bar) { // Handle global mouse entered event + if (!bar->mouse_over) { + bar->mouse_over = true; + bar_manager_handle_mouse_entered_global(&g_bar_manager); + } CFRelease(context); return EVENT_SUCCESS; @@ -173,6 +177,13 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_EXITED) { struct bar* bar = bar_manager_get_bar_by_wid(&g_bar_manager, wid); if (bar) { // Handle global mouse exited event + CGPoint point = CGEventGetLocation(context); + CGRect frame = bar->window.frame; + frame.origin = bar->window.origin; + if (!CGRectContainsPoint(frame, point)) { + bar->mouse_over = false; + bar_manager_handle_mouse_exited_global(&g_bar_manager); + } CFRelease(context); return EVENT_SUCCESS; diff --git a/src/misc/defines.h b/src/misc/defines.h index d6bb57e..c79031d 100644 --- a/src/misc/defines.h +++ b/src/misc/defines.h @@ -93,6 +93,8 @@ #define COMMAND_SUBSCRIBE_MOUSE_ENTERED "mouse.entered" #define COMMAND_SUBSCRIBE_MOUSE_EXITED "mouse.exited" #define COMMAND_SUBSCRIBE_MOUSE_CLICKED "mouse.clicked" +#define COMMAND_SUBSCRIBE_MOUSE_ENTERED_GLOBAL "mouse.entered.global" +#define COMMAND_SUBSCRIBE_MOUSE_EXITED_GLOBAL "mouse.exited.global" #define DOMAIN_QUERY "--query" #define COMMAND_QUERY_DEFAULT_ITEMS "default_menu_items" From e82f2a96e9c0a80755ba752e671e5a3410fd7df7 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Thu, 9 Jun 2022 19:41:07 +0200 Subject: [PATCH 26/27] whoops --- src/custom_events.c | 4 ++-- src/custom_events.h | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/custom_events.c b/src/custom_events.c index 8e692a8..549063c 100644 --- a/src/custom_events.c +++ b/src/custom_events.c @@ -25,10 +25,10 @@ void custom_events_init(struct custom_events* custom_events) { custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_SYSTEM_WOKE), NULL); custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_ENTERED), NULL); custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_EXITED), NULL); - custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_ENTERED_GLOBAL), NULL); - custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_EXITED_GLOBAL), NULL); custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_CLICKED), NULL); custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_SYSTEM_WILL_SLEEP), NULL); + custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_ENTERED_GLOBAL), NULL); + custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_EXITED_GLOBAL), NULL); } void custom_events_append(struct custom_events* custom_events, char* name, char* notification) { diff --git a/src/custom_events.h b/src/custom_events.h index 6dc01a9..5136fb6 100644 --- a/src/custom_events.h +++ b/src/custom_events.h @@ -1,6 +1,15 @@ #pragma once #include "misc/helpers.h" +#define UPDATE_FRONT_APP_SWITCHED 1ULL +#define UPDATE_SPACE_CHANGE 1ULL << 1 +#define UPDATE_DISPLAY_CHANGE 1ULL << 2 +#define UPDATE_SYSTEM_WOKE 1ULL << 3 +#define UPDATE_MOUSE_ENTERED 1ULL << 4 +#define UPDATE_MOUSE_EXITED 1ULL << 5 +#define UPDATE_MOUSE_CLICKED 1ULL << 6 +#define UPDATE_SYSTEM_WILL_SLEEP 1ULL << 7 + extern void* g_workspace_context; extern void workspace_create_custom_observer(void** context, char* name); From df86156c1a65d2519f65fbf1204698a2b75cc770 Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Thu, 9 Jun 2022 21:14:57 +0200 Subject: [PATCH 27/27] better error responses --- src/alias.c | 18 +++------ src/background.c | 9 ++--- src/bar_item.c | 9 ++--- src/graph.c | 3 +- src/image.c | 3 +- src/message.c | 99 +++++++++++++++++++++------------------------- src/misc/helpers.h | 18 +++++++++ src/misc/log.h | 7 ---- src/popup.c | 6 +-- src/shadow.c | 3 +- src/text.c | 6 +-- 11 files changed, 82 insertions(+), 99 deletions(-) diff --git a/src/alias.c b/src/alias.c index 90ce47b..bac02a4 100644 --- a/src/alias.c +++ b/src/alias.c @@ -8,8 +8,7 @@ void print_all_menu_items(FILE* rsp) { kCGNullWindowID ); int window_count = CFArrayGetCount(window_list); - printf("[\n"); - fprintf(rsp, "[\n"); + respond(rsp, "[\n"); int counter = 0; for (int i = 0; i < window_count; ++i) { CFDictionaryRef dictionary = CFArrayGetValueAtIndex(window_list, i); @@ -42,17 +41,14 @@ void print_all_menu_items(FILE* rsp) { if (strcmp(name, "") == 0) continue; if (counter++ > 0) { - fprintf(rsp, ", \n"); - printf(", \n"); + respond(rsp, ", \n"); } - fprintf(rsp, "\t\"%s,%s\"", owner, name); - printf("\t\"%s,%s\"", owner, name); + respond(rsp, "\t\"%s,%s\"", owner, name); free(owner); free(name); } - printf("\n]\n"); - fprintf(rsp, "\n]\n"); + respond(rsp, "\n]\n"); CFRelease(window_list); } @@ -217,8 +213,7 @@ bool alias_parse_sub_domain(struct alias* alias, FILE* rsp, struct token propert entry, message ); else { - fprintf(rsp, "Invalid subdomain: %s \n", subdom.text); - printf("Invalid subdomain: %s \n", subdom.text); + respond(rsp, "[!] Alias: Invalid subdomain '%s'\n", subdom.text); } } else if (token_equals(property, PROPERTY_COLOR)) { @@ -226,8 +221,7 @@ bool alias_parse_sub_domain(struct alias* alias, FILE* rsp, struct token propert alias->color_override = true; return true; } else { - fprintf(rsp, "Unknown property: %s \n", property.text); - printf("Unknown property: %s \n", property.text); + respond(rsp, "[!] Alias: Invalid property '%s' \n", property.text); } return false; } diff --git a/src/background.c b/src/background.c index 00352ff..696ca57 100644 --- a/src/background.c +++ b/src/background.c @@ -193,10 +193,11 @@ bool background_parse_sub_domain(struct background* background, FILE* rsp, struc background->y_offset, token_to_int(token) ); } - else if (token_equals(property, SUB_DOMAIN_IMAGE)) + else if (token_equals(property, SUB_DOMAIN_IMAGE)) { return image_load(&background->image, token_to_string(get_token(&message)), rsp ); + } else { struct key_value_pair key_value_pair = get_key_value_pair(property.text, '.' ); @@ -211,13 +212,11 @@ bool background_parse_sub_domain(struct background* background, FILE* rsp, struc else if (token_equals(subdom, SUB_DOMAIN_IMAGE)) return image_parse_sub_domain(&background->image, rsp, entry, message); else { - fprintf(rsp, "Invalid subdomain: %s \n", subdom.text); - printf("Invalid subdomain: %s \n", subdom.text); + respond(rsp, "[!] Background: Invalid subdomain '%s'\n", subdom.text); } } else { - fprintf(rsp, "Unknown property: %s \n", property.text); - printf("Unknown property: %s \n", property.text); + respond(rsp, "[!] Background: Invalid property '%s'\n", property.text); } } return needs_refresh; diff --git a/src/bar_item.c b/src/bar_item.c index a8a4c21..90f53a1 100644 --- a/src/bar_item.c +++ b/src/bar_item.c @@ -715,8 +715,7 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE* message ); else { - fprintf(rsp, "Invalid subdomain: %s \n", subdom.text); - printf("Invalid subdomain: %s \n", subdom.text); + respond(rsp, "[!] Item (%s): Invalid subdomain '%s'\n", bar_item->name, subdom.text); } } else if (token_equals(property, PROPERTY_ICON)) { @@ -772,8 +771,7 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE* int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, key_value_pair.value); if (item_index_for_name < 0) { - fprintf(rsp, "Name: %s not found in bar items \n", key_value_pair.value); - printf("Name: %s not found in bar items \n", key_value_pair.value); + respond(rsp, "[!] Item Position (%s): Item '%s' is not a valid popup host\n", bar_item->name, key_value_pair.value); return; } struct bar_item* target_item = g_bar_manager.bar_items[item_index_for_name]; @@ -831,8 +829,7 @@ void bar_item_parse_set_message(struct bar_item* bar_item, char* message, FILE* } else if (token_equals(property, COMMAND_DEFAULT_RESET)) { bar_item_init(&g_bar_manager.default_item, NULL); } else { - fprintf(rsp, "Invalid propery: %s \n", property.text); - printf("Invalid propery: %s \n", property.text); + respond(rsp, "[!] Item (%s): Invalid property '%s' \n", bar_item->name, property.text); } if (needs_refresh) bar_item_needs_update(bar_item); diff --git a/src/graph.c b/src/graph.c index 9a83d9a..49287ca 100644 --- a/src/graph.c +++ b/src/graph.c @@ -143,8 +143,7 @@ bool graph_parse_sub_domain(struct graph* graph, FILE* rsp, struct token propert return true; } else { - fprintf(rsp, "Unknown property: %s \n", property.text); - printf("Unknown property: %s \n", property.text); + respond(rsp, "[!] Graph: Invalid property '%s'\n", property.text); } return false; } diff --git a/src/image.c b/src/image.c index 3d5ce63..78489e4 100644 --- a/src/image.c +++ b/src/image.c @@ -22,8 +22,7 @@ bool image_set_enabled(struct image* image, bool enabled) { bool image_load(struct image* image, char* path, FILE* rsp) { char* res_path = resolve_path(path); if (!file_exists(res_path)) { - printf("File %s not found!\n", res_path); - fprintf(rsp, "File %s not found!\n", res_path); + respond(rsp, "[!] Image: File '%s' not found\n", res_path); free(res_path); return false; } diff --git a/src/message.c b/src/message.c index 0101f21..1bb346c 100644 --- a/src/message.c +++ b/src/message.c @@ -10,7 +10,10 @@ static void handle_domain_subscribe(FILE* rsp, struct token domain, char* messag int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, name.text ); - if (item_index_for_name < 0) return; + if (item_index_for_name < 0) { + respond(rsp, "[!] Subscribe: Item not found '%s'\n", name.text); + return; + } struct bar_item* bar_item = g_bar_manager.bar_items[item_index_for_name]; bar_item_parse_subscribe_message(bar_item, message); @@ -42,7 +45,11 @@ static void handle_domain_push(FILE* rsp, struct token domain, char* message) { int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, name.text ); - if (item_index_for_name < 0) return; + + if (item_index_for_name < 0) { + respond(rsp, "[!] Push: Item '%s' not found", name.text); + return; + } struct bar_item* bar_item = g_bar_manager.bar_items[item_index_for_name]; graph_push_back(&bar_item->graph, token_to_float(y)); bar_item_needs_update(bar_item); @@ -56,11 +63,8 @@ static void handle_domain_rename(FILE* rsp, struct token domain, char* message) int item_index_for_new_name = bar_manager_get_item_index_for_name(&g_bar_manager, new_name.text); if (item_index_for_old_name < 0 || item_index_for_new_name >= 0) { - fprintf(rsp, "Could not rename item: %s -> %s \n", old_name.text, - new_name.text); - - printf("Could not rename item: %s -> %s \n", old_name.text, - new_name.text); + respond(rsp, "[!] Rename: Failed to rename item: %s -> %s\n", old_name.text, + new_name.text); return; } bar_item_set_name(g_bar_manager.bar_items[item_index_for_old_name], @@ -79,13 +83,12 @@ static void handle_domain_clone(FILE* rsp, struct token domain, char* message) { if (parent_index >= 0) parent_item = g_bar_manager.bar_items[parent_index]; else { - printf("Parent Item: %s does not exist \n", parent.text); - fprintf(rsp, "Parent Item: %s does not exist \n", parent.text); + respond(rsp, "[!] Clone: Parent Item '%s' not found\n", parent.text); return; } if (bar_manager_get_item_index_for_name(&g_bar_manager, name.text) >= 0) { - fprintf(rsp, "Item %s already exists \n", name.text); + respond(rsp, "[?] Clone: Item '%s' already exists\n", name.text); return; } struct bar_item* bar_item = bar_manager_create_item(&g_bar_manager); @@ -117,7 +120,7 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) { struct token position = get_token(&message); if (bar_manager_get_item_index_for_name(&g_bar_manager, name.text) >= 0) { - fprintf(rsp, "Item %s already exists \n", name.text); + respond(rsp, "[?] Add: Item '%s' already exists\n", name.text); return; } struct bar_item* bar_item = bar_manager_create_item(&g_bar_manager); @@ -153,15 +156,13 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) { if (index >= 0) group_add_member(bar_item->group, g_bar_manager.bar_items[index]); else { - printf("Item %s not found! \n", member.text); - fprintf(rsp, "Item %s not found! \n", member.text); + respond(rsp, "[?] Add (Group) %s: Failed to add member '%s', item not found\n", bar_item->name, member.text); } member = get_token(&message); } } } else { - printf("Command: %s not found \n", command.text); - fprintf(rsp, "Command: %s not found \n", command.text); + respond(rsp, "[!] Add %s: Invalid item type '%s'\n", bar_item->name, command.text); return; } @@ -172,13 +173,11 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) { int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, key_value_pair.value); if (item_index_for_name < 0) { - fprintf(rsp, - "Parent Name: %s for %s not found in bar items. Placing left instead\n", + respond(rsp, + "[!] Add (Popup) %s: Item '%s' is not a valid popup host\n", + bar_item->name, key_value_pair.value, bar_item->name ); - printf("Parent Name: %s for %s not found in bar items. Placing left instead\n", - key_value_pair.value, - bar_item->name ); free(pair); bar_item_set_position(bar_item, POSITION_LEFT); @@ -265,18 +264,10 @@ static bool handle_domain_bar(FILE *rsp, struct token domain, char *message) { if (position.length > 0) needs_refresh = bar_manager_set_display(&g_bar_manager, position.text[0]); - else { - printf("value for %s must be either 'main' or 'all'.\n", command.text); - fprintf(rsp, "value for %s must be either 'main' or 'all'.\n", command.text); - } } else if (token_equals(command, PROPERTY_POSITION)) { struct token position = get_token(&message); if (position.length > 0) needs_refresh = bar_manager_set_position(&g_bar_manager, position.text[0]); - else { - printf("value for %s must be either 'top' or 'bottom'.\n", command.text); - fprintf(rsp, "value for %s must be either 'top' or 'bottom'.\n", command.text); - } } else needs_refresh = background_parse_sub_domain(&g_bar_manager.background, rsp, command, message); @@ -328,8 +319,7 @@ static void handle_domain_query(FILE* rsp, struct token domain, char* message) { int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, name.text ); if (item_index_for_name < 0) { - fprintf(rsp, "Name: %s not found in bar items \n", name.text); - printf("Name: %s not found in bar items \n", name.text); + respond(rsp, "[!] Query: Item '%s' not found\n", name.text); return; } bar_item_serialize(g_bar_manager.bar_items[item_index_for_name], rsp); @@ -344,8 +334,7 @@ static void handle_domain_query(FILE* rsp, struct token domain, char* message) { int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, name.text ); if (item_index_for_name < 0) { - fprintf(rsp, "Not a valid query, or item: %s not found \n", name.text); - printf("Not a valid query, or item: %s not found \n", name.text); + respond(rsp, "[!] Query: Invalid query, or item '%s' not found \n", name.text); return; } bar_item_serialize(g_bar_manager.bar_items[item_index_for_name], rsp); @@ -367,8 +356,7 @@ static void handle_domain_remove(FILE* rsp, struct token domain, char* message) reti = regcomp(®ex, regstring, 0); free(regstring); if (reti) { - fprintf(rsp, "Could not compile regex: %s \n", name.text); - printf("Could not compile regex: %s \n", name.text); + respond(rsp, "[!] Remove: Could not compile regex '%s'\n", name.text); return; } @@ -384,8 +372,7 @@ static void handle_domain_remove(FILE* rsp, struct token domain, char* message) else if (reti != REG_NOMATCH) { char buf[100]; regerror(reti, ®ex, buf, sizeof(buf)); - fprintf(rsp, "Regex match failed: %s\n", buf); - printf("Regex match failed: %s\n", buf); + respond(rsp, "[!] Remove: Regex match failed '%s'\n", buf); return; } } @@ -395,8 +382,7 @@ static void handle_domain_remove(FILE* rsp, struct token domain, char* message) int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, name.text ); if (item_index_for_name < 0) { - fprintf(rsp, "Name: %s not found in bar items \n", name.text); - printf("Name: %s not found in bar items \n", name.text); + respond(rsp, "[!] Remove: Item '%s' not found\n", name.text); return; } bar_items = realloc(bar_items, sizeof(struct bar_item*)); @@ -420,8 +406,7 @@ static void handle_domain_move(FILE* rsp, struct token domain, char* message) { int item_index = bar_manager_get_item_index_for_name(&g_bar_manager, name.text); int reference_item_index = bar_manager_get_item_index_for_name(&g_bar_manager, reference.text); if (item_index < 0 || reference_item_index < 0) { - fprintf(rsp, "Name: %s or %s not found in bar items \n", name.text, reference.text); - printf("Name: %s or %s not found in bar items \n", name.text, reference.text); + respond(rsp, "[!] Move: Item '%s' or '%s' not found\n", name.text, reference.text); return; } @@ -442,8 +427,7 @@ static void handle_domain_order(FILE* rsp, struct token domain, char* message) { while (name.text && name.length > 0) { int index = bar_manager_get_item_index_for_name(&g_bar_manager, name.text); if (index < 0) { - fprintf(rsp, "Item: %s does not exist in bar items.\n", name.text); - printf("Item: %s does not exist in bar items.\n", name.text); + respond(rsp, "[!] Order: Item '%s' not found\n", name.text); name = get_token(&message); continue; } @@ -490,8 +474,7 @@ void handle_message_mach(struct mach_buffer* buffer) { reti = regcomp(®ex, regstring, 0); free(regstring); if (reti) { - fprintf(rsp, "Could not compile regex: %s \n", name.text); - printf("Could not compile regex: %s \n", name.text); + respond(rsp, "[!] Set: Could not compile regex '%s'\n", name.text); break; } @@ -505,10 +488,9 @@ void handle_message_mach(struct mach_buffer* buffer) { bar_items[count - 1] = bar_item; } else if (reti != REG_NOMATCH) { - char buf[100]; - regerror(reti, ®ex, buf, sizeof(buf)); - fprintf(rsp, "Regex match failed: %s\n", buf); - printf("Regex match failed: %s\n", buf); + char buf[1024]; + regerror(reti, ®ex, buf, sizeof(char)*1024); + respond(rsp, "[?] Set: No match found for regex '%s'\n", name.text); break; } } @@ -517,8 +499,7 @@ void handle_message_mach(struct mach_buffer* buffer) { else { int item_index_for_name = bar_manager_get_item_index_for_name(&g_bar_manager, name.text); if (item_index_for_name < 0) { - fprintf(rsp, "Name: %s not found in bar items \n", name.text); - printf("Name: %s not found in bar items \n", name.text); + respond(rsp, "[!] Set: Item not found '%s'\n", name.text); break; } bar_items = realloc(bar_items, sizeof(struct bar_item*)); @@ -533,7 +514,10 @@ void handle_message_mach(struct mach_buffer* buffer) { struct token tmp = {string_copy(token.text), token.length}; char* rbr_msg = reformat_batch_key_value_pair(tmp); free(tmp.text); - if (!rbr_msg) break; + if (!rbr_msg) { + respond(rsp, "[!] Set (%s): Expected = pair, but got: '%s'\n", bar_items[i]->name, token.text); + break; + } bar_item_parse_set_message(bar_items[i], rbr_msg, rsp); free(rbr_msg); } @@ -545,7 +529,10 @@ void handle_message_mach(struct mach_buffer* buffer) { struct token token = get_token(&message); while (token.text && token.length > 0) { char* rbr_msg = reformat_batch_key_value_pair(token); - if (!rbr_msg) break; + if (!rbr_msg) { + respond(rsp, "[!] Set (default): Expected = pair, but got: '%s'\n", token.text); + break; + } handle_domain_default(rsp, command, rbr_msg); free(rbr_msg); if (message && message[0] == '-') break; @@ -558,7 +545,10 @@ void handle_message_mach(struct mach_buffer* buffer) { struct token token = get_token(&message); while (token.text && token.length > 0) { char* rbr_msg = reformat_batch_key_value_pair(token); - if (!rbr_msg) break; + if (!rbr_msg) { + respond(rsp, "[!] Bar: Expected = pair, but got: '%s'\n", token.text); + break; + } bar_needs_refresh |= handle_domain_bar(rsp, command, rbr_msg); free(rbr_msg); if (message && message[0] == '-') break; @@ -614,8 +604,7 @@ void handle_message_mach(struct mach_buffer* buffer) { exit(0); } else { char* rbr_msg = get_batch_line(&message); - fprintf(rsp, "unknown domain %s\n", command.text); - printf("unknown domain %s\n", command.text); + respond(rsp, "[!] Unknown domain '%s'\n", command.text); free(rbr_msg); } command = get_token(&message); diff --git a/src/misc/helpers.h b/src/misc/helpers.h index a1cab25..5244b44 100644 --- a/src/misc/helpers.h +++ b/src/misc/helpers.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "env_vars.h" #include "defines.h" @@ -54,6 +55,23 @@ static inline void notification_destroy(struct notification* notification) { free(notification); } +static inline void respond(FILE* rsp, char* response, ...) { + time_t t = time(NULL); + struct tm ltime = *localtime(&t); + printf("[%d-%02d-%02d %02d:%02d:%02d] ", ltime.tm_year + 1900, + ltime.tm_mon + 1, + ltime.tm_mday, + ltime.tm_hour, + ltime.tm_min, + ltime.tm_sec ); + + va_list args; + va_start(args, response); + vfprintf(rsp, response, args); + vfprintf(stdout, response, args); + va_end(args); +} + static inline uint32_t hex_from_rgba_color(struct rgba_color rgba_color) { uint32_t result = 0; result += ((uint32_t)(rgba_color.a * 255.0)) << 24; diff --git a/src/misc/log.h b/src/misc/log.h index 8892783..e8a91f3 100644 --- a/src/misc/log.h +++ b/src/misc/log.h @@ -12,13 +12,6 @@ static inline void debug(const char *format, ...) { va_end(args); } -static inline void warn(const char *format, ...) { - va_list args; - va_start(args, format); - vfprintf(stderr, format, args); - va_end(args); -} - static inline void error(const char *format, ...) { va_list args; va_start(args, format); diff --git a/src/popup.c b/src/popup.c index 358fcec..b8c1dfd 100644 --- a/src/popup.c +++ b/src/popup.c @@ -255,13 +255,11 @@ bool popup_parse_sub_domain(struct popup* popup, FILE* rsp, struct token propert entry, message ); else { - fprintf(rsp, "Invalid subdomain: %s \n", subdom.text); - printf("Invalid subdomain: %s \n", subdom.text); + respond(rsp, "[!] Popup: Invalid subdomain '%s'\n", subdom.text); } } else { - fprintf(rsp, "Unknown property: %s \n", property.text); - printf("Unknown property: %s \n", property.text); + respond(rsp, "[!] Popup: Invalid property '%s'\n", property.text); } } return false; diff --git a/src/shadow.c b/src/shadow.c index 5c91de0..5171e11 100644 --- a/src/shadow.c +++ b/src/shadow.c @@ -76,8 +76,7 @@ bool shadow_parse_sub_domain(struct shadow* shadow, FILE* rsp, struct token prop token_to_int(token) ); } else { - fprintf(rsp, "Unknown property: %s \n", property.text); - printf("Unknown property: %s \n", property.text); + respond(rsp, "[!] Shadow: Invalid property '%s'\n", property.text); } return needs_refresh; diff --git a/src/text.c b/src/text.c index 3839428..48b89fd 100644 --- a/src/text.c +++ b/src/text.c @@ -383,13 +383,11 @@ bool text_parse_sub_domain(struct text* text, FILE* rsp, struct token property, else if (token_equals(subdom, SUB_DOMAIN_SHADOW)) return shadow_parse_sub_domain(&text->shadow, rsp, entry, message); else { - fprintf(rsp, "Invalid subdomain: %s \n", subdom.text); - printf("Invalid subdomain: %s \n", subdom.text); + respond(rsp, "[!] Text: Invalid subdomain '%s' \n", subdom.text); } } else { - fprintf(rsp, "Unknown property: %s \n", property.text); - printf("Unknown property: %s \n", property.text); + respond(rsp, "[!] Text: Invalid property '%s'\n", property.text); } }