downstream: ivi-shell-ext: send geometry hints to clients
authorJanos Kovacs <jankovac503@gmail.com>
Sun, 24 Aug 2014 11:46:06 +0000 (14:46 +0300)
committerJanos Kovacs <jankovac503@gmail.com>
Wed, 10 Dec 2014 14:28:04 +0000 (16:28 +0200)
Change-Id: Iacb816def8c2f5daa20529e53b60a2faeb382b8e
Signed-off-by: Janos Kovacs <jankovac503@gmail.com>
ivi-shell/ivi-shell-ext.c

index 2e37fbc..f436422 100644 (file)
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <dlfcn.h>
 #include <linux/input.h>
+#include <limits.h>
 
 #include "ivi-shell-ext.h"
 #include "ivi-shell.h"
 #include "compositor.h"
-#include "ivi-layout-export.h"
+#include "ivi-layout-private.h"
 
 struct ivi_shell_ext;
 
@@ -85,6 +87,9 @@ struct ivi_shell_ext
     struct wl_list list_shell_surface;
 };
 
+
+static struct ivi_layout_interface *ivi_layout;
+
 /* ------------------------------------------------------------------------- */
 /* common functions                                                          */
 /* ------------------------------------------------------------------------- */
@@ -112,6 +117,62 @@ configure(struct weston_view *view, float x, float y)
     }
 }
 
+static void
+layout_surface_poperty_changed(struct ivi_layout_surface *ivisurf,
+                               const struct ivi_layout_surface_properties *prop,
+                               enum ivi_layout_notification_mask mask,
+                               void *userdata)
+{
+    struct shell_surface *shsurf = (struct shell_surface *)userdata;
+
+    if ((mask & IVI_NOTIFICATION_DEST_RECT)) {
+        wl_shell_surface_send_configure(shsurf->resource, 0,
+                                        prop->dest_width, prop->dest_height);
+    }
+}
+
+static void
+subscribe_layout_surface_property_changes(struct shell_surface *shsurf)
+{
+    struct ivi_layout_surface *ivisurf;
+
+    if (shsurf == NULL || shsurf->surface == NULL)
+        return;
+
+    if (ivi_layout == NULL ||
+        ivi_layout->surface_find == NULL ||
+        ivi_layout->surface_add_notification == NULL)
+        return;
+
+    ivisurf = ivi_layout->surface_find(shsurf->surface);
+
+    if (ivisurf != NULL) {
+        ivi_layout->surface_add_notification(ivisurf,
+                                            layout_surface_poperty_changed,
+                                            (void *)shsurf);
+    }
+}
+
+
+static void
+unsubscribe_layout_surface_property_changes(struct shell_surface *shsurf)
+{
+    struct ivi_layout_surface *ivisurf;
+
+    if (shsurf == NULL || shsurf->surface == NULL)
+        return;
+
+    if (ivi_layout == NULL ||
+        ivi_layout->surface_find == NULL ||
+        ivi_layout->surface_remove_notification == NULL)
+        return;
+
+    ivisurf = ivi_layout->surface_find(shsurf->surface);
+
+    if (ivisurf != NULL)
+        ivi_layout->surface_remove_notification(ivisurf);
+}
+
 /**
  * Implementation of wl_shell
  */
@@ -149,6 +210,8 @@ destroy_shell_surface(struct shell_surface *shsurf)
 {
     wl_list_remove(&shsurf->surface_destroy_listener.link);
 
+    unsubscribe_layout_surface_property_changes(shsurf);
+
 #if 0
     shsurf->surface->configure = NULL;
 #endif
@@ -390,6 +453,7 @@ shell_weston_surface_destroy(struct wl_listener *listener, void *data)
     lsurf = NULL;
 }
 
+
 static struct shell_surface *
 create_shell_surface(struct ivi_shell_ext *shell,
                      struct wl_client *client,
@@ -437,6 +501,8 @@ create_shell_surface(struct ivi_shell_ext *shell,
     wl_resource_add_destroy_listener(surface->resource,
                                      &shsurf->surface_destroy_listener);
 
+    subscribe_layout_surface_property_changes(shsurf);
+
     return shsurf;
 }
 
@@ -576,6 +642,8 @@ init_ivi_shell_ext(struct weston_compositor *ec,
                    int *argc, char *argv[])
 {
     struct ivi_shell_ext *shell = get_instance();
+    char ivi_layout_path[PATH_MAX];
+    void *module;
 
     wl_list_init(&shell->list_weston_surface);
     wl_list_init(&shell->list_shell_surface);
@@ -588,5 +656,16 @@ init_ivi_shell_ext(struct weston_compositor *ec,
         return -1;
     }
 
+    snprintf(ivi_layout_path, sizeof ivi_layout_path, "%s/%s", MODULEDIR, "ivi-layout.so");
+    module = dlopen(ivi_layout_path, RTLD_NOW | RTLD_NOLOAD);
+    if (module != NULL)
+        ivi_layout = dlsym(module, "ivi_layout_interface");
+
+    if (ivi_layout == NULL) {
+        weston_log("ivi-shell-ext: layer interface in '%s' is not loaded. "
+                   "geometry hints will not be sent to clients\n",
+                   ivi_layout_path);
+    }
+
     return 0;
 }