desktop-shell: Implement shell_surface.move
authorJaehoon Jeong <jh01.j@samsung.com>
Mon, 24 Aug 2015 06:46:02 +0000 (15:46 +0900)
committerGerrit Code Review <root@ap3>
Mon, 24 Aug 2015 07:53:16 +0000 (16:53 +0900)
    - Implement wl_shell_surface.move(), xdg_surface.move()
    - Implement move_grab

Change-Id: I9b4040ae045b7a38092baa56f788470a6e81ca10

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

index 2f4ada5..7eda8a5 100644 (file)
@@ -24,9 +24,9 @@ struct shell_pointer_grab
 struct shell_pointer_grab_interface
 {
     void (*motion)(shell_pointer_grab_t *grab,
-                   int32_t x, int32_t y, uint32_t time, void *data);
+                   uint32_t time, int32_t x, int32_t y, void *data);
     void (*button)(shell_pointer_grab_t *grab,
-                   uint32_t button, uint32_t state, uint32_t time, void *data);
+                   uint32_t time, uint32_t button, uint32_t state, void *data);
     void (*axis)(shell_pointer_grab_t *grab,
                  uint32_t time, enum wl_pointer_axis axis, wl_fixed_t amount, void *data);
 };
@@ -132,6 +132,12 @@ struct shell_surface
 
     char                    *title, *class_;
 
+    struct
+    {
+        int32_t px, py;         /* Initial pointer position */
+        int32_t vx, vy;         /* Initial view position */
+    } move;
+
     /* Data structures per surface type */
     shell_surface_type_t     type;          /* Current surface type */
     shell_surface_type_t     next_type;     /* Requested surface type */
@@ -283,3 +289,6 @@ shell_seat_pointer_start_grab(shell_seat_t *shseat, shell_pointer_grab_interface
 
 void
 shell_seat_pointer_end_grab(shell_seat_t *shseat);
+
+void
+shell_surface_move(shell_surface_t *shsurf, pepper_seat_t *seat, uint32_t serial);
index 8bfc8a9..4a4c796 100644 (file)
@@ -1,6 +1,9 @@
 #include "desktop-shell-internal.h"
 #include "xdg-shell-server-protocol.h"
 
+
+extern shell_pointer_grab_interface_t shell_pointer_move_grab;
+
 void
 remove_ping_timer(shell_client_t *shell_client)
 {
@@ -813,3 +816,19 @@ shell_surface_set_type(shell_surface_t *shsurf, shell_surface_type_t type)
     shsurf->next_type = type;
     shsurf->mapped    = PEPPER_FALSE;
 }
+
+void
+shell_surface_move(shell_surface_t *shsurf, pepper_seat_t *seat, uint32_t serial)
+{
+    shell_seat_t *shseat = pepper_object_get_user_data((pepper_object_t *)seat, shsurf->shell);
+
+    double x, y;
+
+    pepper_view_get_position(shsurf->view, &x, &y);
+    shsurf->move.vx = (int)x;
+    shsurf->move.vy = (int)y;
+
+    pepper_pointer_get_position(shseat->pointer_grab.pointer, &shsurf->move.px, &shsurf->move.py);
+
+    shell_seat_pointer_start_grab(shseat, &shell_pointer_move_grab, shsurf);
+}
index 50a41e7..d5f8808 100644 (file)
@@ -89,8 +89,59 @@ shell_seat_pointer_end_grab(shell_seat_t *shseat)
 }
 
 static void
-shell_pointer_default_grab_motion(shell_pointer_grab_t *grab,
-                                  int32_t x, int32_t y, uint32_t time, void *userdata)
+shell_pointer_move_grab_motion(shell_pointer_grab_t *grab,
+                               uint32_t              time,
+                               int32_t               x,
+                               int32_t               y,
+                               void                 *userdata)
+{
+    pepper_pointer_t    *pointer = grab->pointer;
+    shell_surface_t     *shsurf = userdata;
+
+    pepper_pointer_set_position(pointer, x, y);
+
+    pepper_view_set_position(shsurf->view,
+                             shsurf->move.vx + (x - shsurf->move.px),
+                             shsurf->move.vy + (y - shsurf->move.py));
+}
+
+static void
+shell_pointer_move_grab_button(shell_pointer_grab_t *grab,
+                               uint32_t              time,
+                               uint32_t              button,
+                               uint32_t              state,
+                               void                 *userdata)
+{
+    /* FIXME */
+    if (state == WL_POINTER_BUTTON_STATE_RELEASED)
+    {
+        shell_seat_pointer_end_grab(grab->shseat);
+    }
+}
+
+static void
+shell_pointer_move_grab_axis(shell_pointer_grab_t   *grab,
+                             uint32_t                time,
+                             enum wl_pointer_axis    axis,
+                             wl_fixed_t              amount,
+                             void                   *userdata)
+{
+    /* TODO */
+}
+
+shell_pointer_grab_interface_t shell_pointer_move_grab =
+{
+    shell_pointer_move_grab_motion,
+    shell_pointer_move_grab_button,
+    shell_pointer_move_grab_axis,
+};
+
+static void
+shell_pointer_default_grab_motion(shell_pointer_grab_t  *grab,
+                                  uint32_t               time,
+                                  int32_t                x,
+                                  int32_t                y,
+                                  void                  *userdata)
 {
     /* TODO */
     shell_seat_t        *shseat = grab->shseat;
@@ -125,8 +176,11 @@ shell_pointer_default_grab_motion(shell_pointer_grab_t *grab,
 }
 
 static void
-shell_pointer_default_grab_button(shell_pointer_grab_t *grab,
-                               uint32_t button, uint32_t state, uint32_t time, void *userdata)
+shell_pointer_default_grab_button(shell_pointer_grab_t  *grab,
+                                  uint32_t               time,
+                                  uint32_t               button,
+                                  uint32_t               state,
+                                  void                  *userdata)
 {
     shell_seat_t        *shseat = grab->shseat;
     pepper_pointer_t    *pointer = pepper_seat_get_pointer(shseat->seat);
index 0d9b5e9..bfaf8a0 100644 (file)
@@ -9,10 +9,15 @@ wl_shell_surface_pong(struct wl_client *client, struct wl_resource *resource, ui
 }
 
 static void
-wl_shell_surface_move(struct wl_client *client, struct wl_resource *resource,
-                   struct wl_resource *seat, uint32_t serial)
+wl_shell_surface_move(struct wl_client      *client,
+                      struct wl_resource    *resource,
+                      struct wl_resource    *seat_resource,
+                      uint32_t               serial)
 {
-    /* TODO */
+    shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+    pepper_seat_t   *seat   = wl_resource_get_user_data(seat_resource);
+
+    shell_surface_move(shsurf, seat, serial);
 }
 
 static void
index c9d444e..47cb3d4 100644 (file)
@@ -64,7 +64,19 @@ xdg_surface_move(struct wl_client   *client,
                  struct wl_resource *seat_resource,
                  uint32_t            serial)
 {
-    /* TODO: */
+    shell_surface_t *shsurf = wl_resource_get_user_data(resource);
+    pepper_seat_t   *seat   = wl_resource_get_user_data(seat_resource);
+
+    if (!seat_resource)
+    {
+        wl_resource_post_error(resource,
+                               WL_DISPLAY_ERROR_INVALID_OBJECT,
+                               "Invalid seat");
+        return ;
+    }
+    seat = wl_resource_get_user_data(seat_resource);
+
+    shell_surface_move(shsurf, seat, serial);
 }
 
 static void