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 @@ | |||
1 | #define _XOPEN_SOURCE 700 | 1 | #define _XOPEN_SOURCE 700 |
2 | #define _POSIX_C_SOURCE 199309L | ||
2 | #include <assert.h> | 3 | #include <assert.h> |
4 | #include <time.h> | ||
3 | #include <wlr/types/wlr_cursor.h> | 5 | #include <wlr/types/wlr_cursor.h> |
4 | #include <wlr/types/wlr_output_layout.h> | 6 | #include <wlr/types/wlr_output_layout.h> |
5 | #include <wlr/types/wlr_xcursor_manager.h> | 7 | #include <wlr/types/wlr_xcursor_manager.h> |
@@ -9,6 +11,7 @@ | |||
9 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
10 | #include "sway/input/keyboard.h" | 12 | #include "sway/input/keyboard.h" |
11 | #include "sway/ipc-server.h" | 13 | #include "sway/ipc-server.h" |
14 | #include "sway/layers.h" | ||
12 | #include "sway/output.h" | 15 | #include "sway/output.h" |
13 | #include "sway/tree/container.h" | 16 | #include "sway/tree/container.h" |
14 | #include "sway/tree/view.h" | 17 | #include "sway/tree/view.h" |
@@ -63,7 +66,7 @@ static void seat_send_focus(struct sway_seat *seat, | |||
63 | return; | 66 | return; |
64 | } | 67 | } |
65 | struct sway_view *view = con->sway_view; | 68 | struct sway_view *view = con->sway_view; |
66 | if (view->type == SWAY_XWAYLAND_VIEW) { | 69 | if (view->type == SWAY_VIEW_XWAYLAND) { |
67 | struct wlr_xwayland *xwayland = | 70 | struct wlr_xwayland *xwayland = |
68 | seat->input->server->xwayland; | 71 | seat->input->server->xwayland; |
69 | wlr_xwayland_set_seat(xwayland, seat->wlr_seat); | 72 | wlr_xwayland_set_seat(xwayland, seat->wlr_seat); |
@@ -350,6 +353,12 @@ void seat_configure_xcursor(struct sway_seat *seat) { | |||
350 | seat->cursor->cursor->y); | 353 | seat->cursor->cursor->y); |
351 | } | 354 | } |
352 | 355 | ||
356 | bool seat_is_input_allowed(struct sway_seat *seat, | ||
357 | struct wlr_surface *surface) { | ||
358 | struct wl_client *client = wl_resource_get_client(surface->resource); | ||
359 | return !seat->exclusive_client || seat->exclusive_client == client; | ||
360 | } | ||
361 | |||
353 | void seat_set_focus_warp(struct sway_seat *seat, | 362 | void seat_set_focus_warp(struct sway_seat *seat, |
354 | struct sway_container *container, bool warp) { | 363 | struct sway_container *container, bool warp) { |
355 | if (seat->focused_layer) { | 364 | if (seat->focused_layer) { |
@@ -371,6 +380,12 @@ void seat_set_focus_warp(struct sway_seat *seat, | |||
371 | wl_list_remove(&seat_con->link); | 380 | wl_list_remove(&seat_con->link); |
372 | wl_list_insert(&seat->focus_stack, &seat_con->link); | 381 | wl_list_insert(&seat->focus_stack, &seat_con->link); |
373 | 382 | ||
383 | if (container->type == C_VIEW && !seat_is_input_allowed( | ||
384 | seat, container->sway_view->surface)) { | ||
385 | wlr_log(L_DEBUG, "Refusing to set focus, input is inhibited"); | ||
386 | return; | ||
387 | } | ||
388 | |||
374 | if (container->type == C_VIEW) { | 389 | if (container->type == C_VIEW) { |
375 | seat_send_focus(seat, container); | 390 | seat_send_focus(seat, container); |
376 | } | 391 | } |
@@ -424,11 +439,18 @@ void seat_set_focus(struct sway_seat *seat, | |||
424 | 439 | ||
425 | void seat_set_focus_layer(struct sway_seat *seat, | 440 | void seat_set_focus_layer(struct sway_seat *seat, |
426 | struct wlr_layer_surface *layer) { | 441 | struct wlr_layer_surface *layer) { |
427 | if (!layer) { | 442 | if (!layer && seat->focused_layer) { |
428 | seat->focused_layer = NULL; | 443 | seat->focused_layer = NULL; |
444 | struct sway_container *previous = seat_get_focus(seat); | ||
445 | if (previous) { | ||
446 | wlr_log(L_DEBUG, "Returning focus to %p %s '%s'", previous, | ||
447 | container_type_to_str(previous->type), previous->name); | ||
448 | // Hack to get seat to re-focus the return value of get_focus | ||
449 | seat_set_focus(seat, previous->parent); | ||
450 | seat_set_focus(seat, previous); | ||
451 | } | ||
429 | return; | 452 | return; |
430 | } | 453 | } else if (!layer || seat->focused_layer == layer) { |
431 | if (seat->focused_layer == layer) { | ||
432 | return; | 454 | return; |
433 | } | 455 | } |
434 | if (seat->has_focus) { | 456 | if (seat->has_focus) { |
@@ -453,6 +475,51 @@ void seat_set_focus_layer(struct sway_seat *seat, | |||
453 | } | 475 | } |
454 | } | 476 | } |
455 | 477 | ||
478 | void seat_set_exclusive_client(struct sway_seat *seat, | ||
479 | struct wl_client *client) { | ||
480 | if (!client) { | ||
481 | seat->exclusive_client = client; | ||
482 | // Triggers a refocus of the topmost surface layer if necessary | ||
483 | // TODO: Make layer surface focus per-output based on cursor position | ||
484 | for (int i = 0; i < root_container.children->length; ++i) { | ||
485 | struct sway_container *output = root_container.children->items[i]; | ||
486 | if (!sway_assert(output->type == C_OUTPUT, | ||
487 | "root container has non-output child")) { | ||
488 | continue; | ||
489 | } | ||
490 | arrange_layers(output->sway_output); | ||
491 | } | ||
492 | return; | ||
493 | } | ||
494 | if (seat->focused_layer) { | ||
495 | if (wl_resource_get_client(seat->focused_layer->resource) != client) { | ||
496 | seat_set_focus_layer(seat, NULL); | ||
497 | } | ||
498 | } | ||
499 | if (seat->has_focus) { | ||
500 | struct sway_container *focus = seat_get_focus(seat); | ||
501 | if (focus->type == C_VIEW && wl_resource_get_client( | ||
502 | focus->sway_view->surface->resource) != client) { | ||
503 | seat_set_focus(seat, NULL); | ||
504 | } | ||
505 | } | ||
506 | if (seat->wlr_seat->pointer_state.focused_client) { | ||
507 | if (seat->wlr_seat->pointer_state.focused_client->client != client) { | ||
508 | wlr_seat_pointer_clear_focus(seat->wlr_seat); | ||
509 | } | ||
510 | } | ||
511 | struct timespec now; | ||
512 | clock_gettime(CLOCK_MONOTONIC, &now); | ||
513 | struct wlr_touch_point *point; | ||
514 | wl_list_for_each(point, &seat->wlr_seat->touch_state.touch_points, link) { | ||
515 | if (point->client->client != client) { | ||
516 | wlr_seat_touch_point_clear_focus(seat->wlr_seat, | ||
517 | now.tv_nsec / 1000, point->touch_id); | ||
518 | } | ||
519 | } | ||
520 | seat->exclusive_client = client; | ||
521 | } | ||
522 | |||
456 | struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, | 523 | struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, |
457 | struct sway_container *container) { | 524 | struct sway_container *container) { |
458 | return seat_get_focus_by_type(seat, container, C_TYPES); | 525 | return seat_get_focus_by_type(seat, container, C_TYPES); |