libweston: Use struct timespec for motion events
authorAlexandros Frantzis <alexandros.frantzis@collabora.com>
Fri, 24 Nov 2017 16:01:46 +0000 (18:01 +0200)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Mon, 27 Nov 2017 09:42:07 +0000 (11:42 +0200)
Change code related to motion events to use struct timespec to represent
time.

This commit is part of a larger effort to transition the Weston codebase
to struct timespec.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
13 files changed:
compositor/screen-share.c
desktop-shell/exposay.c
desktop-shell/shell.c
ivi-shell/hmi-controller.c
libweston-desktop/seat.c
libweston/compositor-rdp.c
libweston/compositor-wayland.c
libweston/compositor-x11.c
libweston/compositor.h
libweston/data-device.c
libweston/input.c
libweston/libinput-device.c
tests/weston-test.c

index a6f82b1..c7aad31 100644 (file)
@@ -44,6 +44,7 @@
 #include "weston.h"
 #include "shared/helpers.h"
 #include "shared/os-compatibility.h"
+#include "shared/timespec-util.h"
 #include "fullscreen-shell-unstable-v1-client-protocol.h"
 
 struct shared_output {
@@ -140,11 +141,14 @@ ss_seat_handle_motion(void *data, struct wl_pointer *pointer,
                      uint32_t time, wl_fixed_t x, wl_fixed_t y)
 {
        struct ss_seat *seat = data;
+       struct timespec ts;
+
+       timespec_from_msec(&ts, time);
 
        /* No transformation of input position is required here because we are
         * always receiving the input in the same coordinates as the output. */
 
-       notify_motion_absolute(&seat->base, time,
+       notify_motion_absolute(&seat->base, &ts,
                               wl_fixed_to_double(x), wl_fixed_to_double(y));
        notify_pointer_frame(&seat->base);
 }
index b11a7f7..15b8686 100644 (file)
@@ -349,7 +349,8 @@ exposay_focus(struct weston_pointer_grab *grab)
 }
 
 static void
-exposay_motion(struct weston_pointer_grab *grab, uint32_t time,
+exposay_motion(struct weston_pointer_grab *grab,
+              const struct timespec *time,
               struct weston_pointer_motion_event *event)
 {
        struct desktop_shell *shell =
index 5538041..62dfa45 100644 (file)
@@ -1482,7 +1482,8 @@ constrain_position(struct weston_move_grab *move, int *cx, int *cy)
 }
 
 static void
-move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+move_grab_motion(struct weston_pointer_grab *grab,
+                const struct timespec *time,
                 struct weston_pointer_motion_event *event)
 {
        struct weston_move_grab *move = (struct weston_move_grab *) grab;
@@ -1577,7 +1578,8 @@ struct weston_resize_grab {
 };
 
 static void
-resize_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+resize_grab_motion(struct weston_pointer_grab *grab,
+                  const struct timespec *time,
                   struct weston_pointer_motion_event *event)
 {
        struct weston_resize_grab *resize = (struct weston_resize_grab *) grab;
@@ -1767,7 +1769,8 @@ busy_cursor_grab_focus(struct weston_pointer_grab *base)
 }
 
 static void
-busy_cursor_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+busy_cursor_grab_motion(struct weston_pointer_grab *grab,
+                       const struct timespec *time,
                        struct weston_pointer_motion_event *event)
 {
        weston_pointer_move(grab->pointer, event);
@@ -3443,7 +3446,8 @@ terminate_binding(struct weston_keyboard *keyboard, uint32_t time,
 }
 
 static void
-rotate_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+rotate_grab_motion(struct weston_pointer_grab *grab,
+                  const struct timespec *time,
                   struct weston_pointer_motion_event *event)
 {
        struct rotate_grab *rotate =
index d5403e0..6713eca 100644 (file)
@@ -1534,7 +1534,8 @@ layer_set_pos(struct ivi_layout_layer *layer, wl_fixed_t pos_x,
 }
 
 static void
-pointer_move_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+pointer_move_grab_motion(struct weston_pointer_grab *grab,
+                        const struct timespec *time,
                         struct weston_pointer_motion_event *event)
 {
        struct pointer_move_grab *pnt_move_grab =
index 9630880..18a329c 100644 (file)
@@ -108,7 +108,7 @@ weston_desktop_seat_popup_grab_pointer_focus(struct weston_pointer_grab *grab)
 
 static void
 weston_desktop_seat_popup_grab_pointer_motion(struct weston_pointer_grab *grab,
-                                             uint32_t time,
+                                             const struct timespec *time,
                                              struct weston_pointer_motion_event *event)
 {
        weston_pointer_send_motion(grab->pointer, time, event);
index 990ddc6..315d2ad 100644 (file)
@@ -81,6 +81,7 @@
 #endif
 
 #include "shared/helpers.h"
+#include "shared/timespec-util.h"
 #include "compositor.h"
 #include "compositor-rdp.h"
 #include "pixman-renderer.h"
@@ -1029,11 +1030,13 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
        struct rdp_output *output;
        uint32_t button = 0;
        bool need_frame = false;
+       struct timespec time;
 
        if (flags & PTR_FLAGS_MOVE) {
                output = peerContext->rdpBackend->output;
                if (x < output->base.width && y < output->base.height) {
-                       notify_motion_absolute(peerContext->item.seat, weston_compositor_get_time(),
+                       timespec_from_msec(&time, weston_compositor_get_time());
+                       notify_motion_absolute(peerContext->item.seat, &time,
                                        x, y);
                        need_frame = true;
                }
@@ -1088,11 +1091,12 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
 {
        RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
        struct rdp_output *output;
+       struct timespec time;
 
        output = peerContext->rdpBackend->output;
        if (x < output->base.width && y < output->base.height) {
-               notify_motion_absolute(peerContext->item.seat, weston_compositor_get_time(),
-                               x, y);
+               timespec_from_msec(&time, weston_compositor_get_time());
+               notify_motion_absolute(peerContext->item.seat, &time, x, y);
        }
 
        FREERDP_CB_RETURN(TRUE);
index a0d0e62..8f26c54 100644 (file)
@@ -53,6 +53,7 @@
 #include "shared/image-loader.h"
 #include "shared/os-compatibility.h"
 #include "shared/cairo-util.h"
+#include "shared/timespec-util.h"
 #include "fullscreen-shell-unstable-v1-client-protocol.h"
 #include "xdg-shell-unstable-v6-client-protocol.h"
 #include "presentation-time-server-protocol.h"
@@ -1589,6 +1590,7 @@ input_handle_motion(void *data, struct wl_pointer *pointer,
        enum theme_location location;
        bool want_frame = false;
        double x, y;
+       struct timespec ts;
 
        if (!input->output)
                return;
@@ -1626,7 +1628,8 @@ input_handle_motion(void *data, struct wl_pointer *pointer,
        }
 
        if (location == THEME_LOCATION_CLIENT_AREA) {
-               notify_motion_absolute(&input->base, time, x, y);
+               timespec_from_msec(&ts, time);
+               notify_motion_absolute(&input->base, &ts, x, y);
                want_frame = true;
        }
 
index 60843ac..7e24afc 100644 (file)
@@ -55,6 +55,7 @@
 #include "shared/config-parser.h"
 #include "shared/helpers.h"
 #include "shared/image-loader.h"
+#include "shared/timespec-util.h"
 #include "gl-renderer.h"
 #include "weston-egl-ext.h"
 #include "pixman-renderer.h"
@@ -1242,6 +1243,7 @@ x11_backend_deliver_motion_event(struct x11_backend *b,
        struct weston_pointer_motion_event motion_event = { 0 };
        xcb_motion_notify_event_t *motion_notify =
                        (xcb_motion_notify_event_t *) event;
+       struct timespec time;
 
        if (!b->has_xkb)
                update_xkb_state_from_core(b, motion_notify->state);
@@ -1260,8 +1262,8 @@ x11_backend_deliver_motion_event(struct x11_backend *b,
                .dy = y - b->prev_y
        };
 
-       notify_motion(&b->core_seat, weston_compositor_get_time(),
-                     &motion_event);
+       timespec_from_msec(&time, weston_compositor_get_time());
+       notify_motion(&b->core_seat, &time, &motion_event);
        notify_pointer_frame(&b->core_seat);
 
        b->prev_x = x;
index 59c349d..971676c 100644 (file)
@@ -249,7 +249,7 @@ enum weston_pointer_motion_mask {
 
 struct weston_pointer_motion_event {
        uint32_t mask;
-       uint64_t time_usec;
+       struct timespec time;
        double x;
        double y;
        double dx;
@@ -268,7 +268,8 @@ struct weston_pointer_axis_event {
 struct weston_pointer_grab;
 struct weston_pointer_grab_interface {
        void (*focus)(struct weston_pointer_grab *grab);
-       void (*motion)(struct weston_pointer_grab *grab, uint32_t time,
+       void (*motion)(struct weston_pointer_grab *grab,
+                      const struct timespec *time,
                       struct weston_pointer_motion_event *event);
        void (*button)(struct weston_pointer_grab *grab,
                       uint32_t time, uint32_t button, uint32_t state);
@@ -423,7 +424,8 @@ weston_pointer_create(struct weston_seat *seat);
 void
 weston_pointer_destroy(struct weston_pointer *pointer);
 void
-weston_pointer_send_motion(struct weston_pointer *pointer, uint32_t time,
+weston_pointer_send_motion(struct weston_pointer *pointer,
+                          const struct timespec *time,
                           struct weston_pointer_motion_event *event);
 bool
 weston_pointer_has_focus_resource(struct weston_pointer *pointer);
@@ -1363,10 +1365,10 @@ weston_view_activate(struct weston_view *view,
                     uint32_t flags);
 
 void
-notify_motion(struct weston_seat *seat, uint32_t time,
+notify_motion(struct weston_seat *seat, const struct timespec *time,
              struct weston_pointer_motion_event *event);
 void
-notify_motion_absolute(struct weston_seat *seat, uint32_t time,
+notify_motion_absolute(struct weston_seat *seat, const struct timespec *time,
                       double x, double y);
 void
 notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
index cba1e11..58a440a 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "compositor.h"
 #include "shared/helpers.h"
+#include "shared/timespec-util.h"
 
 struct weston_drag {
        struct wl_client *client;
@@ -575,7 +576,8 @@ drag_grab_focus(struct weston_pointer_grab *grab)
 }
 
 static void
-drag_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
+drag_grab_motion(struct weston_pointer_grab *grab,
+                const struct timespec *time,
                 struct weston_pointer_motion_event *event)
 {
        struct weston_pointer_drag *drag =
@@ -583,6 +585,7 @@ drag_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
        struct weston_pointer *pointer = drag->grab.pointer;
        float fx, fy;
        wl_fixed_t sx, sy;
+       uint32_t msecs;
 
        weston_pointer_move(pointer, event);
 
@@ -594,11 +597,12 @@ drag_grab_motion(struct weston_pointer_grab *grab, uint32_t time,
        }
 
        if (drag->base.focus_resource) {
+               msecs = timespec_to_msec(time);
                weston_view_from_global_fixed(drag->base.focus,
                                              pointer->x, pointer->y,
                                              &sx, &sy);
 
-               wl_data_device_send_motion(drag->base.focus_resource, time, sx, sy);
+               wl_data_device_send_motion(drag->base.focus_resource, msecs, sx, sy);
        }
 }
 
index 81a94a9..c167b8c 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "shared/helpers.h"
 #include "shared/os-compatibility.h"
+#include "shared/timespec-util.h"
 #include "compositor.h"
 #include "relative-pointer-unstable-v1-server-protocol.h"
 #include "pointer-constraints-unstable-v1-server-protocol.h"
@@ -341,7 +342,7 @@ default_grab_pointer_focus(struct weston_pointer_grab *grab)
 
 static void
 pointer_send_relative_motion(struct weston_pointer *pointer,
-                            uint32_t time,
+                            const struct timespec *time,
                             struct weston_pointer_motion_event *event)
 {
        uint64_t time_usec;
@@ -359,9 +360,9 @@ pointer_send_relative_motion(struct weston_pointer *pointer,
                return;
 
        resource_list = &pointer->focus_client->relative_pointer_resources;
-       time_usec = event->time_usec;
+       time_usec = timespec_to_usec(&event->time);
        if (time_usec == 0)
-               time_usec = time * 1000ULL;
+               time_usec = timespec_to_usec(time);
 
        dxf = wl_fixed_from_double(dx);
        dyf = wl_fixed_from_double(dy);
@@ -379,22 +380,26 @@ pointer_send_relative_motion(struct weston_pointer *pointer,
 }
 
 static void
-pointer_send_motion(struct weston_pointer *pointer, uint32_t time,
+pointer_send_motion(struct weston_pointer *pointer,
+                   const struct timespec *time,
                    wl_fixed_t sx, wl_fixed_t sy)
 {
        struct wl_list *resource_list;
        struct wl_resource *resource;
+       uint32_t msecs;
 
        if (!pointer->focus_client)
                return;
 
        resource_list = &pointer->focus_client->pointer_resources;
+       msecs = timespec_to_msec(time);
        wl_resource_for_each(resource, resource_list)
-               wl_pointer_send_motion(resource, time, sx, sy);
+               wl_pointer_send_motion(resource, msecs, sx, sy);
 }
 
 WL_EXPORT void
-weston_pointer_send_motion(struct weston_pointer *pointer, uint32_t time,
+weston_pointer_send_motion(struct weston_pointer *pointer,
+                          const struct timespec *time,
                           struct weston_pointer_motion_event *event)
 {
        wl_fixed_t x, y;
@@ -418,7 +423,8 @@ weston_pointer_send_motion(struct weston_pointer *pointer, uint32_t time,
 }
 
 static void
-default_grab_pointer_motion(struct weston_pointer_grab *grab, uint32_t time,
+default_grab_pointer_motion(struct weston_pointer_grab *grab,
+                           const struct timespec *time,
                            struct weston_pointer_motion_event *event)
 {
        weston_pointer_send_motion(grab->pointer, time, event);
@@ -1551,7 +1557,7 @@ weston_pointer_handle_output_destroy(struct wl_listener *listener, void *data)
 
 WL_EXPORT void
 notify_motion(struct weston_seat *seat,
-             uint32_t time,
+             const struct timespec *time,
              struct weston_pointer_motion_event *event)
 {
        struct weston_compositor *ec = seat->compositor;
@@ -1598,8 +1604,8 @@ run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new)
 }
 
 WL_EXPORT void
-notify_motion_absolute(struct weston_seat *seat,
-                      uint32_t time, double x, double y)
+notify_motion_absolute(struct weston_seat *seat, const struct timespec *time,
+                      double x, double y)
 {
        struct weston_compositor *ec = seat->compositor;
        struct weston_pointer *pointer = weston_seat_get_pointer(seat);
@@ -3314,7 +3320,7 @@ locked_pointer_grab_pointer_focus(struct weston_pointer_grab *grab)
 
 static void
 locked_pointer_grab_pointer_motion(struct weston_pointer_grab *grab,
-                                  uint32_t time,
+                                  const struct timespec *time,
                                   struct weston_pointer_motion_event *event)
 {
        pointer_send_relative_motion(grab->pointer, time, event);
@@ -4291,7 +4297,7 @@ maybe_warp_confined_pointer(struct weston_pointer_constraint *constraint)
 
 static void
 confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab,
-                                    uint32_t time,
+                                    const struct timespec *time,
                                     struct weston_pointer_motion_event *event)
 {
        struct weston_pointer_constraint *constraint =
index b1d269d..24f79b4 100644 (file)
@@ -39,6 +39,7 @@
 #include "compositor.h"
 #include "libinput-device.h"
 #include "shared/helpers.h"
+#include "shared/timespec-util.h"
 
 void
 evdev_led_update(struct evdev_device *device, enum weston_led weston_leds)
@@ -86,26 +87,25 @@ handle_pointer_motion(struct libinput_device *libinput_device,
        struct evdev_device *device =
                libinput_device_get_user_data(libinput_device);
        struct weston_pointer_motion_event event = { 0 };
-       uint64_t time_usec =
-               libinput_event_pointer_get_time_usec(pointer_event);
+       struct timespec time;
        double dx_unaccel, dy_unaccel;
 
+       timespec_from_usec(&time,
+                          libinput_event_pointer_get_time_usec(pointer_event));
        dx_unaccel = libinput_event_pointer_get_dx_unaccelerated(pointer_event);
        dy_unaccel = libinput_event_pointer_get_dy_unaccelerated(pointer_event);
 
        event = (struct weston_pointer_motion_event) {
                .mask = WESTON_POINTER_MOTION_REL |
                        WESTON_POINTER_MOTION_REL_UNACCEL,
-               .time_usec = time_usec,
+               .time = time,
                .dx = libinput_event_pointer_get_dx(pointer_event),
                .dy = libinput_event_pointer_get_dy(pointer_event),
                .dx_unaccel = dx_unaccel,
                .dy_unaccel = dy_unaccel,
        };
 
-       notify_motion(device->seat,
-                     libinput_event_pointer_get_time(pointer_event),
-                     &event);
+       notify_motion(device->seat, &time, &event);
 
        return true;
 }
@@ -118,14 +118,15 @@ handle_pointer_motion_absolute(
        struct evdev_device *device =
                libinput_device_get_user_data(libinput_device);
        struct weston_output *output = device->output;
-       uint32_t time;
+       struct timespec time;
        double x, y;
        uint32_t width, height;
 
        if (!output)
                return false;
 
-       time = libinput_event_pointer_get_time(pointer_event);
+       timespec_from_usec(&time,
+                          libinput_event_pointer_get_time_usec(pointer_event));
        width = device->output->current_mode->width;
        height = device->output->current_mode->height;
 
@@ -135,7 +136,7 @@ handle_pointer_motion_absolute(
                                                              height);
 
        weston_output_transform_coordinate(device->output, x, y, &x, &y);
-       notify_motion_absolute(device->seat, time, x, y);
+       notify_motion_absolute(device->seat, &time, x, y);
 
        return true;
 }
index 189fcc1..3f68482 100644 (file)
@@ -43,6 +43,7 @@
 #endif /* ENABLE_EGL */
 
 #include "shared/helpers.h"
+#include "shared/timespec-util.h"
 
 struct weston_test {
        struct weston_compositor *compositor;
@@ -151,6 +152,7 @@ move_pointer(struct wl_client *client, struct wl_resource *resource,
        struct weston_seat *seat = get_seat(test);
        struct weston_pointer *pointer = weston_seat_get_pointer(seat);
        struct weston_pointer_motion_event event = { 0 };
+       struct timespec time;
 
        event = (struct weston_pointer_motion_event) {
                .mask = WESTON_POINTER_MOTION_REL,
@@ -158,7 +160,9 @@ move_pointer(struct wl_client *client, struct wl_resource *resource,
                .dy = wl_fixed_to_double(wl_fixed_from_int(y) - pointer->y),
        };
 
-       notify_motion(seat, 100, &event);
+       timespec_from_msec(&time, 100);
+
+       notify_motion(seat, &time, &event);
 
        notify_pointer_position(test, resource);
 }