From ef4e833f13e69dced02a169225528f548c98b3f8 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 3 Apr 2018 10:50:16 -0400 Subject: Add wlr_input_inhibitor --- protocol/meson.build | 2 + protocol/wlr-input-inhibitor-unstable-v1.xml | 67 ++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 protocol/wlr-input-inhibitor-unstable-v1.xml (limited to 'protocol') diff --git a/protocol/meson.build b/protocol/meson.build index a41fdec3..b88b4b77 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -31,6 +31,7 @@ protocols = [ 'screenshooter.xml', 'server-decoration.xml', 'wlr-layer-shell-unstable-v1.xml', + 'wlr-input-inhibitor-unstable-v1.xml', ] client_protocols = [ @@ -40,6 +41,7 @@ client_protocols = [ 'idle.xml', 'screenshooter.xml', 'wlr-layer-shell-unstable-v1.xml', + 'wlr-input-inhibitor-unstable-v1.xml', ] wl_protos_src = [] diff --git a/protocol/wlr-input-inhibitor-unstable-v1.xml b/protocol/wlr-input-inhibitor-unstable-v1.xml new file mode 100644 index 00000000..b62d1bb4 --- /dev/null +++ b/protocol/wlr-input-inhibitor-unstable-v1.xml @@ -0,0 +1,67 @@ + + + + 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. + + + + + 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. + + + + + Activates the input inhibitor. As long as the inhibitor is active, the + compositor will not send input events 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). + + + + + Destroy the inhibitor and allow other clients to receive input. + + + + -- cgit v1.2.3 From abfe7923c45c2a1bdb155279b922b112111f3124 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 5 Apr 2018 12:22:19 -0400 Subject: Add wlr_xdg_output_manager --- include/wlr/types/wlr_output_layout.h | 5 + include/wlr/types/wlr_xdg_output.h | 32 ++++++ protocol/meson.build | 1 + rootston/desktop.c | 2 + types/meson.build | 1 + types/wlr_xdg_output.c | 178 ++++++++++++++++++++++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 include/wlr/types/wlr_xdg_output.h create mode 100644 types/wlr_xdg_output.c (limited to 'protocol') diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index 3c150fc0..f2f6e44b 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -32,6 +32,11 @@ struct wlr_output_layout_output { } events; }; +/** + * Creates a wlr_output_layout, which can be used to describing outputs in + * physical space relative to one another, and perform various useful operations + * on that state. + */ struct wlr_output_layout *wlr_output_layout_create(); void wlr_output_layout_destroy(struct wlr_output_layout *layout); diff --git a/include/wlr/types/wlr_xdg_output.h b/include/wlr/types/wlr_xdg_output.h new file mode 100644 index 00000000..27dad2b8 --- /dev/null +++ b/include/wlr/types/wlr_xdg_output.h @@ -0,0 +1,32 @@ +#ifndef WLR_TYPES_WLR_XDG_OUTPUT_H +#define WLR_TYPES_WLR_XDG_OUTPUT_H +#include +#include + +struct wlr_xdg_output { + struct wl_list link; + struct wl_list resources; + + struct wlr_xdg_output_manager *manager; + struct wlr_output_layout_output *layout_output; + + struct wl_listener destroy; +}; + +struct wlr_xdg_output_manager { + struct wl_global *global; + + struct wlr_output_layout *layout; + + struct wl_list outputs; + + struct wl_listener layout_add; + struct wl_listener layout_change; + struct wl_listener layout_destroy; +}; + +struct wlr_xdg_output_manager *wlr_xdg_output_manager_create( + struct wl_display *display, struct wlr_output_layout *layout); +void wlr_xdg_output_manager_destroy(struct wlr_xdg_output_manager *manager); + +#endif diff --git a/protocol/meson.build b/protocol/meson.build index b88b4b77..bdbde96a 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -25,6 +25,7 @@ protocols = [ [wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'], [wl_protocol_dir, 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml'], [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], + [wl_protocol_dir, 'unstable/xdg-output/xdg-output-unstable-v1.xml'], 'gamma-control.xml', 'gtk-primary-selection.xml', 'idle.xml', diff --git a/rootston/desktop.c b/rootston/desktop.c index e9c1ed30..07b80b08 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "rootston/layers.h" #include "rootston/seat.h" @@ -775,6 +776,7 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->config = config; desktop->layout = wlr_output_layout_create(); + wlr_xdg_output_manager_create(server->wl_display, desktop->layout); desktop->layout_change.notify = handle_layout_change; wl_signal_add(&desktop->layout->events.change, &desktop->layout_change); diff --git a/types/meson.build b/types/meson.build index eda5f4e4..7e089d03 100644 --- a/types/meson.build +++ b/types/meson.build @@ -33,6 +33,7 @@ lib_wlr_types = static_library( 'wlr_xcursor_manager.c', 'wlr_xdg_shell_v6.c', 'wlr_xdg_shell.c', + 'wlr_xdg_output.c', ), include_directories: wlr_inc, dependencies: [pixman, xkbcommon, wayland_server, wlr_protos], diff --git a/types/wlr_xdg_output.c b/types/wlr_xdg_output.c new file mode 100644 index 00000000..91c86b2f --- /dev/null +++ b/types/wlr_xdg_output.c @@ -0,0 +1,178 @@ +#include +#include +#include +#include +#include +#include +#include "xdg-output-unstable-v1-protocol.h" + +static void xdg_output_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static const struct zxdg_output_v1_interface xdg_output_implementation = { + .destroy = xdg_output_destroy, +}; + +static void xdg_output_manager_destroy(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static const struct zxdg_output_manager_v1_interface xdg_output_manager_implementation; + +static void xdg_output_send_details(struct wl_resource *resource, + struct wlr_output_layout_output *layout_output) { + zxdg_output_v1_send_logical_position(resource, + layout_output->x, layout_output->y); + zxdg_output_v1_send_logical_size(resource, + (float)layout_output->output->width / layout_output->output->scale, + (float)layout_output->output->height / layout_output->output->scale); + zxdg_output_v1_send_done(resource); +} + +static void xdg_output_manager_get_xdg_output(struct wl_client *client, + struct wl_resource *resource, uint32_t id, struct wl_resource *output) { + assert(wl_resource_instance_of(resource, &zxdg_output_manager_v1_interface, + &xdg_output_manager_implementation)); + + struct wlr_xdg_output_manager *manager = + wl_resource_get_user_data(resource); + struct wlr_output_layout *layout = manager->layout; + struct wlr_output *wlr_output = wlr_output_from_resource(output); + + struct wlr_output_layout_output *layout_output = + wlr_output_layout_get(layout, wlr_output); + assert(layout_output); + + struct wl_resource *output_resource = wl_resource_create(client, + &zxdg_output_v1_interface, wl_resource_get_version(resource), id); + if (!output_resource) { + wl_client_post_no_memory(client); + return; + } + wl_resource_set_implementation(output_resource, + &xdg_output_implementation, NULL, NULL); + xdg_output_send_details(output_resource, layout_output); +} + +static const struct zxdg_output_manager_v1_interface xdg_output_manager_implementation = { + .destroy = xdg_output_manager_destroy, + .get_xdg_output = xdg_output_manager_get_xdg_output, +}; + +static void output_manager_bind(struct wl_client *wl_client, void *data, + uint32_t version, uint32_t id) { + struct wlr_xdg_output_manager *manager = data; + assert(wl_client && manager); + + struct wl_resource *wl_resource = wl_resource_create(wl_client, + &zxdg_output_manager_v1_interface, version, id); + if (wl_resource == NULL) { + wl_client_post_no_memory(wl_client); + return; + } + wl_resource_set_implementation(wl_resource, + &xdg_output_manager_implementation, manager, NULL); +} + +static void destroy_output(struct wlr_xdg_output *output) { + struct wl_resource *resource, *tmp; + wl_resource_for_each_safe(resource, tmp, &output->resources) { + wl_list_remove(wl_resource_get_link(resource)); + wl_list_init(wl_resource_get_link(resource)); + } + wl_list_remove(&output->destroy.link); + wl_list_remove(&output->link); + free(output); +} + +static void handle_output_destroy(struct wl_listener *listener, void *data) { + struct wlr_xdg_output *output = wl_container_of(listener, output, destroy); + destroy_output(output); +} + +static void add_output(struct wlr_xdg_output_manager *manager, + struct wlr_output_layout_output *layout_output) { + struct wlr_xdg_output *output = calloc(1, sizeof(struct wlr_xdg_output)); + wl_list_init(&output->resources); + output->manager = manager; + output->layout_output = layout_output; + output->destroy.notify = handle_output_destroy; + wl_signal_add(&layout_output->events.destroy, &output->destroy); + wl_list_insert(&manager->outputs, &output->link); +} + +static void xdg_output_manager_send_details( + struct wlr_xdg_output_manager *manager) { + struct wlr_xdg_output *output; + wl_list_for_each(output, &manager->outputs, link) { + struct wl_resource *resource; + wl_resource_for_each(resource, &output->resources) { + xdg_output_send_details(resource, output->layout_output); + } + } +} + +static void handle_layout_add(struct wl_listener *listener, void *data) { + struct wlr_xdg_output_manager *manager = + wl_container_of(listener, manager, layout_add); + struct wlr_output_layout_output *layout_output = data; + add_output(manager, layout_output); +} + +static void handle_layout_change(struct wl_listener *listener, void *data) { + struct wlr_xdg_output_manager *manager = + wl_container_of(listener, manager, layout_change); + xdg_output_manager_send_details(manager); +} + +static void handle_layout_destroy(struct wl_listener *listener, void *data) { + struct wlr_xdg_output_manager *manager = + wl_container_of(listener, manager, layout_change); + wlr_xdg_output_manager_destroy(manager); +} + +struct wlr_xdg_output_manager *wlr_xdg_output_manager_create( + struct wl_display *display, struct wlr_output_layout *layout) { + assert(display && layout); + struct wlr_xdg_output_manager *manager = + calloc(1, sizeof(struct wlr_xdg_output_manager)); + if (manager == NULL) { + return NULL; + } + manager->layout = layout; + manager->global = wl_global_create(display, + &zxdg_output_manager_v1_interface, + 1, manager, output_manager_bind); + if (!manager->global) { + free(manager); + return NULL; + } + + wl_list_init(&manager->outputs); + struct wlr_output_layout_output *layout_output; + wl_list_for_each(layout_output, &layout->outputs, link) { + add_output(manager, layout_output); + } + + manager->layout_add.notify = handle_layout_add; + wl_signal_add(&layout->events.add, &manager->layout_add); + manager->layout_change.notify = handle_layout_change; + wl_signal_add(&layout->events.change, &manager->layout_change); + manager->layout_destroy.notify = handle_layout_destroy; + wl_signal_add(&layout->events.destroy, &manager->layout_destroy); + return manager; +} + +void wlr_xdg_output_manager_destroy(struct wlr_xdg_output_manager *manager) { + struct wlr_xdg_output *output, *tmp; + wl_list_for_each_safe(output, tmp, &manager->outputs, link) { + destroy_output(output); + } + wl_list_remove(&manager->layout_add.link); + wl_list_remove(&manager->layout_change.link); + wl_list_remove(&manager->layout_destroy.link); + free(manager); +} -- cgit v1.2.3