mirror of
https://github.com/labwc/labwc.git
synced 2025-11-01 22:58:47 -04:00
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:
parent
bd7a533dd6
commit
bad788ccdd
9 changed files with 139 additions and 54 deletions
83
src/seat.c
83
src/seat.c
|
|
@ -507,6 +507,14 @@ focus_change_notify(struct wl_listener *listener, void *data)
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* We clear the keyboard focus at the beginning of Move/Resize, window
|
||||
* switcher and opening menus, but don't want to deactivate the view.
|
||||
*/
|
||||
if (server->input_mode != LAB_INPUT_STATE_PASSTHROUGH) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (view != server->active_view) {
|
||||
if (server->active_view) {
|
||||
view_set_activated(server->active_view, false);
|
||||
|
|
@ -656,8 +664,16 @@ seat_reconfigure(struct server *server)
|
|||
}
|
||||
|
||||
static void
|
||||
seat_focus(struct seat *seat, struct wlr_surface *surface, bool is_lock_surface)
|
||||
seat_focus(struct seat *seat, struct wlr_surface *surface,
|
||||
bool replace_exclusive_layer, bool is_lock_surface)
|
||||
{
|
||||
/* Respect layer-shell exclusive keyboard-interactivity. */
|
||||
if (seat->focused_layer && seat->focused_layer->current.keyboard_interactive
|
||||
== ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE
|
||||
&& !replace_exclusive_layer) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Respect session lock. This check is critical, DO NOT REMOVE.
|
||||
* It should also come before the !surface condition, or the
|
||||
|
|
@ -708,18 +724,20 @@ seat_focus(struct seat *seat, struct wlr_surface *surface, bool is_lock_surface)
|
|||
void
|
||||
seat_focus_surface(struct seat *seat, struct wlr_surface *surface)
|
||||
{
|
||||
/* Respect layer-shell exclusive keyboard-interactivity. */
|
||||
if (seat->focused_layer && seat->focused_layer->current.keyboard_interactive
|
||||
== ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) {
|
||||
/* Don't update focus while window switcher, Move/Resize and menu interaction */
|
||||
if (seat->server->osd_state.cycle_view || seat->server->input_mode
|
||||
!= LAB_INPUT_STATE_PASSTHROUGH) {
|
||||
return;
|
||||
}
|
||||
seat_focus(seat, surface, /*is_lock_surface*/ false);
|
||||
seat_focus(seat, surface, /*replace_exclusive_layer*/ false,
|
||||
/*is_lock_surface*/ false);
|
||||
}
|
||||
|
||||
void
|
||||
seat_focus_lock_surface(struct seat *seat, struct wlr_surface *surface)
|
||||
{
|
||||
seat_focus(seat, surface, /*is_lock_surface*/ true);
|
||||
seat_focus(seat, surface, /*replace_exclusive_layer*/ true,
|
||||
/*is_lock_surface*/ true);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -730,7 +748,8 @@ seat_set_focus_layer(struct seat *seat, struct wlr_layer_surface_v1 *layer)
|
|||
desktop_focus_topmost_view(seat->server);
|
||||
return;
|
||||
}
|
||||
seat_focus(seat, layer->surface, /*is_lock_surface*/ false);
|
||||
seat_focus(seat, layer->surface, /*replace_exclusive_layer*/ true,
|
||||
/*is_lock_surface*/ false);
|
||||
seat->focused_layer = layer;
|
||||
}
|
||||
|
||||
|
|
@ -794,3 +813,53 @@ seat_output_layout_changed(struct seat *seat)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
handle_focus_override_surface_destroy(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct seat *seat = wl_container_of(listener, seat,
|
||||
focus_override.surface_destroy);
|
||||
wl_list_remove(&seat->focus_override.surface_destroy.link);
|
||||
seat->focus_override.surface = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
seat_focus_override_begin(struct seat *seat, enum input_mode input_mode,
|
||||
enum lab_cursors cursor_shape)
|
||||
{
|
||||
assert(!seat->focus_override.surface);
|
||||
assert(seat->server->input_mode == LAB_INPUT_STATE_PASSTHROUGH);
|
||||
|
||||
seat->server->input_mode = input_mode;
|
||||
|
||||
seat->focus_override.surface = seat->seat->keyboard_state.focused_surface;
|
||||
if (seat->focus_override.surface) {
|
||||
seat->focus_override.surface_destroy.notify =
|
||||
handle_focus_override_surface_destroy;
|
||||
wl_signal_add(&seat->focus_override.surface->events.destroy,
|
||||
&seat->focus_override.surface_destroy);
|
||||
}
|
||||
|
||||
seat_focus(seat, NULL, /*replace_exclusive_layer*/ false,
|
||||
/*is_lock_surface*/ false);
|
||||
wlr_seat_pointer_clear_focus(seat->seat);
|
||||
cursor_set(seat, cursor_shape);
|
||||
}
|
||||
|
||||
void
|
||||
seat_focus_override_end(struct seat *seat)
|
||||
{
|
||||
seat->server->input_mode = LAB_INPUT_STATE_PASSTHROUGH;
|
||||
|
||||
if (seat->focus_override.surface) {
|
||||
if (!seat->seat->keyboard_state.focused_surface) {
|
||||
seat_focus(seat, seat->focus_override.surface,
|
||||
/*replace_exclusive_layer*/ false,
|
||||
/*is_lock_surface*/ false);
|
||||
}
|
||||
wl_list_remove(&seat->focus_override.surface_destroy.link);
|
||||
seat->focus_override.surface = NULL;
|
||||
}
|
||||
|
||||
cursor_update_focus(seat->server);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue