Skip to content

Commit

Permalink
Allow non keyboard_interactive layer surfaces to be focused
Browse files Browse the repository at this point in the history
Layer surfaces can now receive keyboard input while focused. This narrows the gap
between regular views and non-keyboard exclusive layer surfaces which now handle focus
the same way.

This also simultaneously fixes a bug that allowed views under a
keyboard exclusive layer to be resized, moved, and focused.
  • Loading branch information
ErikReider committed May 16, 2023
1 parent 01b0c11 commit 37d1390
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion sway/input/seatop_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,11 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
struct wlr_layer_surface_v1 *layer;
if (surface &&
(layer = wlr_layer_surface_v1_try_from_wlr_surface(surface))) {
if (layer->current.keyboard_interactive) {
if (layer->current.keyboard_interactive
|| !(seat->focused_layer
&& seat->focused_layer->current.keyboard_interactive
&& seat->focused_layer != layer)) {
seat_set_focus(seat, NULL);
seat_set_focus_layer(seat, layer);
transaction_commit_dirty();
}
Expand All @@ -380,6 +384,12 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
return;
}

// Don't change focus and don't send any inputs if there's a focused layer
// with keyboard exclusivity
if (seat->focused_layer && seat->focused_layer->current.keyboard_interactive) {
return;
}

// Handle tiling resize via border
if (cont && resize_edge && button == BTN_LEFT &&
state == WLR_BUTTON_PRESSED && !is_floating) {
Expand Down Expand Up @@ -443,6 +453,9 @@ static void handle_button(struct sway_seat *seat, uint32_t time_msec,
}
}

// Move the focus from the layer non-keyboard exclusive layer
seat_set_focus_layer(seat, NULL);

seat_set_focus(seat, node);
transaction_commit_dirty();
}
Expand Down Expand Up @@ -565,6 +578,11 @@ static void check_focus_follows_mouse(struct sway_seat *seat,
return;
}

// Prevents the layer from losing focus if it has keyboard exclusivity
if (seat->focused_layer && seat->focused_layer->current.keyboard_interactive) {
return;
}

// This is where we handle the common case. We don't want to focus inactive
// tabs, hence the view_is_visible check.
if (node_is_view(hovered_node) &&
Expand All @@ -575,6 +593,9 @@ static void check_focus_follows_mouse(struct sway_seat *seat,
// But if focus_follows_mouse is "always", we do.
if (hovered_node != e->previous_node ||
config->focus_follows_mouse == FOLLOWS_ALWAYS) {
// Move the focus from the layer non-keyboard exclusive layer
seat_set_focus_layer(seat, NULL);

seat_set_focus(seat, hovered_node);
transaction_commit_dirty();
}
Expand Down

0 comments on commit 37d1390

Please sign in to comment.