From 4ee6bdf198c068ea3a7acec22f19fb9a144b2cc5 Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Sun, 6 Feb 2022 16:07:29 -0500 Subject: [PATCH] [client] wayland: bind `xdg_activation_v1` when available --- client/displayservers/Wayland/CMakeLists.txt | 1 + client/displayservers/Wayland/activation.c | 42 ++++++++++++++++++++ client/displayservers/Wayland/registry.c | 3 ++ client/displayservers/Wayland/wayland.c | 3 ++ client/displayservers/Wayland/wayland.h | 7 ++++ 5 files changed, 56 insertions(+) create mode 100644 client/displayservers/Wayland/activation.c diff --git a/client/displayservers/Wayland/CMakeLists.txt b/client/displayservers/Wayland/CMakeLists.txt index 96ed131c..735df425 100644 --- a/client/displayservers/Wayland/CMakeLists.txt +++ b/client/displayservers/Wayland/CMakeLists.txt @@ -23,6 +23,7 @@ else() endif() add_library(displayserver_Wayland STATIC + activation.c clipboard.c cursor.c gl.c diff --git a/client/displayservers/Wayland/activation.c b/client/displayservers/Wayland/activation.c new file mode 100644 index 00000000..bd9a39c9 --- /dev/null +++ b/client/displayservers/Wayland/activation.c @@ -0,0 +1,42 @@ +/** + * Looking Glass + * Copyright © 2017-2022 The Looking Glass Authors + * https://looking-glass.io + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "wayland.h" + +#include +#include + +#include "common/debug.h" + +bool waylandActivationInit(void) +{ + if (!wlWm.xdgActivation) + DEBUG_WARN("xdg_activation_v1 not exported by compositor, will not be able " + "to request host focus on behalf of guest applications"); + return true; +} + +void waylandActivationFree(void) +{ + if (wlWm.xdgActivation) + { + xdg_activation_v1_destroy(wlWm.xdgActivation); + } +} diff --git a/client/displayservers/Wayland/registry.c b/client/displayservers/Wayland/registry.c index b988caf6..695f3f24 100644 --- a/client/displayservers/Wayland/registry.c +++ b/client/displayservers/Wayland/registry.c @@ -72,6 +72,9 @@ static void registryGlobalHandler(void * data, struct wl_registry * registry, wlWm.xdgOutputManager = wl_registry_bind(wlWm.registry, name, // we only need v2 to run, but v3 saves a callback &zxdg_output_manager_v1_interface, version > 3 ? 3 : version); + else if (!strcmp(interface, xdg_activation_v1_interface.name)) + wlWm.xdgActivation = wl_registry_bind(wlWm.registry, name, + &xdg_activation_v1_interface, 1); } static void registryGlobalRemoveHandler(void * data, diff --git a/client/displayservers/Wayland/wayland.c b/client/displayservers/Wayland/wayland.c index 256acf99..1917be87 100644 --- a/client/displayservers/Wayland/wayland.c +++ b/client/displayservers/Wayland/wayland.c @@ -89,6 +89,9 @@ static bool waylandInit(const LG_DSInitParams params) if (!waylandRegistryInit()) return false; + if (!waylandActivationInit()) + return false; + if (!waylandIdleInit()) return false; diff --git a/client/displayservers/Wayland/wayland.h b/client/displayservers/Wayland/wayland.h index 78b46c76..ac7774b2 100644 --- a/client/displayservers/Wayland/wayland.h +++ b/client/displayservers/Wayland/wayland.h @@ -47,6 +47,7 @@ #include "wayland-relative-pointer-unstable-v1-client-protocol.h" #include "wayland-idle-inhibit-unstable-v1-client-protocol.h" #include "wayland-xdg-output-unstable-v1-client-protocol.h" +#include "wayland-xdg-activation-v1-client-protocol.h" typedef void (*WaylandPollCallback)(uint32_t events, void * opaque); @@ -180,6 +181,8 @@ struct WaylandDSState struct zwp_idle_inhibit_manager_v1 * idleInhibitManager; struct zwp_idle_inhibitor_v1 * idleInhibitor; + struct xdg_activation_v1 * xdgActivation; + struct wp_viewporter * viewporter; struct wp_viewport * viewport; struct zxdg_output_manager_v1 * xdgOutputManager; @@ -231,6 +234,10 @@ struct WCBState extern struct WaylandDSState wlWm; extern struct WCBState wlCb; +// activation module +bool waylandActivationInit(void); +void waylandActivationFree(void); + // clipboard module bool waylandCBInit(void); void waylandCBRequest(LG_ClipboardData type);