layer_shell: fix reversed precedence check in handle_map

When a new layer surface maps, Sway determines if it should steal focus
by comparing its layer level against the currently focused layer. The
previous check used `focused >= new` to determine whether to switch
focus to new, which allowed lower precedence layers to steal focus from
higher ones.

This latent issue was masked by arrange_layers() coming through
and fixing up the focus state afterwards. However it resulted in a focus
"flicker" where layer-shell surfaces briefly lost focus before having it
restored again almost immediately.

This commit changes the comparison to `<=` so that lower precedence
surfaces do not steal focus from higher precedence surfaces, and there
is no focus flicker.
This commit is contained in:
Scott Leggett 2026-05-30 23:01:28 +08:00 committed by Simon Ser
parent ce72f66c58
commit cff7a88bda

View file

@ -291,7 +291,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
wl_list_for_each(seat, &server.input->seats, link) {
// but only if the currently focused layer has a lower precedence
if (!seat->focused_layer ||
seat->focused_layer->current.layer >= layer_surface->current.layer) {
seat->focused_layer->current.layer <= layer_surface->current.layer) {
seat_set_focus_layer(seat, layer_surface);
}
}