protocol: Advertise the applications to regular clients
[src/agl-compositor.git] / src / shell.c
index 16b4146..cc7b33b 100644 (file)
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <libweston-6/compositor.h>
-#include <libweston-6/config-parser.h>
+#include <libweston/libweston.h>
+#include <libweston/config-parser.h>
 
 #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);
@@ -49,10 +50,19 @@ insert_black_surface(struct ivi_output *output);
 void
 ivi_set_desktop_surface(struct ivi_surface *surface)
 {
+       struct desktop_client *dclient;
+       struct ivi_compositor *ivi = surface->ivi;
        assert(surface->role == IVI_SURFACE_ROLE_NONE);
 
        surface->role = IVI_SURFACE_ROLE_DESKTOP;
        wl_list_insert(&surface->ivi->surfaces, &surface->link);
+
+       /* advertise to all desktop clients the new surface */
+       wl_list_for_each(dclient, &ivi->desktop_clients, link) {
+               const char *app_id =
+                       weston_desktop_surface_get_app_id(surface->dsurface);
+               agl_shell_desktop_send_application(dclient->resource, app_id);
+       }
 }
 
 void
@@ -89,6 +99,18 @@ ivi_shell_init(struct ivi_compositor *ivi)
        return 0;
 }
 
+static void
+ivi_shell_advertise_xdg_surfaces(struct ivi_compositor *ivi, struct wl_resource *resource)
+{
+       struct ivi_surface *surface;
+
+       wl_list_for_each(surface, &ivi->surfaces, link) {
+               const char *app_id =
+                       weston_desktop_surface_get_app_id(surface->dsurface);
+               agl_shell_desktop_send_application(resource, app_id);
+       }
+}
+
 static void
 client_exec(const char *command, int fd)
 {
@@ -439,6 +461,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 +552,45 @@ 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);
+
+       /* advertise xdg surfaces */
+       ivi_shell_advertise_xdg_surfaces(ivi, resource);
+}
+
 int
 ivi_shell_create_global(struct ivi_compositor *ivi)
 {
@@ -537,5 +602,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;
 }