diff options
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r-- | sway/input/seat.c | 75 |
1 files changed, 71 insertions, 4 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c index 50134aae..e3df6955 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -1,5 +1,7 @@ #define _XOPEN_SOURCE 700 +#define _POSIX_C_SOURCE 199309L #include <assert.h> +#include <time.h> #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_xcursor_manager.h> @@ -9,6 +11,7 @@ #include "sway/input/input-manager.h" #include "sway/input/keyboard.h" #include "sway/ipc-server.h" +#include "sway/layers.h" #include "sway/output.h" #include "sway/tree/container.h" #include "sway/tree/view.h" @@ -63,7 +66,7 @@ static void seat_send_focus(struct sway_seat *seat, return; } struct sway_view *view = con->sway_view; - if (view->type == SWAY_XWAYLAND_VIEW) { + if (view->type == SWAY_VIEW_XWAYLAND) { struct wlr_xwayland *xwayland = seat->input->server->xwayland; wlr_xwayland_set_seat(xwayland, seat->wlr_seat); @@ -350,6 +353,12 @@ void seat_configure_xcursor(struct sway_seat *seat) { seat->cursor->cursor->y); } +bool seat_is_input_allowed(struct sway_seat *seat, + struct wlr_surface *surface) { + struct wl_client *client = wl_resource_get_client(surface->resource); + return !seat->exclusive_client || seat->exclusive_client == client; +} + void seat_set_focus_warp(struct sway_seat *seat, struct sway_container *container, bool warp) { if (seat->focused_layer) { @@ -371,6 +380,12 @@ void seat_set_focus_warp(struct sway_seat *seat, wl_list_remove(&seat_con->link); wl_list_insert(&seat->focus_stack, &seat_con->link); + if (container->type == C_VIEW && !seat_is_input_allowed( + seat, container->sway_view->surface)) { + wlr_log(L_DEBUG, "Refusing to set focus, input is inhibited"); + return; + } + if (container->type == C_VIEW) { seat_send_focus(seat, container); } @@ -424,11 +439,18 @@ void seat_set_focus(struct sway_seat *seat, void seat_set_focus_layer(struct sway_seat *seat, struct wlr_layer_surface *layer) { - if (!layer) { + if (!layer && seat->focused_layer) { seat->focused_layer = NULL; + struct sway_container *previous = seat_get_focus(seat); + if (previous) { + wlr_log(L_DEBUG, "Returning focus to %p %s '%s'", previous, + container_type_to_str(previous->type), previous->name); + // Hack to get seat to re-focus the return value of get_focus + seat_set_focus(seat, previous->parent); + seat_set_focus(seat, previous); + } return; - } - if (seat->focused_layer == layer) { + } else if (!layer || seat->focused_layer == layer) { return; } if (seat->has_focus) { @@ -453,6 +475,51 @@ void seat_set_focus_layer(struct sway_seat *seat, } } +void seat_set_exclusive_client(struct sway_seat *seat, + struct wl_client *client) { + if (!client) { + seat->exclusive_client = client; + // Triggers a refocus of the topmost surface layer if necessary + // TODO: Make layer surface focus per-output based on cursor position + for (int i = 0; i < root_container.children->length; ++i) { + struct sway_container *output = root_container.children->items[i]; + if (!sway_assert(output->type == C_OUTPUT, + "root container has non-output child")) { + continue; + } + arrange_layers(output->sway_output); + } + return; + } + if (seat->focused_layer) { + if (wl_resource_get_client(seat->focused_layer->resource) != client) { + seat_set_focus_layer(seat, NULL); + } + } + if (seat->has_focus) { + struct sway_container *focus = seat_get_focus(seat); + if (focus->type == C_VIEW && wl_resource_get_client( + focus->sway_view->surface->resource) != client) { + seat_set_focus(seat, NULL); + } + } + if (seat->wlr_seat->pointer_state.focused_client) { + if (seat->wlr_seat->pointer_state.focused_client->client != client) { + wlr_seat_pointer_clear_focus(seat->wlr_seat); + } + } + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + struct wlr_touch_point *point; + wl_list_for_each(point, &seat->wlr_seat->touch_state.touch_points, link) { + if (point->client->client != client) { + wlr_seat_touch_point_clear_focus(seat->wlr_seat, + now.tv_nsec / 1000, point->touch_id); + } + } + seat->exclusive_client = client; +} + struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *container) { return seat_get_focus_by_type(seat, container, C_TYPES); |