From 695d32924f03d65c75b4c60767b96da4ae546efd Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Sun, 15 Nov 2020 16:14:37 +0100 Subject: [PATCH] #181 window commands utilizing the scripting addition should return a non-zero exit code upon failure --- CHANGELOG.md | 2 +- src/message.c | 16 ++++++++++++---- src/window_manager.c | 12 +++++++----- src/window_manager.h | 4 ++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2242d53..7ee28f0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Allow *SPACE_SEL* to be used instead of *mission-control index* when specifying config options for a specific space [#705](https://github.com/koekeishiya/yabai/issues/705) - Native fullscreen transitions would freeze on macOS Mojave due to internal API differences between macOS version [#690](https://github.com/koekeishiya/yabai/issues/690) - Report proper error message when trying to use absolute resizing on a managed window [#661](https://github.com/koekeishiya/yabai/issues/661) -- Space commands that utilize the scripting addition should correctly return a non-zero exit code upon failure [#181](https://github.com/koekeishiya/yabai/issues/181) +- Space/Window commands that utilize the scripting addition should correctly return a non-zero exit code upon failure [#181](https://github.com/koekeishiya/yabai/issues/181) ## [3.3.4] - 2020-11-14 ### Changed diff --git a/src/message.c b/src/message.c index 057ccb9e..4bf5091a 100644 --- a/src/message.c +++ b/src/message.c @@ -1712,11 +1712,17 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message) } else if (token_equals(command, COMMAND_WINDOW_LAYER)) { struct token value = get_token(&message); if (token_equals(value, ARGUMENT_WINDOW_LAYER_BELOW)) { - window_manager_set_window_layer(acting_window, LAYER_BELOW); + if (!window_manager_set_window_layer(acting_window, LAYER_BELOW)) { + daemon_fail(rsp, "could not change layer of window with id '%d' due to an error with the scripting-addition.\n", acting_window->id); + } } else if (token_equals(value, ARGUMENT_WINDOW_LAYER_NORMAL)) { - window_manager_set_window_layer(acting_window, LAYER_NORMAL); + if (!window_manager_set_window_layer(acting_window, LAYER_NORMAL)) { + daemon_fail(rsp, "could not change layer of window with id '%d' due to an error with the scripting-addition.\n", acting_window->id); + } } else if (token_equals(value, ARGUMENT_WINDOW_LAYER_ABOVE)) { - window_manager_set_window_layer(acting_window, LAYER_ABOVE); + if (!window_manager_set_window_layer(acting_window, LAYER_ABOVE)) { + daemon_fail(rsp, "could not change layer of window with id '%d' due to an error with the scripting-addition.\n", acting_window->id); + } } else { daemon_fail(rsp, "unknown value '%.*s' given to command '%.*s' for domain '%.*s'\n", value.length, value.text, command.length, command.text, domain.length, domain.text); } @@ -1725,7 +1731,9 @@ static void handle_domain_window(FILE *rsp, struct token domain, char *message) struct token value = get_token(&message); if ((sscanf(value.text, "%f", &opacity) == 1) && in_range_ii(opacity, 0.0f, 1.0f)) { acting_window->opacity = opacity; - window_manager_set_opacity(&g_window_manager, acting_window, opacity); + if (!window_manager_set_opacity(&g_window_manager, acting_window, opacity)) { + daemon_fail(rsp, "could not change opacity of window with id '%d' due to an error with the scripting-addition.\n", acting_window->id); + } } else { daemon_fail(rsp, "unknown value '%.*s' given to command '%.*s' for domain '%.*s'\n", value.length, value.text, command.length, command.text, domain.length, domain.text); } diff --git a/src/window_manager.c b/src/window_manager.c index f52970f2..f105f936 100644 --- a/src/window_manager.c +++ b/src/window_manager.c @@ -461,7 +461,7 @@ void window_manager_set_purify_mode(struct window_manager *wm, enum purify_mode } } -void window_manager_set_opacity(struct window_manager *wm, struct window *window, float opacity) +bool window_manager_set_opacity(struct window_manager *wm, struct window *window, float opacity) { if (opacity == 0.0f) { if (wm->enable_window_opacity) { @@ -471,7 +471,7 @@ void window_manager_set_opacity(struct window_manager *wm, struct window *window } } - scripting_addition_set_opacity(window->id, opacity, wm->window_opacity_duration); + return scripting_addition_set_opacity(window->id, opacity, wm->window_opacity_duration); } void window_manager_set_window_opacity(struct window_manager *wm, struct window *window, float opacity) @@ -508,12 +508,12 @@ void window_manager_set_normal_window_opacity(struct window_manager *wm, float o } } -void window_manager_set_window_layer(struct window *window, int layer) +bool window_manager_set_window_layer(struct window *window, int layer) { - scripting_addition_set_layer(window->id, layer); + bool result = scripting_addition_set_layer(window->id, layer); CFArrayRef window_list = SLSCopyAssociatedWindows(g_connection, window->id); - if (!window_list) return; + if (!window_list) return result; int window_count = CFArrayGetCount(window_list); CFTypeRef query = SLSWindowQueryWindows(g_connection, window_list, window_count); @@ -544,6 +544,8 @@ void window_manager_set_window_layer(struct window *window, int layer) CFRelease(query); CFRelease(iterator); CFRelease(window_list); + + return result; } void window_manager_make_window_topmost(struct window_manager *wm, struct window *window, bool topmost) diff --git a/src/window_manager.h b/src/window_manager.h index c05b212d..992e66e6 100644 --- a/src/window_manager.h +++ b/src/window_manager.h @@ -152,7 +152,7 @@ void window_manager_set_purify_mode(struct window_manager *wm, enum purify_mode void window_manager_set_active_window_opacity(struct window_manager *wm, float opacity); void window_manager_set_normal_window_opacity(struct window_manager *wm, float opacity); void window_manager_set_window_opacity_enabled(struct window_manager *wm, bool enabled); -void window_manager_set_opacity(struct window_manager *wm, struct window *window, float opacity); +bool window_manager_set_opacity(struct window_manager *wm, struct window *window, float opacity); void window_manager_set_window_opacity(struct window_manager *wm, struct window *window, float opacity); void window_manager_set_window_border_enabled(struct window_manager *wm, bool enabled); void window_manager_set_window_border_width(struct window_manager *wm, int width); @@ -173,7 +173,7 @@ void window_manager_purify_window(struct window_manager *wm, struct window *wind void window_manager_make_window_floating(struct space_manager *sm, struct window_manager *wm, struct window *window, bool should_float); void window_manager_make_window_sticky(struct space_manager *sm, struct window_manager *wm, struct window *window, bool should_sticky); void window_manager_make_window_topmost(struct window_manager *wm, struct window *window, bool topmost); -void window_manager_set_window_layer(struct window *window, int layer); +bool window_manager_set_window_layer(struct window *window, int layer); void window_manager_toggle_window_topmost(struct window *window); void window_manager_toggle_window_shadow(struct space_manager *sm, struct window_manager *wm, struct window *window); void window_manager_toggle_window_parent(struct space_manager *sm, struct window_manager *wm, struct window *window);