Clear keyboard/pointer focus on Move/Resize, window switcher and menu

The previous revert fixed the problem of stuck modifier keys with
keybinds in Blender, but made Firefox show its menu bar with Alt-*
keybinds. This is fundamentally inevitable due to the limitation of
wayland protocol, but at least for the default Alt-Tab keybind for
window switcher, we can mitigate this problem by clearing the keyboard
focus when the window switcher is activated. This is what KWin does, and
we decided to follow that.

So in this commit, keyboard and pointer focus are temporarily cleared
while Move/Resize, window switcher and menu interactions and restored
after them. We slightly deviate from KWin as KWin doesn't clear the
keyboard focus while Move/Resize, but it solves our existing problem
that Firefox shows its menu bar after dragging it with default Alt-Drag
mousebind, and this is what Mutter does.

We considered other solutions, but they don't work well:
1. Send wl_keyboard.{leave,enter} every time keybinds/mousebinds are
   triggered. This solves the Firefox's menu bar problem, but that
   sounds like a workaround and sending unnecessary events every time is
   not desirable.
2. Send release events for both modifiers and keys even when they are
   bound to keybinds. This is what Mutter is doing, but it looks like an
   implementation issue and violates wayland protocol.
This commit is contained in:
tokyo4j 2024-12-29 00:48:55 +09:00 committed by Hiroaki Yamamoto
parent bd7a533dd6
commit bad788ccdd
9 changed files with 139 additions and 54 deletions

View file

@ -1336,8 +1336,9 @@ menu_open_root(struct menu *menu, int x, int y)
menu_configure(menu, (struct wlr_box){.x = x, .y = y});
wlr_scene_node_set_enabled(&menu->scene_tree->node, true);
menu->server->menu_current = menu;
menu->server->input_mode = LAB_INPUT_STATE_MENU;
selected_item = NULL;
seat_focus_override_begin(&menu->server->seat,
LAB_INPUT_STATE_MENU, LAB_CURSOR_DEFAULT);
}
static void
@ -1628,8 +1629,7 @@ menu_execute_item(struct menuitem *item)
*/
struct server *server = item->parent->server;
menu_close(server->menu_current);
server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
cursor_update_focus(server);
seat_focus_override_end(&server->seat);
/*
* We call the actions after closing the menu so that virtual keyboard
@ -1739,7 +1739,7 @@ menu_close_root(struct server *server)
server->menu_current = NULL;
destroy_pipemenus(server);
}
server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
seat_focus_override_end(&server->seat);
}
void