Skip to content

Commit

Permalink
#203 properly track the focused window in a stack
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jun 28, 2020
1 parent a1027b3 commit 376a437
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
17 changes: 17 additions & 0 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 17 additions & 9 deletions src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 376a437

Please sign in to comment.