From b6ef26fa81cb01a4634de063875fe03fab4c0455 Mon Sep 17 00:00:00 2001 From: project-repo Date: Sat, 20 Mar 2021 17:19:56 +0100 Subject: [PATCH] Leave list of views invariant under cycling --- keybinding.c | 39 ++++++++++++++++++++++++--------------- seat.c | 8 ++++---- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/keybinding.c b/keybinding.c index 25c4135..1c379b3 100644 --- a/keybinding.c +++ b/keybinding.c @@ -608,26 +608,39 @@ keybinding_cycle_views(struct cg_server *server, bool reverse) { server->curr_output->workspaces[server->curr_output->curr_workspace]; struct cg_view *current_view = curr_workspace->focused_tile->view; - struct cg_view *tmp_view, *next_view = NULL; + if(current_view == NULL) { + current_view=wl_container_of(&curr_workspace->views,current_view,link); + } + struct cg_view *it_view, *next_view = NULL; if(reverse) { - wl_list_for_each_reverse(tmp_view, &curr_workspace->views, link) { - if(tmp_view == current_view) { + struct wl_list *it; + it=current_view->link.prev; + while(it != ¤t_view->link) { + if(it == &curr_workspace->views) { + it=it->prev; continue; } - if(!view_is_visible(tmp_view)) { - next_view = tmp_view; + it_view=wl_container_of(it,it_view,link); + if(!view_is_visible(it_view)) { + next_view = it_view; break; } + it=it->prev; } } else { - wl_list_for_each(tmp_view, &curr_workspace->views, link) { - if(tmp_view == current_view) { + struct wl_list *it; + it=current_view->link.next; + while(it != ¤t_view->link) { + if(it == &curr_workspace->views) { + it=it->next; continue; } - if(!view_is_visible(tmp_view)) { - next_view = tmp_view; + it_view=wl_container_of(it,it_view,link); + if(!view_is_visible(it_view)) { + next_view = it_view; break; } + it=it->next; } } @@ -637,13 +650,9 @@ keybinding_cycle_views(struct cg_server *server, bool reverse) { wlr_output_damage_add_box(curr_workspace->output->damage, &curr_workspace->focused_tile->tile); + /* Prevent seat_set_focus from reordering the views */ + curr_workspace->focused_tile->view=wl_container_of(next_view->link.prev,curr_workspace->focused_tile->view,link); seat_set_focus(server->seat, next_view); - /* Move the previous view to the end of the list unless we are focused on - * the desktop*/ - if(!reverse && current_view != NULL) { - wl_list_remove(¤t_view->link); - wl_list_insert(curr_workspace->views.prev, ¤t_view->link); - } } void diff --git a/seat.c b/seat.c index 6e90616..8f63c20 100644 --- a/seat.c +++ b/seat.c @@ -961,11 +961,11 @@ seat_set_focus(struct cg_seat *seat, struct cg_view *view) { #endif { /* Always resize the view, even if prev_view == view */ + struct cg_workspace *curr_workspace = + server->curr_output + ->workspaces[server->curr_output->curr_workspace]; + view_maximize(view, curr_workspace->focused_tile); if(!view_is_visible(view)) { - struct cg_workspace *curr_workspace = - server->curr_output - ->workspaces[server->curr_output->curr_workspace]; - view_maximize(view, curr_workspace->focused_tile); wl_list_remove(&view->link); if(curr_workspace->focused_tile->view != NULL) { wl_list_insert(&curr_workspace->focused_tile->view->link,