mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-21 19:03:12 +00:00
disable alias capture during system animations (#341)
This commit is contained in:
parent
db9fc50a68
commit
2f01d41d4d
7 changed files with 61 additions and 27 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
test
|
||||
bin
|
||||
todo.md
|
||||
notifications.md
|
||||
|
|
47
src/alias.c
47
src/alias.c
|
@ -86,23 +86,6 @@ void alias_init(struct alias* alias) {
|
|||
image_init(&alias->image);
|
||||
}
|
||||
|
||||
void alias_setup(struct alias* alias, char* owner, char* name) {
|
||||
alias->name = name;
|
||||
alias->owner = owner;
|
||||
alias_get_permission(alias);
|
||||
alias_update_image(alias);
|
||||
}
|
||||
|
||||
uint32_t alias_get_length(struct alias* alias) {
|
||||
if (alias->image.image_ref) return alias->image.bounds.size.width;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t alias_get_height(struct alias* alias) {
|
||||
if (alias->image.image_ref) return alias->image.bounds.size.height;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void alias_find_window(struct alias* alias) {
|
||||
CFArrayRef window_list = CGWindowListCopyWindowInfo(kCGWindowListOptionAll,
|
||||
kCGNullWindowID );
|
||||
|
@ -171,7 +154,7 @@ static void alias_find_window(struct alias* alias) {
|
|||
CFRelease(window_list);
|
||||
}
|
||||
|
||||
bool alias_update_image(struct alias* alias) {
|
||||
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;
|
||||
|
||||
|
@ -182,16 +165,36 @@ bool alias_update_image(struct alias* alias) {
|
|||
return false;
|
||||
}
|
||||
|
||||
return image_set_image(&alias->image, image_ref, alias->window.frame, false);
|
||||
return image_set_image(&alias->image,
|
||||
image_ref,
|
||||
alias->window.frame,
|
||||
forced );
|
||||
}
|
||||
|
||||
bool alias_update(struct alias* alias) {
|
||||
void alias_setup(struct alias* alias, char* owner, char* name) {
|
||||
alias->name = name;
|
||||
alias->owner = owner;
|
||||
alias_get_permission(alias);
|
||||
alias_update_image(alias, true);
|
||||
}
|
||||
|
||||
uint32_t alias_get_length(struct alias* alias) {
|
||||
if (alias->image.image_ref) return alias->image.bounds.size.width;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t alias_get_height(struct alias* alias) {
|
||||
if (alias->image.image_ref) return alias->image.bounds.size.height;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool alias_update(struct alias* alias, bool forced) {
|
||||
if (alias->update_frequency == 0) return false;
|
||||
|
||||
alias->counter++;
|
||||
if (alias->counter >= alias->update_frequency) {
|
||||
if (forced || alias->counter >= alias->update_frequency) {
|
||||
alias->counter = 0;
|
||||
if (alias_update_image(alias)) {
|
||||
if (alias_update_image(alias, forced)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,13 +25,12 @@ struct alias {
|
|||
|
||||
void alias_init(struct alias* alias);
|
||||
void alias_setup(struct alias* alias, char* owner, char* name);
|
||||
bool alias_update_image(struct alias* alias);
|
||||
uint32_t alias_get_length(struct alias* alias);
|
||||
uint32_t alias_get_height(struct alias* alias);
|
||||
|
||||
void alias_calculate_bounds(struct alias* alias, uint32_t x, uint32_t y);
|
||||
void alias_draw(struct alias* alias, CGContextRef context);
|
||||
bool alias_update(struct alias* alias);
|
||||
bool alias_update(struct alias* alias, bool forced);
|
||||
void alias_destroy(struct alias* alias);
|
||||
|
||||
void print_all_menu_items(FILE* rsp);
|
||||
|
|
|
@ -440,7 +440,7 @@ void bar_manager_update_alias_components(struct bar_manager* bar_manager, bool f
|
|||
continue;
|
||||
}
|
||||
|
||||
bar_item_update(bar_manager->bar_items[i], NULL, forced, NULL);
|
||||
alias_update(&bar_manager->bar_items[i]->alias, forced);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,7 +520,7 @@ void bar_manager_update(struct bar_manager* bar_manager, bool forced) {
|
|||
|
||||
if (bar_item->has_alias
|
||||
&& bar_item_is_shown(bar_item)
|
||||
&& alias_update(&bar_item->alias)) {
|
||||
&& alias_update(&bar_item->alias, false)) {
|
||||
bar_item_needs_update(bar_item);
|
||||
needs_refresh = true;
|
||||
}
|
||||
|
|
|
@ -116,7 +116,8 @@ void image_copy(struct image* image, CGImageRef source) {
|
|||
bool image_set_image(struct image* image, CGImageRef new_image_ref, CGRect bounds, bool forced) {
|
||||
CFDataRef new_data_ref = CGDataProviderCopyData(CGImageGetDataProvider(new_image_ref));
|
||||
|
||||
if (!forced && image_data_equals(image, new_data_ref)) {
|
||||
if (!forced && image_data_equals(image, new_data_ref)
|
||||
&& CGSizeEqualToSize(image->size, bounds.size) ) {
|
||||
CFRelease(new_data_ref);
|
||||
CGImageRelease(new_image_ref);
|
||||
return false;
|
||||
|
|
|
@ -41,6 +41,7 @@ char g_config_file[4096];
|
|||
char g_lock_file[MAXLEN];
|
||||
bool g_volume_events;
|
||||
bool g_brightness_events;
|
||||
int64_t g_disable_capture = 0;
|
||||
|
||||
static int client_send_message(int argc, char **argv) {
|
||||
if (argc <= 1) {
|
||||
|
@ -198,6 +199,17 @@ static void parse_arguments(int argc, char **argv) {
|
|||
exit(client_send_message(argc, argv));
|
||||
}
|
||||
|
||||
void system_events(uint32_t event, void* data, size_t data_length, void* context) {
|
||||
if (event == 1322) {
|
||||
g_disable_capture = clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW_APPROX);
|
||||
} else if (event == 905) {
|
||||
g_disable_capture = -1;
|
||||
} else {
|
||||
g_disable_capture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
extern CGError SLSRegisterNotifyProc(void* callback, uint32_t event, void* context);
|
||||
int main(int argc, char **argv) {
|
||||
if (argc > 1) parse_arguments(argc, argv);
|
||||
|
||||
|
@ -209,6 +221,12 @@ int main(int argc, char **argv) {
|
|||
if (!event_loop_init(&g_event_loop))
|
||||
error("sketchybar: could not initialize event_loop! abort..\n");
|
||||
|
||||
SLSRegisterNotifyProc((void*)system_events, 904, NULL);
|
||||
SLSRegisterNotifyProc((void*)system_events, 905, NULL);
|
||||
SLSRegisterNotifyProc((void*)system_events, 1401, NULL);
|
||||
SLSRegisterNotifyProc((void*)system_events, 1508, NULL);
|
||||
SLSRegisterNotifyProc((void*)system_events, 1322, NULL);
|
||||
|
||||
workspace_event_handler_init(&g_workspace_context);
|
||||
bar_manager_init(&g_bar_manager);
|
||||
|
||||
|
|
12
src/window.c
12
src/window.c
|
@ -241,7 +241,19 @@ void window_disable_shadow(struct window* window) {
|
|||
CFRelease(shadow_props_cf);
|
||||
}
|
||||
|
||||
extern int64_t g_disable_capture;
|
||||
CGImageRef window_capture(struct window* window) {
|
||||
if (g_disable_capture) {
|
||||
int64_t time = clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW_APPROX);
|
||||
if (g_disable_capture < 0) {
|
||||
return NULL;
|
||||
}
|
||||
else if (time - g_disable_capture > (int64_t)2e9) {
|
||||
g_disable_capture = 0;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
CGImageRef image_ref = NULL;
|
||||
|
||||
uint64_t wid = window->id;
|
||||
|
|
Loading…
Reference in a new issue