From a4d337485c7bdde1751b2ae752dbf533483520c2 Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Thu, 22 Sep 2022 18:21:36 +0200 Subject: [PATCH] #1311 properly set window order when adding to the top of a stack --- CHANGELOG.md | 1 + src/osax/common.h | 2 +- src/osax/payload.m | 19 +++++++++++++++++++ src/sa.h | 2 +- src/sa.m | 14 ++++++++++++++ src/view.c | 5 +++-- src/window_manager.c | 1 + 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fdc73f0..0419d360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Make window zoom more flexible, allow parent-zoomed window to enter fullscreen and vice versa [#1429](https://github.com/koekeishiya/yabai/issues/1429) - Fix border size issue when moving a window to a different display on macOS Big Sur [#1229](https://github.com/koekeishiya/yabai/issues/1229) - Check Dock.app isFinishedLaunching property before attempting to inject scripting addition [#749](https://github.com/koekeishiya/yabai/issues/749) +- Properly update window ordering when a window is added to the top of a stack [#1311](https://github.com/koekeishiya/yabai/issues/1311) ### Removed - Removed support for macOS High Sierra, Mojave, and Catalina. diff --git a/src/osax/common.h b/src/osax/common.h index d51c0230..656094ab 100644 --- a/src/osax/common.h +++ b/src/osax/common.h @@ -1,7 +1,7 @@ #ifndef SA_COMMON_H #define SA_COMMON_H -#define OSAX_VERSION "2.0.11" +#define OSAX_VERSION "2.0.12" #define OSAX_ATTRIB_DOCK_SPACES 0x01 #define OSAX_ATTRIB_DPPM 0x02 diff --git a/src/osax/payload.m b/src/osax/payload.m index b2ef308e..4ba2c271 100644 --- a/src/osax/payload.m +++ b/src/osax/payload.m @@ -805,6 +805,22 @@ static void do_window_swap_proxy(char *message) CFRelease(transaction); } +static void do_window_order(char *message) +{ + uint32_t a_wid; + unpack(message, a_wid); + if (!a_wid) return; + + int order; + unpack(message, order); + + uint32_t b_wid; + unpack(message, b_wid); + if (!b_wid) return; + + CGSOrderWindow(_connection, a_wid, order, b_wid); +} + static void do_handshake(int sockfd) { uint32_t attrib = 0; @@ -875,6 +891,9 @@ static void handle_message(int sockfd, char *message) case 0x0E: { do_window_swap_proxy(message); } break; + case 0x0F: { + do_window_order(message); + } break; } } diff --git a/src/sa.h b/src/sa.h index dcc12577..49abaa59 100644 --- a/src/sa.h +++ b/src/sa.h @@ -23,7 +23,7 @@ bool scripting_addition_set_sticky(uint32_t wid, bool sticky); bool scripting_addition_set_shadow(uint32_t wid, bool shadow); bool scripting_addition_focus_window(uint32_t wid); bool scripting_addition_scale_window(uint32_t wid, float x, float y, float w, float h); -bool scripting_addition_swap_window_order(uint32_t a_wid, uint32_t b_wid); bool scripting_addition_swap_window_proxy(uint32_t a_wid, uint32_t b_wid, float opacity, int order); +bool scripting_addition_order_window(uint32_t a_wid, int order, uint32_t b_wid); #endif diff --git a/src/sa.m b/src/sa.m index d088b0bc..078edfee 100644 --- a/src/sa.m +++ b/src/sa.m @@ -539,3 +539,17 @@ bool scripting_addition_swap_window_proxy(uint32_t a_wid, uint32_t b_wid, float return scripting_addition_send_bytes(bytes, length); } + +bool scripting_addition_order_window(uint32_t a_wid, int order, uint32_t b_wid) +{ + char bytes[0x100]; + + char length = 2; + pack(bytes, a_wid, length); + pack(bytes, order, length); + pack(bytes, b_wid, length); + bytes[1] = 0x0F; + bytes[0] = length-1; + + return scripting_addition_send_bytes(bytes, length); +} diff --git a/src/view.c b/src/view.c index b717f9da..5279d735 100644 --- a/src/view.c +++ b/src/view.c @@ -681,8 +681,9 @@ struct window_node *view_remove_window_node(struct view *view, struct window *wi void view_stack_window_node(struct view *view, struct window_node *node, struct window *window) { - node->window_list[node->window_count] = window->id; - node->window_order[node->window_count] = window->id; + node->window_list[node->window_count] = window->id; + memmove(node->window_order + 1, node->window_order, sizeof(uint32_t) * node->window_count); + node->window_order[0] = window->id; ++node->window_count; } diff --git a/src/window_manager.c b/src/window_manager.c index d588a27c..239c2f6f 100644 --- a/src/window_manager.c +++ b/src/window_manager.c @@ -1522,6 +1522,7 @@ enum window_op_error window_manager_stack_window(struct space_manager *sm, struc view_stack_window_node(a_view, a_node, b); window_manager_add_managed_window(wm, b, a_view); + scripting_addition_order_window(b->id, 1, a_node->window_order[1]); if (a_node->zoom) { window_manager_animate_window((struct window_capture) { b, a_node->zoom->area.x, a_node->zoom->area.y, a_node->zoom->area.w, a_node->zoom->area.h });