From 4237f50e11826445319864518289ba1733e11223 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 9 Apr 2014 16:33:31 +0100 Subject: [PATCH] Reset focus on unknown seats when restoring focus state The focus_state list on a workspace only contains entries for seats which have a keyboard focus on that workspace. For workspaces that have no surfaces the list will be empty. That means that when a workspace with no surfaces is switched to it would previously leave the keyboard focus unaffected and you could still type in the surface on the old workspace. This patch makes it instead reset the keyboard focus to NULL for seats without a focus_state. It does this by temporarily stealing the compositor's list of seats while it iterates the focus_states. After all of the focus states have been processed any seats remaining in this temporary list have their focus reset. https://bugs.freedesktop.org/show_bug.cgi?id=73905 --- desktop-shell/shell.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index ba5f2f3..b13b224 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -694,8 +694,20 @@ restore_focus_state(struct desktop_shell *shell, struct workspace *ws) { struct focus_state *state, *next; struct weston_surface *surface; + struct wl_list pending_seat_list; + struct weston_seat *seat, *next_seat; + + /* Temporarily steal the list of seats so that we can keep + * track of the seats we've already processed */ + wl_list_init(&pending_seat_list); + wl_list_insert_list(&pending_seat_list, &shell->compositor->seat_list); + wl_list_init(&shell->compositor->seat_list); wl_list_for_each_safe(state, next, &ws->focus_list, link) { + wl_list_remove(&state->seat->link); + wl_list_insert(&shell->compositor->seat_list, + &state->seat->link); + if (state->seat->keyboard == NULL) continue; @@ -703,6 +715,17 @@ restore_focus_state(struct desktop_shell *shell, struct workspace *ws) weston_keyboard_set_focus(state->seat->keyboard, surface); } + + /* For any remaining seats that we don't have a focus state + * for we'll reset the keyboard focus to NULL */ + wl_list_for_each_safe(seat, next_seat, &pending_seat_list, link) { + wl_list_insert(&shell->compositor->seat_list, &seat->link); + + if (state->seat->keyboard == NULL) + continue; + + weston_keyboard_set_focus(seat->keyboard, NULL); + } } static void -- 2.7.4