desktop-shell: implement set_transient
authorJaehoon Jeong <jh01.j@samsung.com>
Tue, 21 Jul 2015 06:02:33 +0000 (15:02 +0900)
committerJaehoon Jeong <jh01.j@samsung.com>
Tue, 21 Jul 2015 06:07:28 +0000 (15:07 +0900)
Change-Id: I5f7b8fd3dfc18848a528a13be753fe30026e7a4f

src/lib/desktop-shell/desktop-shell-internal.h
src/lib/desktop-shell/shell-surface.c
src/lib/desktop-shell/wl-shell.c

index 0b78d13..ea511a1 100644 (file)
@@ -84,6 +84,12 @@ struct shell_surface
         pepper_seat_t       *seat;
     } popup;
 
+    struct
+    {
+        int32_t              x, y;
+        uint32_t             flags;
+    } transient;
+
     /* (*map) */
     void (*shell_surface_map)(shell_surface_t *shsurf);
     pepper_bool_t            mapped;
@@ -144,5 +150,9 @@ void
 shell_surface_set_popup(shell_surface_t *shsurf, pepper_seat_t *seat, pepper_surface_t *parent,
                         int32_t x, int32_t y, uint32_t flags);
 
+void
+shell_surface_set_transient(shell_surface_t *shsurf, pepper_surface_t *parent,
+                            int32_t x, int32_t y, uint32_t flags);
+
 pepper_bool_t
 init_wl_shell(desktop_shell_t *shell);
index 68a6d55..59e1d7e 100644 (file)
@@ -256,6 +256,22 @@ shell_surface_set_popup(shell_surface_t     *shsurf,
     shell_surface_set_type(shsurf, SHELL_SURFACE_TYPE_POPUP);
 }
 
+void
+shell_surface_set_transient(shell_surface_t     *shsurf,
+                            pepper_surface_t    *parent,
+                            int32_t              x,
+                            int32_t              y,
+                            uint32_t             flags)
+{
+    shell_surface_set_parent(shsurf, parent);
+
+    shsurf->transient.x = x;
+    shsurf->transient.y = y;
+    shsurf->transient.flags = flags;
+
+    shell_surface_set_type(shsurf, SHELL_SURFACE_TYPE_TRANSIENT);
+}
+
 static void
 shell_surface_set_position(shell_surface_t *shsurf, int32_t x, int32_t y)
 {
@@ -290,9 +306,33 @@ shell_surface_map_popup(shell_surface_t *shsurf)
 
     pepper_view_map(shsurf->view);
 
+    pepper_view_stack_top(shsurf->view, PEPPER_TRUE);
+
     /* TODO: add_popup_grab(), but how? */
 }
 
+static void
+shell_surface_map_transient(shell_surface_t *shsurf)
+{
+    shell_surface_t *parent = get_shsurf_from_surface(shsurf->parent, shsurf->shell);
+    double x, y;
+
+    pepper_view_get_position(parent->view, &x, &y);
+
+    pepper_view_set_parent(shsurf->view, parent->view);
+
+    shell_surface_set_position(shsurf,
+                               x + shsurf->transient.x,
+                               y + shsurf->transient.y);
+
+    if (shsurf->transient.flags != WL_SHELL_SURFACE_TRANSIENT_INACTIVE)
+    {
+        /* TODO: set keyboard focus to view */
+    }
+
+    pepper_view_map(shsurf->view);
+}
+
 void
 shell_surface_set_type(shell_surface_t *shsurf, shell_surface_type_t type)
 {
@@ -309,6 +349,9 @@ shell_surface_set_type(shell_surface_t *shsurf, shell_surface_type_t type)
     case SHELL_SURFACE_TYPE_POPUP:
         shsurf->shell_surface_map = shell_surface_map_popup;
         break;
+    case SHELL_SURFACE_TYPE_TRANSIENT:
+        shsurf->shell_surface_map = shell_surface_map_transient;
+        break;
     default :
         /* XXX: Maybe some logs be needed */
         break;
index 1a42a74..e4d037b 100644 (file)
@@ -31,10 +31,17 @@ wl_shell_surface_set_toplevel(struct wl_client *client, struct wl_resource *reso
 }
 
 static void
-wl_shell_surface_set_transient(struct wl_client *client, struct wl_resource *resource,
-                            struct wl_resource *parent, int32_t x, int32_t y, uint32_t flags)
+wl_shell_surface_set_transient(struct wl_client     *client,
+                               struct wl_resource   *resource,
+                               struct wl_resource   *parent_resource,
+                               int32_t               x,
+                               int32_t               y,
+                               uint32_t              flags)
 {
-    /* TODO */
+    shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+    pepper_surface_t *parent = wl_resource_get_user_data(parent_resource);
+
+    shell_surface_set_transient(shsurf, parent, x, y, flags);
 }
 
 static void