protocol: Add agl-shell-desktop protocol 88/24188/2
authorMarius Vlad <marius.vlad@collabora.com>
Mon, 17 Feb 2020 14:42:27 +0000 (16:42 +0200)
committerMarius Vlad <marius.vlad@collabora.com>
Fri, 6 Mar 2020 16:16:05 +0000 (18:16 +0200)
Protocol intented for use by regular XDG application which want to
tell the compositor to activate another application. This mimics
the activate_app request from agl-shell, and assumes the application is
already started.

Bug-AGL: SPEC-3252

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: I1f7bd1d8d2f7d8f1eedf710aef1bf1046846f9be

meson.build
protocol/agl-shell-desktop.xml [new file with mode: 0644]
src/ivi-compositor.h
src/main.c
src/shell.c

index 37eb26a..aa69218 100644 (file)
@@ -50,6 +50,7 @@ xdg_shell_xml = join_paths(dir_wp_base, 'stable', 'xdg-shell', 'xdg-shell.xml')
 
 protocols = [
   { 'name': 'agl-shell', 'source': 'internal' },
+  { 'name': 'agl-shell-desktop', 'source': 'internal' },
   { 'name': 'xdg-shell', 'source': 'wp-stable' },
 ]
 
@@ -122,7 +123,9 @@ srcs_agl_compositor = [
        'shared/option-parser.c',
        'shared/os-compatibility.c',
        agl_shell_server_protocol_h,
+       agl_shell_desktop_server_protocol_h,
        agl_shell_protocol_c,
+       agl_shell_desktop_protocol_c,
        xdg_shell_protocol_c,
 ]
 
diff --git a/protocol/agl-shell-desktop.xml b/protocol/agl-shell-desktop.xml
new file mode 100644 (file)
index 0000000..076b4f2
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="agl_shell_desktop">
+  <copyright>
+    Copyright © 2020 Collabora, Ltd.
+
+    Permission is hereby granted, free of charge, to any person obtaining a
+    copy of this software and associated documentation files (the "Software"),
+    to deal in the Software without restriction, including without limitation
+    the rights to use, copy, modify, merge, publish, distribute, sublicense,
+    and/or sell copies of the Software, and to permit persons to whom the
+    Software is furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice (including the next
+    paragraph) shall be included in all copies or substantial portions of the
+    Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+    DEALINGS IN THE SOFTWARE.
+  </copyright>
+  <interface name="agl_shell_desktop" version="1">
+    <description summary="Private extension to allow applications activate other apps">
+      This extension can be used by regular application to instruct to compositor
+      to activate or switch to other running (regular) applications. The client
+      is responsbile for filtering their own app_id when receiving application id.
+
+      Note that other (regular) applications can bind to this interface and there is
+      no mechanism to place to restrict or limit that.
+    </description>
+
+    <request name="activate_app">
+      <description summary="make client current window">
+        Ask the compositor to make a toplevel to become the current/focused
+        window for window management purposes.
+
+        See xdg_toplevel.set_app_id from the xdg-shell protocol for a
+        description of app_id.
+      </description>
+      <arg name="app_id" type="string"/>
+      <arg name="output" type="object" interface="wl_output"/>
+    </request>
+  </interface>
+</protocol>
index a01c617..8631477 100644 (file)
 
 #define ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0]))
 
+struct desktop_client {
+       struct wl_resource *resource;
+       struct wl_list link;    /* ivi_compositor::desktop_clients */
+};
+
 struct ivi_compositor {
        struct weston_compositor *compositor;
        struct weston_config *config;
@@ -62,6 +67,7 @@ struct ivi_compositor {
        const struct weston_drm_output_api *drm_api;
 
        struct wl_global *agl_shell;
+       struct wl_global *agl_shell_desktop;
        struct {
                int activate_apps_by_default;   /* switches once xdg top level has been 'created' */
        } quirks;
@@ -72,6 +78,8 @@ struct ivi_compositor {
                bool ready;
        } shell_client;
 
+       struct wl_list desktop_clients; /* desktop_client::link */
+
        struct wl_list outputs; /* ivi_output.link */
        struct wl_list surfaces; /* ivi_surface.link */
 
index e1ebab5..8c4b10b 100644 (file)
@@ -1145,6 +1145,7 @@ int main(int argc, char *argv[])
        wl_list_init(&ivi.outputs);
        wl_list_init(&ivi.surfaces);
        wl_list_init(&ivi.pending_surfaces);
+       wl_list_init(&ivi.desktop_clients);
 
        /* Prevent any clients we spawn getting our stdin */
        os_fd_set_cloexec(STDIN_FILENO);
index 0553f30..9100ad7 100644 (file)
@@ -39,6 +39,7 @@
 #include "shared/os-compatibility.h"
 
 #include "agl-shell-server-protocol.h"
+#include "agl-shell-desktop-server-protocol.h"
 
 static void
 create_black_surface_view(struct ivi_output *output);
@@ -439,6 +440,10 @@ static const struct agl_shell_interface agl_shell_implementation = {
        .activate_app = shell_activate_app,
 };
 
+static const struct agl_shell_desktop_interface agl_shell_desktop_implementation = {
+       .activate_app = shell_activate_app,
+};
+
 static void
 unbind_agl_shell(struct wl_resource *resource)
 {
@@ -526,6 +531,42 @@ bind_agl_shell(struct wl_client *client,
        ivi->shell_client.resource = resource;
 }
 
+static void
+unbind_agl_shell_desktop(struct wl_resource *resource)
+{
+       struct desktop_client *dclient = wl_resource_get_user_data(resource);
+
+       wl_list_remove(&dclient->link);
+       free(dclient);
+}
+
+static void
+bind_agl_shell_desktop(struct wl_client *client,
+                      void *data, uint32_t version, uint32_t id)
+{
+       struct ivi_compositor *ivi = data;
+       struct wl_resource *resource;
+       struct desktop_client *dclient = zalloc(sizeof(*dclient));
+
+       if (!dclient) {
+               wl_client_post_no_memory(client);
+               return;
+       }
+
+       resource = wl_resource_create(client, &agl_shell_desktop_interface,
+                                     version, id);
+       if (!resource) {
+               wl_client_post_no_memory(client);
+               return;
+       }
+
+       wl_resource_set_implementation(resource, &agl_shell_desktop_implementation,
+                                      dclient, unbind_agl_shell_desktop);
+
+       dclient->resource = resource;
+       wl_list_insert(&ivi->desktop_clients, &dclient->link);
+}
+
 int
 ivi_shell_create_global(struct ivi_compositor *ivi)
 {
@@ -537,5 +578,13 @@ ivi_shell_create_global(struct ivi_compositor *ivi)
                return -1;
        }
 
+       ivi->agl_shell_desktop = wl_global_create(ivi->compositor->wl_display,
+                                                 &agl_shell_desktop_interface, 1,
+                                                 ivi, bind_agl_shell_desktop);
+       if (!ivi->agl_shell_desktop) {
+               weston_log("Failed to create wayland global (agl_shell_desktop).\n");
+               return -1;
+       }
+
        return 0;
 }