diff --git a/src/event.c b/src/event.c index d2ff27f2..3c6921ee 100644 --- a/src/event.c +++ b/src/event.c @@ -26,6 +26,19 @@ static void window_did_receive_focus(struct window_manager *wm, struct mouse_sta wm->focused_window_id = window->id; wm->focused_window_psn = window->application->psn; ms->ffm_window_id = 0; + + struct view *view = window_manager_find_managed_window(&g_window_manager, window); + if (!view) return; + + struct window_node *node = view_find_window_node(view, window->id); + if (node->window_count <= 1) return; + + for (int i = 0; i < node->window_count; ++i) { + if (node->window_id[i] == window->id) { + node->window_index = i; + break; + } + } } static EVENT_CALLBACK(EVENT_HANDLER_APPLICATION_LAUNCHED) @@ -718,15 +731,19 @@ static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP) uint32_t tmp_window_id[64]; uint32_t tmp_window_count; + int tmp_window_index; memcpy(tmp_window_id, a_node->window_id, sizeof(uint32_t) * a_node->window_count); tmp_window_count = a_node->window_count; + tmp_window_index = a_node->window_index; memcpy(a_node->window_id, b_node->window_id, sizeof(uint32_t) * b_node->window_count); a_node->window_count = b_node->window_count; + a_node->window_index = b_node->window_index; memcpy(b_node->window_id, tmp_window_id, sizeof(uint32_t) * tmp_window_count); b_node->window_count = tmp_window_count; + b_node->window_index = tmp_window_index; a_node->zoom = NULL; b_node->zoom = NULL; diff --git a/src/view.c b/src/view.c index a0a868f7..e54fcd89 100644 --- a/src/view.c +++ b/src/view.c @@ -242,11 +242,13 @@ static void window_node_split(struct view *view, struct window_node *node, struc if (window_node_get_child(node) == CHILD_SECOND) { memcpy(left->window_id, node->window_id, sizeof(uint32_t) * node->window_count); left->window_count = node->window_count; + left->window_index = node->window_index; right->window_id[0] = window->id; right->window_count = 1; } else { memcpy(right->window_id, node->window_id, sizeof(uint32_t) * node->window_count); right->window_count = node->window_count; + right->window_index = node->window_index; left->window_id[0] = window->id; left->window_count = 1; } @@ -255,6 +257,7 @@ static void window_node_split(struct view *view, struct window_node *node, struc right->parent = node; node->window_count = 0; + node->window_index = 0; node->left = left; node->right = right; node->zoom = NULL; @@ -518,6 +521,7 @@ void view_remove_window_node(struct view *view, struct window *window) for (int i = 0; i < node->window_count; ++i) { if (node->window_id[i] == window->id) { node->window_id[i] = node->window_id[--node->window_count]; + if (node->window_index == node->window_count) node->window_index = i; break; } } @@ -526,6 +530,7 @@ void view_remove_window_node(struct view *view, struct window *window) if (node == view->root) { node->window_count = 0; + node->window_index = 0; insert_feedback_destroy(node); node->split = SPLIT_NONE; node->child = CHILD_NONE; @@ -542,6 +547,8 @@ void view_remove_window_node(struct view *view, struct window *window) memcpy(parent->window_id, child->window_id, sizeof(uint32_t) * child->window_count); parent->window_count = child->window_count; + parent->window_index = child->window_index; + parent->left = NULL; parent->right = NULL; parent->zoom = NULL; @@ -714,8 +721,8 @@ void view_serialize(FILE *rsp, struct view *view) space_is_visible(view->sid), view->sid == g_space_manager.current_space_id, space_is_fullscreen(view->sid), - first_leaf ? first_leaf->window_id[0] : 0, - last_leaf ? last_leaf->window_id[0] : 0); + first_leaf ? first_leaf->window_id[first_leaf->window_index] : 0, + last_leaf ? last_leaf->window_id[last_leaf->window_index] : 0); } void view_update(struct view *view) diff --git a/src/view.h b/src/view.h index d1428577..004cd489 100644 --- a/src/view.h +++ b/src/view.h @@ -60,6 +60,7 @@ struct window_node struct window_node *zoom; uint32_t window_id[64]; uint32_t window_count; + int window_index; float ratio; enum window_node_split split; enum window_node_child child; diff --git a/src/window_manager.c b/src/window_manager.c index a1fb8bb1..91e5d2f4 100644 --- a/src/window_manager.c +++ b/src/window_manager.c @@ -638,7 +638,7 @@ struct window *window_manager_find_closest_managed_window_in_direction(struct wi struct window_node *closest = view_find_window_node_in_direction(view, node, direction); if (!closest) return NULL; - return window_manager_find_window(wm, closest->window_id[0]); + return window_manager_find_window(wm, closest->window_id[closest->window_index]); } struct window *window_manager_find_prev_managed_window(struct space_manager *sm, struct window_manager *wm, struct window *window) @@ -652,7 +652,7 @@ struct window *window_manager_find_prev_managed_window(struct space_manager *sm, struct window_node *prev = window_node_find_prev_leaf(node); if (!prev) return NULL; - return window_manager_find_window(wm, prev->window_id[0]); + return window_manager_find_window(wm, prev->window_id[prev->window_index]); } struct window *window_manager_find_next_managed_window(struct space_manager *sm, struct window_manager *wm, struct window *window) @@ -666,7 +666,7 @@ struct window *window_manager_find_next_managed_window(struct space_manager *sm, struct window_node *next = window_node_find_next_leaf(node); if (!next) return NULL; - return window_manager_find_window(wm, next->window_id[0]); + return window_manager_find_window(wm, next->window_id[next->window_index]); } struct window *window_manager_find_first_managed_window(struct space_manager *sm, struct window_manager *wm) @@ -677,7 +677,7 @@ struct window *window_manager_find_first_managed_window(struct space_manager *sm struct window_node *first = window_node_find_first_leaf(view->root); if (!first) return NULL; - return window_manager_find_window(wm, first->window_id[0]); + return window_manager_find_window(wm, first->window_id[first->window_index]); } struct window *window_manager_find_last_managed_window(struct space_manager *sm, struct window_manager *wm) @@ -688,7 +688,7 @@ struct window *window_manager_find_last_managed_window(struct space_manager *sm, struct window_node *last = window_node_find_last_leaf(view->root); if (!last) return NULL; - return window_manager_find_window(wm, last->window_id[0]); + return window_manager_find_window(wm, last->window_id[last->window_index]); } struct window *window_manager_find_recent_managed_window(struct space_manager *sm, struct window_manager *wm) @@ -713,7 +713,7 @@ struct window *window_manager_find_largest_managed_window(struct space_manager * for (struct window_node *node = window_node_find_first_leaf(view->root); node != NULL; node = window_node_find_next_leaf(node)) { uint32_t area = node->area.w * node->area.h; if (area > best_area) { - best_id = node->window_id[0]; + best_id = node->window_id[node->window_index]; best_area = area; } } @@ -732,7 +732,7 @@ struct window *window_manager_find_smallest_managed_window(struct space_manager for (struct window_node *node = window_node_find_first_leaf(view->root); node != NULL; node = window_node_find_next_leaf(node)) { uint32_t area = node->area.w * node->area.h; if (area <= best_area) { - best_id = node->window_id[0]; + best_id = node->window_id[node->window_index]; best_area = area; } } @@ -1038,7 +1038,7 @@ enum window_op_error window_manager_set_window_insertion(struct space_manager *s } node->insert_dir = direction; - view->insertion_point = node->window_id[0]; + view->insertion_point = node->window_id[node->window_index]; insert_feedback_show(node); return WINDOW_OP_ERROR_SUCCESS; @@ -1101,15 +1101,19 @@ enum window_op_error window_manager_warp_window(struct space_manager *sm, struct uint32_t tmp_window_id[64]; uint32_t tmp_window_count; + int tmp_window_index; memcpy(tmp_window_id, a_node->window_id, sizeof(uint32_t) * a_node->window_count); tmp_window_count = a_node->window_count; + tmp_window_index = a_node->window_index; memcpy(a_node->window_id, b_node->window_id, sizeof(uint32_t) * b_node->window_count); a_node->window_count = b_node->window_count; + a_node->window_index = b_node->window_index; memcpy(b_node->window_id, tmp_window_id, sizeof(uint32_t) * tmp_window_count); - b_node->window_count = tmp_window_count;; + b_node->window_count = tmp_window_count; + b_node->window_index = tmp_window_index; a_node->zoom = NULL; b_node->zoom = NULL; @@ -1168,15 +1172,19 @@ enum window_op_error window_manager_swap_window(struct space_manager *sm, struct uint32_t tmp_window_id[64]; uint32_t tmp_window_count; + int tmp_window_index; memcpy(tmp_window_id, a_node->window_id, sizeof(uint32_t) * a_node->window_count); tmp_window_count = a_node->window_count; + tmp_window_index = a_node->window_index; memcpy(a_node->window_id, b_node->window_id, sizeof(uint32_t) * b_node->window_count); a_node->window_count = b_node->window_count; + a_node->window_index = b_node->window_index; memcpy(b_node->window_id, tmp_window_id, sizeof(uint32_t) * tmp_window_count); b_node->window_count = tmp_window_count; + b_node->window_index = tmp_window_index; a_node->zoom = NULL; b_node->zoom = NULL;