Skip to content

Commit

Permalink
koekeishiya#181 window commands utilizing the scripting addition shou…
Browse files Browse the repository at this point in the history
…ld return a non-zero exit code upon failure
  • Loading branch information
koekeishiya authored and unrevre committed Nov 15, 2020
1 parent 0542ab7 commit 1ce77e5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1628,11 +1628,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);
}
Expand All @@ -1641,7 +1647,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);
}
Expand Down
12 changes: 7 additions & 5 deletions src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/window_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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);
Expand All @@ -167,7 +167,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);
Expand Down

0 comments on commit 1ce77e5

Please sign in to comment.