data-device: Update drag icon position from configure and motion handlers
authorKristian Høgsberg <krh@bitplanet.net>
Wed, 8 May 2013 02:53:43 +0000 (22:53 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Wed, 8 May 2013 02:57:15 +0000 (22:57 -0400)
We can now update the drag icon position directly from the configure
handler or the grab motion handler, and no longer need
weston_seat_update_drag_surface().

src/compositor.c
src/compositor.h
src/data-device.c
src/input.c

index 4dba3a3..a810fd2 100644 (file)
@@ -1182,8 +1182,6 @@ weston_output_repaint(struct weston_output *output, uint32_t msecs)
        struct wl_list frame_callback_list;
        pixman_region32_t output_damage;
 
-       weston_compositor_update_drag_surfaces(ec);
-
        /* Rebuild the surface list and update surface transforms up front. */
        wl_list_init(&ec->surface_list);
        wl_list_init(&frame_callback_list);
index 5a9349d..45054f5 100644 (file)
@@ -334,8 +334,6 @@ void
 weston_seat_set_keyboard(struct weston_seat *seat, struct weston_keyboard *keyboard);
 void
 weston_seat_set_touch(struct weston_seat *seat, struct weston_touch *touch);
-void
-weston_seat_update_drag_surface(struct weston_seat *seat, int dx, int dy);
 
 void
 weston_pointer_init(struct weston_pointer *pointer);
@@ -474,6 +472,7 @@ struct weston_seat {
        struct weston_pointer_grab drag_grab;
        struct weston_surface *drag_surface;
        struct wl_listener drag_surface_destroy_listener;
+       int32_t drag_dx, drag_dy;
 
        uint32_t num_tp;
 
@@ -856,8 +855,6 @@ void
 weston_compositor_offscreen(struct weston_compositor *compositor);
 void
 weston_compositor_sleep(struct weston_compositor *compositor);
-void
-weston_compositor_update_drag_surfaces(struct weston_compositor *compositor);
 struct weston_surface *
 weston_compositor_pick_surface(struct weston_compositor *compositor,
                               wl_fixed_t x, wl_fixed_t y,
index 8b2c7cf..ee17f76 100644 (file)
@@ -167,6 +167,7 @@ drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_
 {
        struct weston_seat *seat = es->configure_private;
        struct wl_list *list;
+       float fx, fy;
 
        if (!weston_surface_is_mapped(es) && es->buffer_ref.buffer) {
                if (seat->sprite && weston_surface_is_mapped(seat->sprite))
@@ -179,9 +180,12 @@ drag_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy, int32_
                empty_region(&es->pending.input);
        }
 
-       weston_surface_configure(es,
-                                es->geometry.x + sx, es->geometry.y + sy,
-                                width, height);
+       seat->drag_dx += sx;
+       seat->drag_dy += sy;
+
+       fx = wl_fixed_to_double(seat->pointer->x) + seat->drag_dx;
+       fy = wl_fixed_to_double(seat->pointer->y) + seat->drag_dy;
+       weston_surface_configure(es, fx, fy, width, height);
 }
 
 static int
@@ -196,10 +200,8 @@ device_setup_new_drag_surface(struct weston_seat *seat,
        }
 
        seat->drag_surface = surface;
-
-       weston_surface_set_position(seat->drag_surface,
-                                   wl_fixed_to_double(seat->pointer->x),
-                                   wl_fixed_to_double(seat->pointer->y));
+       seat->drag_dx = 0;
+       seat->drag_dy = 0;
 
        surface->configure = drag_surface_configure;
        surface->configure_private = seat;
@@ -222,29 +224,6 @@ device_release_drag_surface(struct weston_seat *seat)
        seat->drag_surface = NULL;
 }
 
-void
-weston_seat_update_drag_surface(struct weston_seat *seat, int dx, int dy)
-{
-       if (!seat->drag_surface)
-               return;
-
-       if (!dx && !dy)
-               return;
-
-       weston_surface_set_position(seat->drag_surface,
-                                   seat->drag_surface->geometry.x + wl_fixed_to_double(dx),
-                                   seat->drag_surface->geometry.y + wl_fixed_to_double(dy));
-}
-
-void
-weston_compositor_update_drag_surfaces(struct weston_compositor *compositor)
-{
-       struct weston_seat *seat;
-
-       wl_list_for_each(seat, &compositor->seat_list, link)
-               weston_seat_update_drag_surface(seat, 0, 0);
-}
-
 static void
 destroy_drag_focus(struct wl_listener *listener, void *data)
 {
@@ -307,6 +286,14 @@ drag_grab_motion(struct weston_pointer_grab *grab,
 {
        struct weston_seat *seat =
                container_of(grab, struct weston_seat, drag_grab);
+       float fx, fy;
+
+       if (seat->drag_surface) {
+               fx = wl_fixed_to_double(seat->pointer->x) + seat->drag_dx;
+               fy = wl_fixed_to_double(seat->pointer->y) + seat->drag_dy;
+               weston_surface_set_position(seat->drag_surface, fx, fy);
+               weston_surface_schedule_repaint(seat->drag_surface);
+       }
 
        if (seat->drag_focus_resource)
                wl_data_device_send_motion(seat->drag_focus_resource,
@@ -316,10 +303,8 @@ drag_grab_motion(struct weston_pointer_grab *grab,
 static void
 data_device_end_drag_grab(struct weston_seat *seat)
 {
-       if (seat->drag_surface) {
+       if (seat->drag_surface)
                device_release_drag_surface(seat);
-               weston_seat_update_drag_surface(seat, 0, 0);
-       }
 
        drag_grab_focus(&seat->drag_grab, NULL,
                        wl_fixed_from_int(0), wl_fixed_from_int(0));
@@ -408,7 +393,6 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
        if (icon_resource) {
                if (!device_setup_new_drag_surface(seat, icon_resource->data))
                        return;
-               weston_seat_update_drag_surface(seat, 0, 0);
        }
 
        weston_pointer_set_focus(seat->pointer, NULL,
index 753b679..1d8aee3 100644 (file)
@@ -639,8 +639,6 @@ move_pointer(struct weston_seat *seat, wl_fixed_t x, wl_fixed_t y)
 
        clip_pointer_motion(seat, &x, &y);
 
-       weston_seat_update_drag_surface(seat, x - pointer->x, y - pointer->y);
-
        pointer->x = x;
        pointer->y = y;