From 4058ffef0b6fdbdb4abd90e30bc63f31024df50b Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Thu, 1 Jun 2023 09:01:49 +0200 Subject: [PATCH] fix aliases not updating properly when the parent application is restarted (#377) --- src/alias.c | 7 ++++++- src/window.c | 5 ++++- src/window.h | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/alias.c b/src/alias.c index 1f52037..88b1f2b 100644 --- a/src/alias.c +++ b/src/alias.c @@ -158,9 +158,14 @@ static bool alias_update_image(struct alias* alias, bool forced) { if (alias->window.id == 0) alias_find_window(alias); if (alias->window.id == 0) return false; - CGImageRef image_ref = window_capture(&alias->window); + bool disabled = false; + CGImageRef image_ref = window_capture(&alias->window, &disabled); if (!image_ref) { + if (!disabled) { + alias->window.id = 0; + image_destroy(&alias->image); + } return false; } diff --git a/src/window.c b/src/window.c index 91550eb..f1e4619 100644 --- a/src/window.c +++ b/src/window.c @@ -241,18 +241,21 @@ void window_disable_shadow(struct window* window) { CFRelease(shadow_props_cf); } -CGImageRef window_capture(struct window* window) { +CGImageRef window_capture(struct window* window, bool* disabled) { if (g_disable_capture) { int64_t time = clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW_APPROX); if (g_disable_capture < 0) { + *disabled = true; return NULL; } else if (time - g_disable_capture > (1ULL << 30)) { g_disable_capture = 0; } else { + *disabled = true; return NULL; } } + *disabled = false; CGImageRef image_ref = NULL; uint64_t wid = window->id; diff --git a/src/window.h b/src/window.h index 1d567c6..1419e29 100644 --- a/src/window.h +++ b/src/window.h @@ -95,7 +95,7 @@ void window_set_level(struct window* window, uint32_t level); void window_order(struct window* window, struct window* parent, int mode); void window_assign_mouse_tracking_area(struct window* window, CGRect rect); -CGImageRef window_capture(struct window* window); +CGImageRef window_capture(struct window* window, bool* disabled); void context_set_font_smoothing(CGContextRef context, bool smoothing);