Merge pull request #1703 from swaywm/layer-keyboard

Give keyboard input to layer surfaces that ask for it
master
Drew DeVault 7 years ago committed by GitHub
commit 447dcd3cb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,7 @@
#ifndef _SWAY_INPUT_SEAT_H #ifndef _SWAY_INPUT_SEAT_H
#define _SWAY_INPUT_SEAT_H #define _SWAY_INPUT_SEAT_H
#include <wlr/types/wlr_layer_shell.h>
#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_seat.h>
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
@ -28,6 +29,9 @@ struct sway_seat {
bool has_focus; bool has_focus;
struct wl_list focus_stack; // list of containers in focus order struct wl_list focus_stack; // list of containers in focus order
// If the focused layer is set, views cannot receive keyboard focus
struct wlr_layer_surface *focused_layer;
struct wl_listener focus_destroy; struct wl_listener focus_destroy;
struct wl_listener new_container; struct wl_listener new_container;
@ -57,6 +61,9 @@ void seat_set_focus(struct sway_seat *seat, struct sway_container *container);
void seat_set_focus_warp(struct sway_seat *seat, void seat_set_focus_warp(struct sway_seat *seat,
struct sway_container *container, bool warp); struct sway_container *container, bool warp);
void seat_set_focus_layer(struct sway_seat *seat,
struct wlr_layer_surface *layer);
struct sway_container *seat_get_focus(struct sway_seat *seat); struct sway_container *seat_get_focus(struct sway_seat *seat);
/** /**

@ -7,6 +7,8 @@
#include <wlr/types/wlr_output_damage.h> #include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/layers.h" #include "sway/layers.h"
#include "sway/output.h" #include "sway/output.h"
#include "sway/server.h" #include "sway/server.h"
@ -187,6 +189,31 @@ void arrange_layers(struct sway_output *output) {
&usable_area, false); &usable_area, false);
arrange_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND], arrange_layer(output, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND],
&usable_area, false); &usable_area, false);
// Find topmost keyboard interactive layer, if such a layer exists
uint32_t layers_above_shell[] = {
ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY,
ZWLR_LAYER_SHELL_V1_LAYER_TOP,
};
size_t nlayers = sizeof(layers_above_shell) / sizeof(layers_above_shell[0]);
struct sway_layer_surface *layer, *topmost = NULL;
for (size_t i = 0; i < nlayers; ++i) {
wl_list_for_each_reverse(layer,
&output->layers[layers_above_shell[i]], link) {
if (layer->layer_surface->current.keyboard_interactive) {
topmost = layer;
break;
}
}
if (topmost != NULL) {
break;
}
}
struct sway_seat *seat;
wl_list_for_each(seat, &input_manager->seats, link) {
seat_set_focus_layer(seat, topmost ? topmost->layer_surface : NULL);
}
} }
static void handle_output_destroy(struct wl_listener *listener, void *data) { static void handle_output_destroy(struct wl_listener *listener, void *data) {

@ -180,13 +180,18 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
double sx, sy; double sx, sy;
struct sway_container *cont = struct sway_container *cont =
container_at_cursor(cursor, &surface, &sx, &sy); container_at_cursor(cursor, &surface, &sx, &sy);
if (surface && wlr_surface_is_layer_surface(surface)) {
struct wlr_layer_surface *layer =
wlr_layer_surface_from_wlr_surface(surface);
if (layer->current.keyboard_interactive) {
seat_set_focus_layer(cursor->seat, layer);
return;
}
}
// Avoid moving keyboard focus from a surface that accepts it to one // Avoid moving keyboard focus from a surface that accepts it to one
// that does not unless the change would move us to a new workspace. // that does not unless the change would move us to a new workspace.
// //
// This prevents, for example, losing focus when clicking on swaybar. // This prevents, for example, losing focus when clicking on swaybar.
//
// TODO: Replace this condition with something like
// !surface_accepts_keyboard_input
if (surface && cont && cont->type != C_VIEW) { if (surface && cont && cont->type != C_VIEW) {
struct sway_container *new_ws = cont; struct sway_container *new_ws = cont;
if (new_ws && new_ws->type != C_WORKSPACE) { if (new_ws && new_ws->type != C_WORKSPACE) {

@ -352,8 +352,11 @@ void seat_configure_xcursor(struct sway_seat *seat) {
void seat_set_focus_warp(struct sway_seat *seat, void seat_set_focus_warp(struct sway_seat *seat,
struct sway_container *container, bool warp) { struct sway_container *container, bool warp) {
struct sway_container *last_focus = seat_get_focus(seat); if (seat->focused_layer) {
return;
}
struct sway_container *last_focus = seat_get_focus(seat);
if (container && last_focus == container) { if (container && last_focus == container) {
return; return;
} }
@ -419,6 +422,37 @@ void seat_set_focus(struct sway_seat *seat,
seat_set_focus_warp(seat, container, true); seat_set_focus_warp(seat, container, true);
} }
void seat_set_focus_layer(struct sway_seat *seat,
struct wlr_layer_surface *layer) {
if (!layer) {
seat->focused_layer = NULL;
return;
}
if (seat->focused_layer == layer) {
return;
}
if (seat->has_focus) {
struct sway_container *focus = seat_get_focus(seat);
if (focus->type == C_VIEW) {
wlr_seat_keyboard_clear_focus(seat->wlr_seat);
view_set_activated(focus->sway_view, false);
}
}
if (layer->layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP) {
seat->focused_layer = layer;
}
struct wlr_keyboard *keyboard =
wlr_seat_get_keyboard(seat->wlr_seat);
if (keyboard) {
wlr_seat_keyboard_notify_enter(seat->wlr_seat,
layer->surface, keyboard->keycodes,
keyboard->num_keycodes, &keyboard->modifiers);
} else {
wlr_seat_keyboard_notify_enter(seat->wlr_seat,
layer->surface, NULL, 0, NULL);
}
}
struct sway_container *seat_get_focus_inactive(struct sway_seat *seat, struct sway_container *seat_get_focus_inactive(struct sway_seat *seat,
struct sway_container *container) { struct sway_container *container) {
return seat_get_focus_by_type(seat, container, C_TYPES); return seat_get_focus_by_type(seat, container, C_TYPES);

Loading…
Cancel
Save