mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 16:01:27 +00:00
Implement input-inhibit in sway, swaylock
This commit is contained in:
parent
06fbd51ff5
commit
b7e7794912
|
@ -32,6 +32,9 @@ struct sway_seat {
|
||||||
// If the focused layer is set, views cannot receive keyboard focus
|
// If the focused layer is set, views cannot receive keyboard focus
|
||||||
struct wlr_layer_surface *focused_layer;
|
struct wlr_layer_surface *focused_layer;
|
||||||
|
|
||||||
|
// If exclusive_client is set, no other clients will receive input events
|
||||||
|
struct wl_client *exclusive_client;
|
||||||
|
|
||||||
struct wl_listener focus_destroy;
|
struct wl_listener focus_destroy;
|
||||||
struct wl_listener new_container;
|
struct wl_listener new_container;
|
||||||
|
|
||||||
|
@ -88,4 +91,6 @@ void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config);
|
||||||
|
|
||||||
struct seat_config *seat_get_config(struct sway_seat *seat);
|
struct seat_config *seat_get_config(struct sway_seat *seat);
|
||||||
|
|
||||||
|
bool seat_allow_input(struct sway_seat *seat, struct wlr_surface *surface);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,6 +33,7 @@ struct swaylock_state {
|
||||||
struct wl_display *display;
|
struct wl_display *display;
|
||||||
struct wl_compositor *compositor;
|
struct wl_compositor *compositor;
|
||||||
struct zwlr_layer_shell_v1 *layer_shell;
|
struct zwlr_layer_shell_v1 *layer_shell;
|
||||||
|
struct zwlr_input_inhibit_manager_v1 *input_inhibit_manager;
|
||||||
struct wl_shm *shm;
|
struct wl_shm *shm;
|
||||||
struct wl_list surfaces;
|
struct wl_list surfaces;
|
||||||
struct swaylock_args args;
|
struct swaylock_args args;
|
||||||
|
|
|
@ -22,12 +22,14 @@ wayland_scanner_server = generator(
|
||||||
|
|
||||||
client_protocols = [
|
client_protocols = [
|
||||||
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
|
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
|
||||||
['wlr-layer-shell-unstable-v1.xml']
|
['wlr-layer-shell-unstable-v1.xml'],
|
||||||
|
['wlr-input-inhibitor-unstable-v1.xml']
|
||||||
]
|
]
|
||||||
|
|
||||||
server_protocols = [
|
server_protocols = [
|
||||||
[wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'],
|
[wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'],
|
||||||
['wlr-layer-shell-unstable-v1.xml']
|
['wlr-layer-shell-unstable-v1.xml'],
|
||||||
|
['wlr-input-inhibitor-unstable-v1.xml']
|
||||||
]
|
]
|
||||||
|
|
||||||
client_protos_src = []
|
client_protos_src = []
|
||||||
|
|
67
protocols/wlr-input-inhibitor-unstable-v1.xml
Normal file
67
protocols/wlr-input-inhibitor-unstable-v1.xml
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<protocol name="wlr_input_inhibit_unstable_v1">
|
||||||
|
<copyright>
|
||||||
|
Copyright © 2018 Drew DeVault
|
||||||
|
|
||||||
|
Permission to use, copy, modify, distribute, and sell this
|
||||||
|
software and its documentation for any purpose is hereby granted
|
||||||
|
without fee, provided that the above copyright notice appear in
|
||||||
|
all copies and that both that copyright notice and this permission
|
||||||
|
notice appear in supporting documentation, and that the name of
|
||||||
|
the copyright holders not be used in advertising or publicity
|
||||||
|
pertaining to distribution of the software without specific,
|
||||||
|
written prior permission. The copyright holders make no
|
||||||
|
representations about the suitability of this software for any
|
||||||
|
purpose. It is provided "as is" without express or implied
|
||||||
|
warranty.
|
||||||
|
|
||||||
|
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
||||||
|
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||||
|
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||||
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||||
|
THIS SOFTWARE.
|
||||||
|
</copyright>
|
||||||
|
|
||||||
|
<interface name="zwlr_input_inhibit_manager_v1" version="1">
|
||||||
|
<description summary="inhibits input events to other clients">
|
||||||
|
Clients can use this interface to prevent input events from being sent to
|
||||||
|
any surfaces but its own, which is useful for example in lock screen
|
||||||
|
software. It is assumed that access to this interface will be locked down
|
||||||
|
to whitelisted clients by the compositor.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<request name="get_inhibitor">
|
||||||
|
<description summary="inhibit input to other clients">
|
||||||
|
Activates the input inhibitor. As long as the inhibitor is active, the
|
||||||
|
compositor will not send input events to other clients.
|
||||||
|
</description>
|
||||||
|
<arg name="id" type="new_id" interface="zwlr_input_inhibitor_v1"/>
|
||||||
|
</request>
|
||||||
|
|
||||||
|
<enum name="error">
|
||||||
|
<entry name="already_inhibited" value="0" summary="an input inhibitor is already in use on the compositor"/>
|
||||||
|
</enum>
|
||||||
|
</interface>
|
||||||
|
|
||||||
|
<interface name="zwlr_input_inhibitor_v1" version="1">
|
||||||
|
<description summary="inhibits input to other clients">
|
||||||
|
While this resource exists, input to clients other than the owner of the
|
||||||
|
inhibitor resource will not receive input events. The client that owns
|
||||||
|
this resource will receive all input events normally. The compositor will
|
||||||
|
also disable all of its own input processing (such as keyboard shortcuts)
|
||||||
|
while the inhibitor is active.
|
||||||
|
|
||||||
|
The compositor may continue to send input events to selected clients,
|
||||||
|
such as an on-screen keyboard (via the input-method protocol).
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<request name="destroy" type="destructor">
|
||||||
|
<description summary="destroy the input inhibitor object">
|
||||||
|
Destroy the inhibitor and allow other clients to receive input.
|
||||||
|
</description>
|
||||||
|
</request>
|
||||||
|
</interface>
|
||||||
|
</protocol>
|
|
@ -146,8 +146,10 @@ static void cursor_send_pointer_motion(struct sway_cursor *cursor,
|
||||||
|
|
||||||
// send pointer enter/leave
|
// send pointer enter/leave
|
||||||
if (surface != NULL) {
|
if (surface != NULL) {
|
||||||
|
if (seat_allow_input(cursor->seat, surface)) {
|
||||||
wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
|
wlr_seat_pointer_notify_enter(seat, surface, sx, sy);
|
||||||
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
|
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
wlr_seat_pointer_clear_focus(seat);
|
wlr_seat_pointer_clear_focus(seat);
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,6 +279,14 @@ static void handle_inhibit_deactivate(struct wl_listener *listener, void *data)
|
||||||
struct sway_seat *seat;
|
struct sway_seat *seat;
|
||||||
wl_list_for_each(seat, &input_manager->seats, link) {
|
wl_list_for_each(seat, &input_manager->seats, link) {
|
||||||
seat_set_exclusive_client(seat, NULL);
|
seat_set_exclusive_client(seat, 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#define _XOPEN_SOURCE 700
|
#define _XOPEN_SOURCE 700
|
||||||
|
#define _POSIX_C_SOURCE 199309L
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <time.h>
|
||||||
#include <wlr/types/wlr_cursor.h>
|
#include <wlr/types/wlr_cursor.h>
|
||||||
#include <wlr/types/wlr_output_layout.h>
|
#include <wlr/types/wlr_output_layout.h>
|
||||||
#include <wlr/types/wlr_xcursor_manager.h>
|
#include <wlr/types/wlr_xcursor_manager.h>
|
||||||
|
@ -9,6 +11,7 @@
|
||||||
#include "sway/input/input-manager.h"
|
#include "sway/input/input-manager.h"
|
||||||
#include "sway/input/keyboard.h"
|
#include "sway/input/keyboard.h"
|
||||||
#include "sway/ipc-server.h"
|
#include "sway/ipc-server.h"
|
||||||
|
#include "sway/layers.h"
|
||||||
#include "sway/output.h"
|
#include "sway/output.h"
|
||||||
#include "sway/tree/container.h"
|
#include "sway/tree/container.h"
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
|
@ -350,6 +353,11 @@ void seat_configure_xcursor(struct sway_seat *seat) {
|
||||||
seat->cursor->cursor->y);
|
seat->cursor->cursor->y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool seat_allow_input(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,
|
void seat_set_focus_warp(struct sway_seat *seat,
|
||||||
struct sway_container *container, bool warp) {
|
struct sway_container *container, bool warp) {
|
||||||
if (seat->focused_layer) {
|
if (seat->focused_layer) {
|
||||||
|
@ -371,6 +379,12 @@ void seat_set_focus_warp(struct sway_seat *seat,
|
||||||
wl_list_remove(&seat_con->link);
|
wl_list_remove(&seat_con->link);
|
||||||
wl_list_insert(&seat->focus_stack, &seat_con->link);
|
wl_list_insert(&seat->focus_stack, &seat_con->link);
|
||||||
|
|
||||||
|
if (container->type == C_VIEW && !seat_allow_input(
|
||||||
|
seat, container->sway_view->surface)) {
|
||||||
|
wlr_log(L_DEBUG, "Refusing to set focus, input is inhibited");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (container->type == C_VIEW) {
|
if (container->type == C_VIEW) {
|
||||||
seat_send_focus(seat, container);
|
seat_send_focus(seat, container);
|
||||||
}
|
}
|
||||||
|
@ -426,13 +440,13 @@ void seat_set_focus_layer(struct sway_seat *seat,
|
||||||
struct wlr_layer_surface *layer) {
|
struct wlr_layer_surface *layer) {
|
||||||
if (!layer && seat->focused_layer) {
|
if (!layer && seat->focused_layer) {
|
||||||
seat->focused_layer = NULL;
|
seat->focused_layer = NULL;
|
||||||
struct sway_container *c = seat_get_focus(seat);
|
struct sway_container *previous = seat_get_focus(seat);
|
||||||
if (c) {
|
if (previous) {
|
||||||
wlr_log(L_DEBUG, "Returning focus to %p %s '%s'", c,
|
wlr_log(L_DEBUG, "Returning focus to %p %s '%s'", previous,
|
||||||
container_type_to_str(c->type), c->name);
|
container_type_to_str(previous->type), previous->name);
|
||||||
// Hack to get seat to re-focus the return value of get_focus
|
// Hack to get seat to re-focus the return value of get_focus
|
||||||
seat_set_focus(seat, c->parent);
|
seat_set_focus(seat, previous->parent);
|
||||||
seat_set_focus(seat, c);
|
seat_set_focus(seat, previous);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (!layer || seat->focused_layer == layer) {
|
} else if (!layer || seat->focused_layer == layer) {
|
||||||
|
@ -462,7 +476,47 @@ void seat_set_focus_layer(struct sway_seat *seat,
|
||||||
|
|
||||||
void seat_set_exclusive_client(struct sway_seat *seat,
|
void seat_set_exclusive_client(struct sway_seat *seat,
|
||||||
struct wl_client *client) {
|
struct wl_client *client) {
|
||||||
// TODO
|
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 *seat_get_focus_inactive(struct sway_seat *seat,
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "pool-buffer.h"
|
#include "pool-buffer.h"
|
||||||
#include "cairo.h"
|
#include "cairo.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "wlr-input-inhibitor-unstable-v1-client-protocol.h"
|
||||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||||
|
|
||||||
static void daemonize() {
|
static void daemonize() {
|
||||||
|
@ -71,6 +72,9 @@ static void handle_global(void *data, struct wl_registry *registry,
|
||||||
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
||||||
state->layer_shell = wl_registry_bind(
|
state->layer_shell = wl_registry_bind(
|
||||||
registry, name, &zwlr_layer_shell_v1_interface, 1);
|
registry, name, &zwlr_layer_shell_v1_interface, 1);
|
||||||
|
} else if (strcmp(interface, zwlr_input_inhibit_manager_v1_interface.name) == 0) {
|
||||||
|
state->input_inhibit_manager = wl_registry_bind(
|
||||||
|
registry, name, &zwlr_input_inhibit_manager_v1_interface, 1);
|
||||||
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
} else if (strcmp(interface, wl_output_interface.name) == 0) {
|
||||||
struct swaylock_surface *surface =
|
struct swaylock_surface *surface =
|
||||||
calloc(1, sizeof(struct swaylock_surface));
|
calloc(1, sizeof(struct swaylock_surface));
|
||||||
|
@ -187,6 +191,10 @@ int main(int argc, char **argv) {
|
||||||
wl_registry_add_listener(registry, ®istry_listener, &state);
|
wl_registry_add_listener(registry, ®istry_listener, &state);
|
||||||
wl_display_roundtrip(state.display);
|
wl_display_roundtrip(state.display);
|
||||||
assert(state.compositor && state.layer_shell && state.shm);
|
assert(state.compositor && state.layer_shell && state.shm);
|
||||||
|
if (!state.input_inhibit_manager) {
|
||||||
|
wlr_log(L_ERROR, "Compositor does not support the input inhibitor "
|
||||||
|
"protocol, refusing to run insecurely");
|
||||||
|
}
|
||||||
|
|
||||||
if (wl_list_empty(&state.surfaces)) {
|
if (wl_list_empty(&state.surfaces)) {
|
||||||
wlr_log(L_DEBUG, "Exiting - no outputs to show on.");
|
wlr_log(L_DEBUG, "Exiting - no outputs to show on.");
|
||||||
|
@ -220,6 +228,8 @@ int main(int argc, char **argv) {
|
||||||
wl_display_roundtrip(state.display);
|
wl_display_roundtrip(state.display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zwlr_input_inhibit_manager_v1_get_inhibitor(state.input_inhibit_manager);
|
||||||
|
|
||||||
state.run_display = true;
|
state.run_display = true;
|
||||||
while (wl_display_dispatch(state.display) != -1 && state.run_display) {
|
while (wl_display_dispatch(state.display) != -1 && state.run_display) {
|
||||||
// This space intentionally left blank
|
// This space intentionally left blank
|
||||||
|
|
Loading…
Reference in a new issue