data_device: Add support for touch drag 23/280023/1
authorSeunghun Lee <shiin.lee@samsung.com>
Thu, 18 Aug 2022 02:21:07 +0000 (11:21 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 22 Aug 2022 09:08:16 +0000 (18:08 +0900)
Change-Id: Ifed6d3b8718ddb4a465ad6c1836d24b61e148b27

include/libds/data_device.h
src/data_device/data_device.c
src/data_device/data_device_private.h
src/data_device/drag.c
src/seat.h
src/seat/seat_private.h
src/seat/seat_touch.c

index d11f1c2..a34b4c4 100644 (file)
@@ -35,6 +35,8 @@ struct ds_data_offer;
 
 struct ds_drag;
 
+struct ds_touch_point;
+
 struct ds_event_request_set_selection
 {
     struct ds_seat *seat;
@@ -90,6 +92,9 @@ void ds_drag_destroy(struct ds_drag *drag);
 
 void ds_drag_start_pointer_drag(struct ds_drag *drag, uint32_t serial);
 
+void ds_drag_start_touch_drag(struct ds_drag *drag, uint32_t serial,
+        struct ds_touch_point *point);
+
 void ds_drag_add_destroy_listener(struct ds_drag *drag,
         struct wl_listener *listener);
 
index d62a4ae..345958c 100644 (file)
@@ -104,6 +104,19 @@ data_device_send_drag_leave(struct ds_data_device *data_device)
 }
 
 void
+data_device_send_drag_motion(struct ds_data_device *data_device,
+        uint32_t time_msec, double sx, double sy)
+{
+    struct wl_resource *device_resource;
+
+    wl_resource_for_each(device_resource, &data_device->resources) {
+        wl_data_device_send_motion(device_resource, time_msec,
+                wl_fixed_from_double(sx),
+                wl_fixed_from_double(sy));
+    }
+}
+
+void
 data_device_destroy_drag_offers(struct ds_data_device *data_device,
         struct ds_data_source *drag_source)
 {
index 235592d..70be749 100644 (file)
@@ -99,6 +99,7 @@ struct ds_drag
     struct ds_data_source *source;
 
     enum ds_drag_grab_type grab_type;
+    int32_t grab_touch_id, touch_id;
 
     struct wl_listener icon_destroy;
     struct wl_listener source_destroy;
@@ -145,6 +146,9 @@ bool data_device_send_drag_enter(struct ds_data_device *data_device,
 
 void data_device_send_drag_leave(struct ds_data_device *data_device);
 
+void data_device_send_drag_motion(struct ds_data_device *data_device,
+        uint32_t time_msec, double sx, double sy);
+
 void data_device_destroy_drag_offers(struct ds_data_device *data_device,
         struct ds_data_source *drag_source);
 
index 0f64ba2..1c74bf6 100644 (file)
@@ -3,6 +3,7 @@
 #include "data_device_private.h"
 
 static const struct ds_pointer_grab_interface drag_pointer_grab_iface;
+static const struct ds_touch_grab_interface drag_touch_grab_iface;
 static const struct ds_keyboard_grab_interface drag_keyboard_grab_iface;
 
 static void drag_destroy(struct ds_drag *drag);
@@ -51,11 +52,17 @@ ds_drag_start_pointer_drag(struct ds_drag *drag, uint32_t serial)
 }
 
 WL_EXPORT void
-ds_drag_start_touch_drag(struct ds_drag *drag, uint32_t serial)
+ds_drag_start_touch_drag(struct ds_drag *drag, uint32_t serial,
+        struct ds_touch_point *point)
 {
     drag->grab_type = DS_DRAG_GRAB_KEYBOARD_TOUCH;
+    drag->grab_touch_id = ds_seat_touch_get_grab_id(drag->seat);
+    drag->touch_id = point->touch_id;
 
-    // TODO
+    ds_seat_touch_start_grab(drag->seat, &drag->touch_grab);
+    drag_set_focus(drag, point->surface, point->sx, point->sy);
+
+    drag_start(drag, serial);
 }
 
 WL_EXPORT void
@@ -131,6 +138,9 @@ create_drag(struct ds_data_device *data_device, struct ds_data_source *source,
     drag->pointer_grab.data = drag;
     drag->pointer_grab.iface = &drag_pointer_grab_iface;
 
+    drag->touch_grab.data = drag;
+    drag->touch_grab.iface = &drag_touch_grab_iface;
+
     drag->keyboard_grab.data = drag;
     drag->keyboard_grab.iface = &drag_keyboard_grab_iface;
 
@@ -154,7 +164,7 @@ drag_destroy(struct ds_drag *drag)
                 ds_seat_pointer_end_grab(drag->seat);
                 break;
             case DS_DRAG_GRAB_KEYBOARD_TOUCH:
-                // TODO
+                ds_seat_touch_end_grab(drag->seat);
                 break;
             default:
             case DS_DRAG_GRAB_KEYBOARD:
@@ -306,19 +316,14 @@ drag_pointer_grab_iface_motion(struct ds_seat_pointer_grab *grab,
 {
     struct ds_drag *drag = grab->data;
     struct ds_data_device *data_device;
-    struct wl_resource *resource;
 
     if (!drag->focused_surface || !drag->focused_client)
         return;
 
     data_device = data_device_for_seat_client(drag->data_device->manager,
             drag->focused_client);
-    if (data_device) {
-        wl_resource_for_each(resource, &data_device->resources) {
-            wl_data_device_send_motion(resource, time,
-                    wl_fixed_from_double(sx), wl_fixed_from_double(sy));
-        }
-    }
+    if (data_device) 
+        data_device_send_drag_motion(data_device, time, sx, sy);
 
     struct ds_event_drag_motion event = {
         .drag = drag,
@@ -384,6 +389,70 @@ static const struct ds_pointer_grab_interface drag_pointer_grab_iface = {
     .cancel = drag_pointer_grab_iface_cancel,
 };
 
+static uint32_t
+drag_touch_grab_iface_down(struct ds_seat_touch_grab *grab, uint32_t time_msec,
+        struct ds_touch_point *point)
+{
+    // eat the event
+    return 0;
+}
+
+static void
+drag_touch_grab_iface_up(struct ds_seat_touch_grab *grab, uint32_t time_msec,
+        struct ds_touch_point *point)
+{
+    struct ds_drag *drag = grab->data;
+
+    if (drag->grab_touch_id != point->touch_id)
+        return;
+
+    if (drag->focused_client)
+        drag_drop(drag, time_msec);
+
+    drag_destroy(drag);
+}
+
+static void
+drag_touch_grab_iface_motion(struct ds_seat_touch_grab *grab, uint32_t time_msec,
+        struct ds_touch_point *point)
+{
+    struct ds_drag *drag = grab->data;
+    struct ds_data_device *data_device;
+
+    if (!drag->focused_surface || !drag->focused_client)
+        return;
+
+    data_device = data_device_for_seat_client(drag->data_device->manager,
+            drag->focused_client);
+    if (data_device)
+        data_device_send_drag_motion(data_device, time_msec,
+                point->sx, point->sy);
+}
+
+static void
+drag_touch_grab_iface_enter(struct ds_seat_touch_grab *grab, uint32_t time_msec,
+        struct ds_touch_point *point)
+{
+    struct ds_drag *drag = grab->data;
+    drag_set_focus(drag, point->focused_surface, point->sx, point->sy);
+}
+
+static void
+drag_touch_grab_iface_cancel(struct ds_seat_touch_grab *grab)
+{
+    struct ds_drag *drag = grab->data;
+    drag_destroy(drag);
+}
+
+
+static const struct ds_touch_grab_interface drag_touch_grab_iface = {
+    .down = drag_touch_grab_iface_down,
+    .up = drag_touch_grab_iface_up,
+    .motion = drag_touch_grab_iface_motion,
+    .enter = drag_touch_grab_iface_enter,
+    .cancel = drag_touch_grab_iface_cancel,
+};
+
 static void
 drag_keyboard_grab_iface_enter(struct ds_seat_keyboard_grab *grab,
         struct ds_surface *surface, uint32_t keycodes[], size_t num_keycodes,
index 3971d6a..83dc0a9 100644 (file)
@@ -32,6 +32,27 @@ struct ds_seat_touch_grab
     void *data;
 };
 
+struct ds_touch_point
+{
+    int32_t touch_id;
+    struct ds_surface *surface;
+    struct ds_seat_client *seat_client;
+
+    struct ds_seat_client *focused_client;
+    struct ds_surface *focused_surface;
+    double sx, sy;
+
+    struct wl_listener surface_destroy;
+    struct wl_listener focused_surface_destroy;
+    struct wl_listener client_destroy;
+
+    struct {
+        struct wl_signal destroy;
+    } events;
+
+    struct wl_list link;
+};
+
 void ds_seat_add_set_selection_listener(struct ds_seat *seat,
         struct wl_listener *listener);
 
@@ -91,4 +112,6 @@ void ds_seat_touch_send_motion(struct ds_seat *seat, uint32_t time_msec,
 
 void ds_seat_touch_send_frame(struct ds_seat *seat);
 
+uint32_t ds_seat_touch_get_grab_id(struct ds_seat *seat);
+
 #endif
index 7d7e063..38f1819 100644 (file)
@@ -77,27 +77,6 @@ struct ds_seat_keyboard
     } events;
 };
 
-struct ds_touch_point
-{
-    int32_t touch_id;
-    struct ds_surface *surface;
-    struct ds_seat_client *seat_client;
-
-    struct ds_seat_client *focused_client;
-    struct ds_surface *focused_surface;
-    double sx, sy;
-
-    struct wl_listener surface_destroy;
-    struct wl_listener focused_surface_destroy;
-    struct wl_listener client_destroy;
-
-    struct {
-        struct wl_signal destroy;
-    } events;
-
-    struct wl_list link;
-};
-
 struct ds_seat_touch
 {
     struct ds_seat *seat;
index 476c6a8..e7364af 100644 (file)
@@ -94,6 +94,28 @@ ds_seat_touch_notify_frame(struct ds_seat *seat)
 }
 
 WL_EXPORT void
+ds_seat_touch_start_grab(struct ds_seat *seat, struct ds_seat_touch_grab *grab)
+{
+    grab->seat = seat;
+    seat->touch.grab = grab;
+    wl_signal_emit(&seat->events.touch_grab_begin, grab);
+}
+
+WL_EXPORT void
+ds_seat_touch_end_grab(struct ds_seat *seat)
+{
+    struct ds_seat_touch *touch = &seat->touch;
+    struct ds_seat_touch_grab *grab = touch->grab;
+
+    if (grab != touch->default_grab) {
+        touch->grab = touch->default_grab;
+        wl_signal_emit(&seat->events.touch_grab_end, grab);
+        if (grab->iface->cancel)
+            grab->iface->cancel(grab);
+    }
+}
+
+WL_EXPORT void
 ds_seat_touch_add_grab_start_listener(struct ds_seat *seat,
         struct wl_listener *listener)
 {
@@ -192,6 +214,12 @@ ds_seat_touch_send_frame(struct ds_seat *seat)
     }
 }
 
+uint32_t
+ds_seat_touch_get_grab_id(struct ds_seat *seat)
+{
+    return seat->touch.grab_id;
+}
+
 bool
 seat_touch_init(struct ds_seat *seat)
 {