libweston: Use struct timespec for motion events

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>
This commit is contained in:
Alexandros Frantzis 2017-11-24 18:01:46 +02:00 committed by Pekka Paalanen
parent e6ac2afa56
commit 84b31f8956
13 changed files with 79 additions and 43 deletions

View File

@ -44,6 +44,7 @@
#include "weston.h" #include "weston.h"
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/os-compatibility.h" #include "shared/os-compatibility.h"
#include "shared/timespec-util.h"
#include "fullscreen-shell-unstable-v1-client-protocol.h" #include "fullscreen-shell-unstable-v1-client-protocol.h"
struct shared_output { 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) uint32_t time, wl_fixed_t x, wl_fixed_t y)
{ {
struct ss_seat *seat = data; struct ss_seat *seat = data;
struct timespec ts;
timespec_from_msec(&ts, time);
/* No transformation of input position is required here because we are /* No transformation of input position is required here because we are
* always receiving the input in the same coordinates as the output. */ * 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)); wl_fixed_to_double(x), wl_fixed_to_double(y));
notify_pointer_frame(&seat->base); notify_pointer_frame(&seat->base);
} }

View File

@ -349,7 +349,8 @@ exposay_focus(struct weston_pointer_grab *grab)
} }
static void 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 weston_pointer_motion_event *event)
{ {
struct desktop_shell *shell = struct desktop_shell *shell =

View File

@ -1482,7 +1482,8 @@ constrain_position(struct weston_move_grab *move, int *cx, int *cy)
} }
static void 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_pointer_motion_event *event)
{ {
struct weston_move_grab *move = (struct weston_move_grab *) grab; struct weston_move_grab *move = (struct weston_move_grab *) grab;
@ -1577,7 +1578,8 @@ struct weston_resize_grab {
}; };
static void 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_pointer_motion_event *event)
{ {
struct weston_resize_grab *resize = (struct weston_resize_grab *) grab; 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 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) struct weston_pointer_motion_event *event)
{ {
weston_pointer_move(grab->pointer, event); weston_pointer_move(grab->pointer, event);
@ -3443,7 +3446,8 @@ terminate_binding(struct weston_keyboard *keyboard, uint32_t time,
} }
static void 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 weston_pointer_motion_event *event)
{ {
struct rotate_grab *rotate = struct rotate_grab *rotate =

View File

@ -1534,7 +1534,8 @@ layer_set_pos(struct ivi_layout_layer *layer, wl_fixed_t pos_x,
} }
static void 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 weston_pointer_motion_event *event)
{ {
struct pointer_move_grab *pnt_move_grab = struct pointer_move_grab *pnt_move_grab =

View File

@ -108,7 +108,7 @@ weston_desktop_seat_popup_grab_pointer_focus(struct weston_pointer_grab *grab)
static void static void
weston_desktop_seat_popup_grab_pointer_motion(struct weston_pointer_grab *grab, 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) struct weston_pointer_motion_event *event)
{ {
weston_pointer_send_motion(grab->pointer, time, event); weston_pointer_send_motion(grab->pointer, time, event);

View File

@ -81,6 +81,7 @@
#endif #endif
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/timespec-util.h"
#include "compositor.h" #include "compositor.h"
#include "compositor-rdp.h" #include "compositor-rdp.h"
#include "pixman-renderer.h" #include "pixman-renderer.h"
@ -1029,11 +1030,13 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
struct rdp_output *output; struct rdp_output *output;
uint32_t button = 0; uint32_t button = 0;
bool need_frame = false; bool need_frame = false;
struct timespec time;
if (flags & PTR_FLAGS_MOVE) { if (flags & PTR_FLAGS_MOVE) {
output = peerContext->rdpBackend->output; output = peerContext->rdpBackend->output;
if (x < output->base.width && y < output->base.height) { 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); x, y);
need_frame = true; need_frame = true;
} }
@ -1088,11 +1091,12 @@ xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
{ {
RdpPeerContext *peerContext = (RdpPeerContext *)input->context; RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
struct rdp_output *output; struct rdp_output *output;
struct timespec time;
output = peerContext->rdpBackend->output; output = peerContext->rdpBackend->output;
if (x < output->base.width && y < output->base.height) { 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());
x, y); notify_motion_absolute(peerContext->item.seat, &time, x, y);
} }
FREERDP_CB_RETURN(TRUE); FREERDP_CB_RETURN(TRUE);

View File

@ -53,6 +53,7 @@
#include "shared/image-loader.h" #include "shared/image-loader.h"
#include "shared/os-compatibility.h" #include "shared/os-compatibility.h"
#include "shared/cairo-util.h" #include "shared/cairo-util.h"
#include "shared/timespec-util.h"
#include "fullscreen-shell-unstable-v1-client-protocol.h" #include "fullscreen-shell-unstable-v1-client-protocol.h"
#include "xdg-shell-unstable-v6-client-protocol.h" #include "xdg-shell-unstable-v6-client-protocol.h"
#include "presentation-time-server-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; enum theme_location location;
bool want_frame = false; bool want_frame = false;
double x, y; double x, y;
struct timespec ts;
if (!input->output) if (!input->output)
return; return;
@ -1626,7 +1628,8 @@ input_handle_motion(void *data, struct wl_pointer *pointer,
} }
if (location == THEME_LOCATION_CLIENT_AREA) { 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; want_frame = true;
} }

View File

@ -55,6 +55,7 @@
#include "shared/config-parser.h" #include "shared/config-parser.h"
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/image-loader.h" #include "shared/image-loader.h"
#include "shared/timespec-util.h"
#include "gl-renderer.h" #include "gl-renderer.h"
#include "weston-egl-ext.h" #include "weston-egl-ext.h"
#include "pixman-renderer.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 }; struct weston_pointer_motion_event motion_event = { 0 };
xcb_motion_notify_event_t *motion_notify = xcb_motion_notify_event_t *motion_notify =
(xcb_motion_notify_event_t *) event; (xcb_motion_notify_event_t *) event;
struct timespec time;
if (!b->has_xkb) if (!b->has_xkb)
update_xkb_state_from_core(b, motion_notify->state); 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 .dy = y - b->prev_y
}; };
notify_motion(&b->core_seat, weston_compositor_get_time(), timespec_from_msec(&time, weston_compositor_get_time());
&motion_event); notify_motion(&b->core_seat, &time, &motion_event);
notify_pointer_frame(&b->core_seat); notify_pointer_frame(&b->core_seat);
b->prev_x = x; b->prev_x = x;

View File

@ -249,7 +249,7 @@ enum weston_pointer_motion_mask {
struct weston_pointer_motion_event { struct weston_pointer_motion_event {
uint32_t mask; uint32_t mask;
uint64_t time_usec; struct timespec time;
double x; double x;
double y; double y;
double dx; double dx;
@ -268,7 +268,8 @@ struct weston_pointer_axis_event {
struct weston_pointer_grab; struct weston_pointer_grab;
struct weston_pointer_grab_interface { struct weston_pointer_grab_interface {
void (*focus)(struct weston_pointer_grab *grab); 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); struct weston_pointer_motion_event *event);
void (*button)(struct weston_pointer_grab *grab, void (*button)(struct weston_pointer_grab *grab,
uint32_t time, uint32_t button, uint32_t state); uint32_t time, uint32_t button, uint32_t state);
@ -423,7 +424,8 @@ weston_pointer_create(struct weston_seat *seat);
void void
weston_pointer_destroy(struct weston_pointer *pointer); weston_pointer_destroy(struct weston_pointer *pointer);
void 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); struct weston_pointer_motion_event *event);
bool bool
weston_pointer_has_focus_resource(struct weston_pointer *pointer); weston_pointer_has_focus_resource(struct weston_pointer *pointer);
@ -1363,10 +1365,10 @@ weston_view_activate(struct weston_view *view,
uint32_t flags); uint32_t flags);
void 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); struct weston_pointer_motion_event *event);
void 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); double x, double y);
void void
notify_button(struct weston_seat *seat, uint32_t time, int32_t button, notify_button(struct weston_seat *seat, uint32_t time, int32_t button,

View File

@ -34,6 +34,7 @@
#include "compositor.h" #include "compositor.h"
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/timespec-util.h"
struct weston_drag { struct weston_drag {
struct wl_client *client; struct wl_client *client;
@ -575,7 +576,8 @@ drag_grab_focus(struct weston_pointer_grab *grab)
} }
static void 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_motion_event *event)
{ {
struct weston_pointer_drag *drag = 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; struct weston_pointer *pointer = drag->grab.pointer;
float fx, fy; float fx, fy;
wl_fixed_t sx, sy; wl_fixed_t sx, sy;
uint32_t msecs;
weston_pointer_move(pointer, event); 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) { if (drag->base.focus_resource) {
msecs = timespec_to_msec(time);
weston_view_from_global_fixed(drag->base.focus, weston_view_from_global_fixed(drag->base.focus,
pointer->x, pointer->y, pointer->x, pointer->y,
&sx, &sy); &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);
} }
} }

View File

@ -38,6 +38,7 @@
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/os-compatibility.h" #include "shared/os-compatibility.h"
#include "shared/timespec-util.h"
#include "compositor.h" #include "compositor.h"
#include "relative-pointer-unstable-v1-server-protocol.h" #include "relative-pointer-unstable-v1-server-protocol.h"
#include "pointer-constraints-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 static void
pointer_send_relative_motion(struct weston_pointer *pointer, pointer_send_relative_motion(struct weston_pointer *pointer,
uint32_t time, const struct timespec *time,
struct weston_pointer_motion_event *event) struct weston_pointer_motion_event *event)
{ {
uint64_t time_usec; uint64_t time_usec;
@ -359,9 +360,9 @@ pointer_send_relative_motion(struct weston_pointer *pointer,
return; return;
resource_list = &pointer->focus_client->relative_pointer_resources; resource_list = &pointer->focus_client->relative_pointer_resources;
time_usec = event->time_usec; time_usec = timespec_to_usec(&event->time);
if (time_usec == 0) if (time_usec == 0)
time_usec = time * 1000ULL; time_usec = timespec_to_usec(time);
dxf = wl_fixed_from_double(dx); dxf = wl_fixed_from_double(dx);
dyf = wl_fixed_from_double(dy); dyf = wl_fixed_from_double(dy);
@ -379,22 +380,26 @@ pointer_send_relative_motion(struct weston_pointer *pointer,
} }
static void 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) wl_fixed_t sx, wl_fixed_t sy)
{ {
struct wl_list *resource_list; struct wl_list *resource_list;
struct wl_resource *resource; struct wl_resource *resource;
uint32_t msecs;
if (!pointer->focus_client) if (!pointer->focus_client)
return; return;
resource_list = &pointer->focus_client->pointer_resources; resource_list = &pointer->focus_client->pointer_resources;
msecs = timespec_to_msec(time);
wl_resource_for_each(resource, resource_list) 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 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) struct weston_pointer_motion_event *event)
{ {
wl_fixed_t x, y; wl_fixed_t x, y;
@ -418,7 +423,8 @@ weston_pointer_send_motion(struct weston_pointer *pointer, uint32_t time,
} }
static void 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) struct weston_pointer_motion_event *event)
{ {
weston_pointer_send_motion(grab->pointer, time, 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 WL_EXPORT void
notify_motion(struct weston_seat *seat, notify_motion(struct weston_seat *seat,
uint32_t time, const struct timespec *time,
struct weston_pointer_motion_event *event) struct weston_pointer_motion_event *event)
{ {
struct weston_compositor *ec = seat->compositor; 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 WL_EXPORT void
notify_motion_absolute(struct weston_seat *seat, notify_motion_absolute(struct weston_seat *seat, const struct timespec *time,
uint32_t time, double x, double y) double x, double y)
{ {
struct weston_compositor *ec = seat->compositor; struct weston_compositor *ec = seat->compositor;
struct weston_pointer *pointer = weston_seat_get_pointer(seat); 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 static void
locked_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, locked_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_motion_event *event)
{ {
pointer_send_relative_motion(grab->pointer, time, event); pointer_send_relative_motion(grab->pointer, time, event);
@ -4291,7 +4297,7 @@ maybe_warp_confined_pointer(struct weston_pointer_constraint *constraint)
static void static void
confined_pointer_grab_pointer_motion(struct weston_pointer_grab *grab, 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_motion_event *event)
{ {
struct weston_pointer_constraint *constraint = struct weston_pointer_constraint *constraint =

View File

@ -39,6 +39,7 @@
#include "compositor.h" #include "compositor.h"
#include "libinput-device.h" #include "libinput-device.h"
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/timespec-util.h"
void void
evdev_led_update(struct evdev_device *device, enum weston_led weston_leds) 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 = struct evdev_device *device =
libinput_device_get_user_data(libinput_device); libinput_device_get_user_data(libinput_device);
struct weston_pointer_motion_event event = { 0 }; struct weston_pointer_motion_event event = { 0 };
uint64_t time_usec = struct timespec time;
libinput_event_pointer_get_time_usec(pointer_event);
double dx_unaccel, dy_unaccel; 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); dx_unaccel = libinput_event_pointer_get_dx_unaccelerated(pointer_event);
dy_unaccel = libinput_event_pointer_get_dy_unaccelerated(pointer_event); dy_unaccel = libinput_event_pointer_get_dy_unaccelerated(pointer_event);
event = (struct weston_pointer_motion_event) { event = (struct weston_pointer_motion_event) {
.mask = WESTON_POINTER_MOTION_REL | .mask = WESTON_POINTER_MOTION_REL |
WESTON_POINTER_MOTION_REL_UNACCEL, WESTON_POINTER_MOTION_REL_UNACCEL,
.time_usec = time_usec, .time = time,
.dx = libinput_event_pointer_get_dx(pointer_event), .dx = libinput_event_pointer_get_dx(pointer_event),
.dy = libinput_event_pointer_get_dy(pointer_event), .dy = libinput_event_pointer_get_dy(pointer_event),
.dx_unaccel = dx_unaccel, .dx_unaccel = dx_unaccel,
.dy_unaccel = dy_unaccel, .dy_unaccel = dy_unaccel,
}; };
notify_motion(device->seat, notify_motion(device->seat, &time, &event);
libinput_event_pointer_get_time(pointer_event),
&event);
return true; return true;
} }
@ -118,14 +118,15 @@ handle_pointer_motion_absolute(
struct evdev_device *device = struct evdev_device *device =
libinput_device_get_user_data(libinput_device); libinput_device_get_user_data(libinput_device);
struct weston_output *output = device->output; struct weston_output *output = device->output;
uint32_t time; struct timespec time;
double x, y; double x, y;
uint32_t width, height; uint32_t width, height;
if (!output) if (!output)
return false; 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; width = device->output->current_mode->width;
height = device->output->current_mode->height; height = device->output->current_mode->height;
@ -135,7 +136,7 @@ handle_pointer_motion_absolute(
height); height);
weston_output_transform_coordinate(device->output, x, y, &x, &y); 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; return true;
} }

View File

@ -43,6 +43,7 @@
#endif /* ENABLE_EGL */ #endif /* ENABLE_EGL */
#include "shared/helpers.h" #include "shared/helpers.h"
#include "shared/timespec-util.h"
struct weston_test { struct weston_test {
struct weston_compositor *compositor; 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_seat *seat = get_seat(test);
struct weston_pointer *pointer = weston_seat_get_pointer(seat); struct weston_pointer *pointer = weston_seat_get_pointer(seat);
struct weston_pointer_motion_event event = { 0 }; struct weston_pointer_motion_event event = { 0 };
struct timespec time;
event = (struct weston_pointer_motion_event) { event = (struct weston_pointer_motion_event) {
.mask = WESTON_POINTER_MOTION_REL, .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), .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); notify_pointer_position(test, resource);
} }