diff --git a/CHANGELOG.md b/CHANGELOG.md index 58ac3292..8348f96f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- When a new window is added to a stack it is placed after the currently focused window (instead of the end) [#2387](https://github.com/koekeishiya/yabai/issues/2387) ## [7.1.2] - 2024-08-10 ### Changed diff --git a/src/view.c b/src/view.c index 7f076f0b..1bf81c09 100644 --- a/src/view.c +++ b/src/view.c @@ -722,7 +722,20 @@ struct window_node *view_remove_window_node(struct view *view, struct window *wi void view_stack_window_node(struct window_node *node, struct window *window) { - node->window_list[node->window_count] = window->id; + int insert_index = node->window_count; + + for (int i = 0; i < node->window_count; ++i) { + if (node->window_list[i] == node->window_order[0]) { + insert_index = i+1; + break; + } + } + + if (insert_index < node->window_count) { + memmove(node->window_list + insert_index + 1, node->window_list + insert_index, sizeof(uint32_t) * (node->window_count - insert_index)); + } + + node->window_list[insert_index] = 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;