[PATCH weston v2 05/12] libweston: Use struct timespec for motion events
Alexandros Frantzis
alexandros.frantzis at collabora.com
Fri Nov 24 16:01:46 UTC 2017
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 at collabora.com>
---
Changes in v2:
- Fix handle_pointer_motion_absolute to use the event time in
microseconds with libinput_event_pointer_get_time_usec.
compositor/screen-share.c | 6 +++++-
desktop-shell/exposay.c | 3 ++-
desktop-shell/shell.c | 12 ++++++++----
ivi-shell/hmi-controller.c | 3 ++-
libweston-desktop/seat.c | 2 +-
libweston/compositor-rdp.c | 10 +++++++---
libweston/compositor-wayland.c | 5 ++++-
libweston/compositor-x11.c | 6 ++++--
libweston/compositor.h | 12 +++++++-----
libweston/data-device.c | 8 ++++++--
libweston/input.c | 30 ++++++++++++++++++------------
libweston/libinput-device.c | 19 ++++++++++---------
tests/weston-test.c | 6 +++++-
13 files changed, 79 insertions(+), 43 deletions(-)
diff --git a/compositor/screen-share.c b/compositor/screen-share.c
index a6f82b19..c7aad313 100644
--- a/compositor/screen-share.c
+++ b/compositor/screen-share.c
@@ -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);
}
diff --git a/desktop-shell/exposay.c b/desktop-shell/exposay.c
index b11a7f79..15b86863 100644
--- a/desktop-shell/exposay.c
+++ b/desktop-shell/exposay.c
@@ -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 =
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 55380417..62dfa450 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -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 =
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index d5403e06..6713eca3 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -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 =
diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c
index 96308807..18a329c4 100644
--- a/libweston-desktop/seat.c
+++ b/libweston-desktop/seat.c
@@ -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);
diff --git a/libweston/compositor-rdp.c b/libweston/compositor-rdp.c
index 990ddc66..315d2ade 100644
--- a/libweston/compositor-rdp.c
+++ b/libweston/compositor-rdp.c
@@ -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);
diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index a0d0e62a..8f26c545 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -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;
}
diff --git a/libweston/compositor-x11.c b/libweston/compositor-x11.c
index 60843ac1..7e24afcb 100644
--- a/libweston/compositor-x11.c
+++ b/libweston/compositor-x11.c
@@ -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;
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 59c349d5..971676cf 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -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,
diff --git a/libweston/data-device.c b/libweston/data-device.c
index cba1e116..58a440ae 100644
--- a/libweston/data-device.c
+++ b/libweston/data-device.c
@@ -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);
}
}
diff --git a/libweston/input.c b/libweston/input.c
index 81a94a92..c167b8ce 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -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 =
diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c
index b1d269db..24f79b4c 100644
--- a/libweston/libinput-device.c
+++ b/libweston/libinput-device.c
@@ -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;
}
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 189fcc1b..3f684820 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -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);
}
--
2.14.1
More information about the wayland-devel
mailing list