From 6c846d4151e42c0c341add7e3df2799e39bb8b3f Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Thu, 1 Aug 2019 16:42:40 +0200 Subject: [PATCH] #183 fix issue that could cause windows to tile with overlapped region --- CHANGELOG.md | 1 + src/event.c | 4 ++-- src/space_manager.c | 2 +- src/view.c | 35 ++++++++++++----------------------- src/view.h | 2 +- src/window.c | 2 +- src/window_manager.c | 26 +++++++++++++------------- 7 files changed, 31 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e91e46e7..9ace1e08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Exiting mission-control will invalidate the region assigned to Spaces/Views as because a Space may have been dragged to a different monitor [#](https://github.com/koekeishiya/yabai/issues/118) - Application_Launched signal incorrectly fired multiple times due to accessibility retries [#175](https://github.com/koekeishiya/yabai/issues/175) - Global space settings should properly apply again [#176](https://github.com/koekeishiya/yabai/issues/176) +- Fixed an issue that could cause windows to be overlapped when tiled [#183](https://github.com/koekeishiya/yabai/issues/183) ## [1.1.2] - 2019-07-15 ### Changed diff --git a/src/event.c b/src/event.c index 5c5a6e28..311b612c 100644 --- a/src/event.c +++ b/src/event.c @@ -950,8 +950,8 @@ static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) if (!window) window = window_manager_find_window_at_point(&g_window_manager, point); if (window == g_mouse_state.window) window = NULL; - struct window_node *a_node = view_find_window_node(src_view->root, g_mouse_state.window->id); - struct window_node *b_node = window ? view_find_window_node(dst_view->root, window->id) : NULL; + struct window_node *a_node = view_find_window_node(src_view, g_mouse_state.window->id); + struct window_node *b_node = window ? view_find_window_node(dst_view, window->id) : NULL; if (src_view->sid == dst_view->sid) { if (a_node && b_node) { diff --git a/src/space_manager.c b/src/space_manager.c index 40cb8c5a..3f354616 100644 --- a/src/space_manager.c +++ b/src/space_manager.c @@ -360,7 +360,7 @@ void space_manager_toggle_window_split(struct space_manager *sm, struct window * struct view *view = space_manager_find_view(sm, space_manager_active_space()); if (view->layout != VIEW_BSP) return; - struct window_node *node = view_find_window_node(view->root, window->id); + struct window_node *node = view_find_window_node(view, window->id); if (node && window_node_is_intermediate(node)) { node->parent->split = node->parent->split == SPLIT_Y ? SPLIT_X : SPLIT_Y; diff --git a/src/view.c b/src/view.c index f87689ee..f0c878e9 100644 --- a/src/view.c +++ b/src/view.c @@ -325,16 +325,12 @@ struct window_node *view_find_min_depth_leaf_node(struct window_node *node) return NULL; } -struct window_node *view_find_window_node(struct window_node *node, uint32_t window_id) +struct window_node *view_find_window_node(struct view *view, uint32_t window_id) { - if (node->window_id == window_id) return node; - - if (!window_node_is_leaf(node)) { - struct window_node *left = view_find_window_node(node->left, window_id); - if (left) return left; - - struct window_node *right = view_find_window_node(node->right, window_id); - if (right) return right; + struct window_node *node = window_node_find_first_leaf(view->root); + while (node) { + if (node->window_id == window_id) return node; + node = window_node_find_next_leaf(node); } return NULL; @@ -342,7 +338,7 @@ struct window_node *view_find_window_node(struct window_node *node, uint32_t win void view_remove_window_node(struct view *view, struct window *window) { - struct window_node *node = view_find_window_node(view->root, window->id); + struct window_node *node = view_find_window_node(view, window->id); if (!node) return; if (node == view->root) { @@ -387,12 +383,13 @@ void view_add_window_node(struct view *view, struct window *window) struct window_node *leaf = NULL; if (view->insertion_point) { - leaf = view_find_window_node(view->root, view->insertion_point); + leaf = view_find_window_node(view, view->insertion_point); view->insertion_point = 0; } - if (!leaf) leaf = view_find_window_node(view->root, g_window_manager.focused_window_id); + if (!leaf) leaf = view_find_window_node(view, g_window_manager.focused_window_id); if (!leaf) leaf = view_find_min_depth_leaf_node(view->root); + struct window *leaf_window = window_manager_find_window(&g_window_manager, leaf->window_id); window_node_split(view, leaf, window); @@ -548,16 +545,8 @@ struct view *view_create(uint64_t sid) void view_clear(struct view *view) { if (view->root) { - if (view->root->left) { - window_node_destroy(view->root->left); - view->root->left = NULL; - } - - if (view->root->right) { - window_node_destroy(view->root->right); - view->root->right = NULL; - } - - view->root->window_id = 0; + if (view->root->left) window_node_destroy(view->root->left); + if (view->root->right) window_node_destroy(view->root->right); + memset(view->root, 0, sizeof(struct window_node)); } } diff --git a/src/view.h b/src/view.h index b7d8387b..02155710 100644 --- a/src/view.h +++ b/src/view.h @@ -103,7 +103,7 @@ struct window_node *window_node_find_last_leaf(struct window_node *root); struct window_node *window_node_find_prev_leaf(struct window_node *node); struct window_node *window_node_find_next_leaf(struct window_node *node); -struct window_node *view_find_window_node(struct window_node *node, uint32_t window_id); +struct window_node *view_find_window_node(struct view *view, uint32_t window_id); void view_remove_window_node(struct view *view, struct window *window); void view_add_window_node(struct view *view, struct window *window); uint32_t *view_find_window_list(struct view *view); diff --git a/src/window.c b/src/window.c index e1287d27..fa5b8a86 100644 --- a/src/window.c +++ b/src/window.c @@ -133,7 +133,7 @@ void window_serialize(FILE *rsp, struct window *window) } struct view *view = window_manager_find_managed_window(&g_window_manager, window); - struct window_node *node = view ? view_find_window_node(view->root, window->id) : NULL; + struct window_node *node = view ? view_find_window_node(view, window->id) : NULL; char split[MAXLEN]; snprintf(split, sizeof(split), "%s", window_node_split_str[node && node->parent ? node->parent->split : 0]); diff --git a/src/window_manager.c b/src/window_manager.c index 1ee3bf0a..47408be9 100644 --- a/src/window_manager.c +++ b/src/window_manager.c @@ -258,7 +258,7 @@ void window_manager_resize_window_relative(struct window_manager *wm, struct win struct window_node *x_fence = NULL; struct window_node *y_fence = NULL; - struct window_node *node = view_find_window_node(view->root, window->id); + struct window_node *node = view_find_window_node(view, window->id); if (!node) return; if (direction & HANDLE_TOP) x_fence = window_node_fence(node, DIR_NORTH); @@ -613,7 +613,7 @@ struct window *window_manager_find_prev_managed_window(struct space_manager *sm, struct view *view = space_manager_find_view(sm, space_manager_active_space()); if (!view) return NULL; - struct window_node *node = view_find_window_node(view->root, window->id); + struct window_node *node = view_find_window_node(view, window->id); if (!node) return NULL; struct window_node *prev = window_node_find_prev_leaf(node); @@ -627,7 +627,7 @@ struct window *window_manager_find_next_managed_window(struct space_manager *sm, struct view *view = space_manager_find_view(sm, space_manager_active_space()); if (!view) return NULL; - struct window_node *node = view_find_window_node(view->root, window->id); + struct window_node *node = view_find_window_node(view, window->id); if (!node) return NULL; struct window_node *prev = window_node_find_next_leaf(node); @@ -663,7 +663,7 @@ struct window *window_manager_find_recent_managed_window(struct space_manager *s struct view *view = space_manager_find_view(sm, space_manager_active_space()); if (!view) return NULL; - struct window_node *node = view_find_window_node(view->root, wm->last_window_id); + struct window_node *node = view_find_window_node(view, wm->last_window_id); if (!node) return NULL; return window_manager_find_window(wm, node->window_id); @@ -987,11 +987,11 @@ void window_manager_set_window_insertion(struct space_manager *sm, struct window struct view *view = space_manager_find_view(sm, sid); if (view->layout != VIEW_BSP) return; - struct window_node *node = view_find_window_node(view->root, window->id); + struct window_node *node = view_find_window_node(view, window->id); if (!node) return; if (view->insertion_point && view->insertion_point != window->id) { - struct window_node *insert_node = view_find_window_node(view->root, view->insertion_point); + struct window_node *insert_node = view_find_window_node(view, view->insertion_point); if (insert_node) { insert_node->split = SPLIT_NONE; insert_node->child = CHILD_NONE; @@ -1050,10 +1050,10 @@ void window_manager_warp_window(struct space_manager *sm, struct window_manager struct view *b_view = space_manager_find_view(sm, b_sid); if (b_view->layout != VIEW_BSP) return; - struct window_node *a_node = view_find_window_node(a_view->root, a->id); + struct window_node *a_node = view_find_window_node(a_view, a->id); if (!a_node) return; - struct window_node *b_node = view_find_window_node(b_view->root, b->id); + struct window_node *b_node = view_find_window_node(b_view, b->id); if (!b_node) return; if (a_node->parent == b_node->parent) { @@ -1110,10 +1110,10 @@ void window_manager_swap_window(struct space_manager *sm, struct window_manager struct view *b_view = space_manager_find_view(sm, b_sid); if (b_view->layout != VIEW_BSP) return; - struct window_node *a_node = view_find_window_node(a_view->root, a->id); + struct window_node *a_node = view_find_window_node(a_view, a->id); if (!a_node) return; - struct window_node *b_node = view_find_window_node(b_view->root, b->id); + struct window_node *b_node = view_find_window_node(b_view, b->id); if (!b_node) return; a_node->window_id = b->id; @@ -1328,7 +1328,7 @@ void window_manager_toggle_window_parent(struct space_manager *sm, struct window struct view *view = window_manager_find_managed_window(wm, window); if (!view || view->layout != VIEW_BSP) return; - struct window_node *node = view_find_window_node(view->root, window->id); + struct window_node *node = view_find_window_node(view, window->id); if (node->zoom) { float offset = window_node_border_window_offset(window); window_manager_move_window(window, node->area.x + offset, node->area.y + offset); @@ -1347,7 +1347,7 @@ void window_manager_toggle_window_fullscreen(struct space_manager *sm, struct wi struct view *view = window_manager_find_managed_window(wm, window); if (!view || view->layout != VIEW_BSP) return; - struct window_node *node = view_find_window_node(view->root, window->id); + struct window_node *node = view_find_window_node(view, window->id); if (node->zoom) { float offset = window_node_border_window_offset(window); window_manager_move_window(window, node->area.x + offset, node->area.y + offset); @@ -1364,7 +1364,7 @@ void window_manager_toggle_window_fullscreen(struct space_manager *sm, struct wi void window_manager_toggle_window_border(struct window_manager *wm, struct window *window) { struct view *view = window_manager_find_managed_window(wm, window); - struct window_node *node = view ? view_find_window_node(view->root, window->id) : NULL; + struct window_node *node = view ? view_find_window_node(view, window->id) : NULL; if (window->border.enabled) { border_window_hide(window);