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
dev
Neil Roberts 11 years ago committed by Kristian Høgsberg
parent e5a1aee694
commit 4237f50e11
  1. 23
      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

Loading…
Cancel
Save