[PATCH weston 09/12] libweston: Use struct timespec for touch down events

Alexandros Frantzis alexandros.frantzis at collabora.com
Thu Nov 16 16:20:58 UTC 2017


Change code related to touch down 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>
---
 desktop-shell/shell.c          |  8 +++++---
 ivi-shell/hmi-controller.c     |  3 ++-
 ivi-shell/ivi-shell.c          |  3 ++-
 libweston-desktop/seat.c       |  3 ++-
 libweston/bindings.c           |  3 ++-
 libweston/compositor-wayland.c | 14 +++++++++++---
 libweston/compositor.h         | 15 ++++++++-------
 libweston/data-device.c        |  5 +++--
 libweston/input.c              | 22 +++++++++++++---------
 libweston/libinput-device.c    | 14 +++++++++-----
 10 files changed, 57 insertions(+), 33 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index b8f00eb1..30cffed1 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -1331,7 +1331,8 @@ take_surface_to_workspace_by_seat(struct desktop_shell *shell,
 }
 
 static void
-touch_move_grab_down(struct weston_touch_grab *grab, uint32_t time,
+touch_move_grab_down(struct weston_touch_grab *grab,
+		     const struct timespec *time,
 		     int touch_id, wl_fixed_t x, wl_fixed_t y)
 {
 }
@@ -3274,7 +3275,7 @@ fullscreen_binding(struct weston_keyboard *keyboard,
 }
 
 static void
-touch_move_binding(struct weston_touch *touch, uint32_t time, void *data)
+touch_move_binding(struct weston_touch *touch, const struct timespec *time, void *data)
 {
 	struct weston_surface *focus;
 	struct weston_surface *surface;
@@ -3774,7 +3775,8 @@ click_to_activate_binding(struct weston_pointer *pointer,
 }
 
 static void
-touch_to_activate_binding(struct weston_touch *touch, uint32_t time,
+touch_to_activate_binding(struct weston_touch *touch,
+			  const struct timespec *time,
 			  void *data)
 {
 	if (touch->grab != &touch->default_grab)
diff --git a/ivi-shell/hmi-controller.c b/ivi-shell/hmi-controller.c
index d61e26b5..9b99668c 100644
--- a/ivi-shell/hmi-controller.c
+++ b/ivi-shell/hmi-controller.c
@@ -1584,7 +1584,8 @@ pointer_move_workspace_grab_button(struct weston_pointer_grab *grab,
 }
 
 static void
-touch_nope_grab_down(struct weston_touch_grab *grab, uint32_t time,
+touch_nope_grab_down(struct weston_touch_grab *grab,
+		     const struct timespec *time,
 		     int touch_id, wl_fixed_t sx, wl_fixed_t sy)
 {
 }
diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
index e675a3bd..766a1fd1 100644
--- a/ivi-shell/ivi-shell.c
+++ b/ivi-shell/ivi-shell.c
@@ -463,7 +463,8 @@ click_to_activate_binding(struct weston_pointer *pointer,
 }
 
 static void
-touch_to_activate_binding(struct weston_touch *touch, uint32_t time,
+touch_to_activate_binding(struct weston_touch *touch,
+			  const struct timespec *time,
 			  void *data)
 {
 	if (touch->grab != &touch->default_grab)
diff --git a/libweston-desktop/seat.c b/libweston-desktop/seat.c
index bba2605f..3e044fe1 100644
--- a/libweston-desktop/seat.c
+++ b/libweston-desktop/seat.c
@@ -180,7 +180,8 @@ static const struct weston_pointer_grab_interface weston_desktop_seat_pointer_po
 
 static void
 weston_desktop_seat_popup_grab_touch_down(struct weston_touch_grab *grab,
-					  uint32_t time, int touch_id,
+					  const struct timespec *time,
+					  int touch_id,
 					  wl_fixed_t sx, wl_fixed_t sy)
 {
 	weston_touch_send_down(grab->touch, time, touch_id, sx, sy);
diff --git a/libweston/bindings.c b/libweston/bindings.c
index 79c043e9..d9e280e4 100644
--- a/libweston/bindings.c
+++ b/libweston/bindings.c
@@ -377,7 +377,8 @@ weston_compositor_run_button_binding(struct weston_compositor *compositor,
 
 void
 weston_compositor_run_touch_binding(struct weston_compositor *compositor,
-				    struct weston_touch *touch, uint32_t time,
+				    struct weston_touch *touch,
+				    const struct timespec *time,
 				    int touch_type)
 {
 	struct weston_binding *b, *tmp;
diff --git a/libweston/compositor-wayland.c b/libweston/compositor-wayland.c
index 7b96b7be..3bdfb03e 100644
--- a/libweston/compositor-wayland.c
+++ b/libweston/compositor-wayland.c
@@ -1974,10 +1974,13 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch,
 	bool first_touch;
 	int32_t fx, fy;
 	double x, y;
+	struct timespec ts;
 
 	x = wl_fixed_to_double(fixed_x);
 	y = wl_fixed_to_double(fixed_y);
 
+	timespec_from_msec(&ts, time);
+
 	first_touch = (input->touch_points == 0);
 	input->touch_points++;
 
@@ -2015,7 +2018,7 @@ input_handle_touch_down(void *data, struct wl_touch *wl_touch,
 
 	weston_output_transform_coordinate(&output->base, x, y, &x, &y);
 
-	notify_touch(&input->base, time, id, x, y, WL_TOUCH_DOWN);
+	notify_touch(&input->base, &ts, id, x, y, WL_TOUCH_DOWN);
 	input->touch_active = true;
 }
 
@@ -2026,6 +2029,9 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch,
 	struct wayland_input *input = data;
 	struct wayland_output *output = input->touch_focus;
 	bool active = input->touch_active;
+	struct timespec ts;
+
+	timespec_from_msec(&ts, time);
 
 	input->touch_points--;
 	if (input->touch_points == 0) {
@@ -2053,7 +2059,7 @@ input_handle_touch_up(void *data, struct wl_touch *wl_touch,
 	}
 
 	if (active)
-		notify_touch(&input->base, time, id, 0, 0, WL_TOUCH_UP);
+		notify_touch(&input->base, &ts, id, 0, 0, WL_TOUCH_UP);
 }
 
 static void
@@ -2065,9 +2071,11 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch,
 	struct wayland_output *output = input->touch_focus;
 	int32_t fx, fy;
 	double x, y;
+	struct timespec ts;
 
 	x = wl_fixed_to_double(fixed_x);
 	y = wl_fixed_to_double(fixed_y);
+	timespec_from_msec(&ts, time);
 
 	if (!output || !input->touch_active)
 		return;
@@ -2080,7 +2088,7 @@ input_handle_touch_motion(void *data, struct wl_touch *wl_touch,
 
 	weston_output_transform_coordinate(&output->base, x, y, &x, &y);
 
-	notify_touch(&input->base, time, id, x, y, WL_TOUCH_MOTION);
+	notify_touch(&input->base, &ts, id, x, y, WL_TOUCH_MOTION);
 }
 
 static void
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 964c3233..9aadd83f 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -305,7 +305,7 @@ struct weston_keyboard_grab {
 struct weston_touch_grab;
 struct weston_touch_grab_interface {
 	void (*down)(struct weston_touch_grab *grab,
-			uint32_t time,
+			const struct timespec *time,
 			int touch_id,
 			wl_fixed_t sx,
 			wl_fixed_t sy);
@@ -412,7 +412,7 @@ struct weston_touch {
 	int grab_touch_id;
 	wl_fixed_t grab_x, grab_y;
 	uint32_t grab_serial;
-	uint32_t grab_time;
+	struct timespec grab_time;
 };
 
 void
@@ -516,7 +516,7 @@ weston_touch_end_grab(struct weston_touch *touch);
 bool
 weston_touch_has_focus_resource(struct weston_touch *touch);
 void
-weston_touch_send_down(struct weston_touch *touch, uint32_t time,
+weston_touch_send_down(struct weston_touch *touch, const struct timespec *time,
 		       int touch_id, wl_fixed_t x, wl_fixed_t y);
 void
 weston_touch_send_up(struct weston_touch *touch, uint32_t time, int touch_id);
@@ -1402,8 +1402,8 @@ void
 notify_keyboard_focus_out(struct weston_seat *seat);
 
 void
-notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
-	     double x, double y, int touch_type);
+notify_touch(struct weston_seat *seat, const struct timespec *time,
+	     int touch_id, double x, double y, int touch_type);
 void
 notify_touch_frame(struct weston_seat *seat);
 
@@ -1506,7 +1506,7 @@ weston_compositor_add_button_binding(struct weston_compositor *compositor,
 				     void *data);
 
 typedef void (*weston_touch_binding_handler_t)(struct weston_touch *touch,
-					       uint32_t time,
+					       const struct timespec *time,
 					       void *data);
 struct weston_binding *
 weston_compositor_add_touch_binding(struct weston_compositor *compositor,
@@ -1559,7 +1559,8 @@ weston_compositor_run_button_binding(struct weston_compositor *compositor,
 				     enum wl_pointer_button_state value);
 void
 weston_compositor_run_touch_binding(struct weston_compositor *compositor,
-				    struct weston_touch *touch, uint32_t time,
+				    struct weston_touch *touch,
+				    const struct timespec *time,
 				    int touch_type);
 int
 weston_compositor_run_axis_binding(struct weston_compositor *compositor,
diff --git a/libweston/data-device.c b/libweston/data-device.c
index 674d3a24..1c7d546c 100644
--- a/libweston/data-device.c
+++ b/libweston/data-device.c
@@ -718,8 +718,9 @@ static const struct weston_pointer_grab_interface pointer_drag_grab_interface =
 };
 
 static void
-drag_grab_touch_down(struct weston_touch_grab *grab, uint32_t time,
-		int touch_id, wl_fixed_t sx, wl_fixed_t sy)
+drag_grab_touch_down(struct weston_touch_grab *grab,
+		     const struct timespec *time, int touch_id,
+		     wl_fixed_t sx, wl_fixed_t sy)
 {
 }
 
diff --git a/libweston/input.c b/libweston/input.c
index a1085463..73334bf8 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -670,7 +670,7 @@ weston_touch_has_focus_resource(struct weston_touch *touch)
  * resources of the client which currently has the surface with touch focus.
  */
 WL_EXPORT void
-weston_touch_send_down(struct weston_touch *touch, uint32_t time,
+weston_touch_send_down(struct weston_touch *touch, const struct timespec *time,
 		       int touch_id, wl_fixed_t x, wl_fixed_t y)
 {
 	struct wl_display *display = touch->seat->compositor->wl_display;
@@ -678,6 +678,7 @@ weston_touch_send_down(struct weston_touch *touch, uint32_t time,
 	struct wl_resource *resource;
 	struct wl_list *resource_list;
 	wl_fixed_t sx, sy;
+	uint32_t msecs;
 
 	if (!weston_touch_has_focus_resource(touch))
 		return;
@@ -686,15 +687,17 @@ weston_touch_send_down(struct weston_touch *touch, uint32_t time,
 
 	resource_list = &touch->focus_resource_list;
 	serial = wl_display_next_serial(display);
+	msecs = timespec_to_msec(time);
 	wl_resource_for_each(resource, resource_list)
-			wl_touch_send_down(resource, serial, time,
+			wl_touch_send_down(resource, serial, msecs,
 					   touch->focus->surface->resource,
 					   touch_id, sx, sy);
 }
 
 static void
-default_grab_touch_down(struct weston_touch_grab *grab, uint32_t time,
-			int touch_id, wl_fixed_t x, wl_fixed_t y)
+default_grab_touch_down(struct weston_touch_grab *grab,
+			const struct timespec *time, int touch_id,
+			wl_fixed_t x, wl_fixed_t y)
 {
 	weston_touch_send_down(grab->touch, time, touch_id, x, y);
 }
@@ -2140,8 +2143,8 @@ weston_touch_set_focus(struct weston_touch *touch, struct weston_view *view)
  *
  */
 WL_EXPORT void
-notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
-             double double_x, double double_y, int touch_type)
+notify_touch(struct weston_seat *seat, const struct timespec *time,
+	     int touch_id, double double_x, double double_y, int touch_type)
 {
 	struct weston_compositor *ec = seat->compositor;
 	struct weston_touch *touch = weston_seat_get_touch(seat);
@@ -2186,7 +2189,7 @@ notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
 			touch->grab_serial =
 				wl_display_get_serial(ec->wl_display);
 			touch->grab_touch_id = touch_id;
-			touch->grab_time = time;
+			touch->grab_time = *time;
 			touch->grab_x = x;
 			touch->grab_y = y;
 		}
@@ -2197,7 +2200,8 @@ notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
 		if (!ev)
 			break;
 
-		grab->interface->motion(grab, time, touch_id, x, y);
+		grab->interface->motion(grab, timespec_to_msec(time),
+					touch_id, x, y);
 		break;
 	case WL_TOUCH_UP:
 		if (touch->num_tp == 0) {
@@ -2211,7 +2215,7 @@ notify_touch(struct weston_seat *seat, uint32_t time, int touch_id,
 		weston_compositor_idle_release(ec);
 		touch->num_tp--;
 
-		grab->interface->up(grab, time, touch_id);
+		grab->interface->up(grab, timespec_to_msec(time), touch_id);
 		if (touch->num_tp == 0)
 			weston_touch_set_focus(touch, NULL);
 		break;
diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c
index bd7a7596..af2b6d23 100644
--- a/libweston/libinput-device.c
+++ b/libweston/libinput-device.c
@@ -306,13 +306,14 @@ handle_touch_with_coords(struct libinput_device *libinput_device,
 	double x;
 	double y;
 	uint32_t width, height;
-	uint32_t time;
+	struct timespec time;
 	int32_t slot;
 
 	if (!device->output)
 		return;
 
-	time = libinput_event_touch_get_time(touch_event);
+	timespec_from_usec(&time,
+			   libinput_event_touch_get_time_usec(touch_event));
 	slot = libinput_event_touch_get_seat_slot(touch_event);
 
 	width = device->output->current_mode->width;
@@ -323,7 +324,7 @@ handle_touch_with_coords(struct libinput_device *libinput_device,
 	weston_output_transform_coordinate(device->output,
 					   x, y, &x, &y);
 
-	notify_touch(device->seat, time, slot, x, y, touch_type);
+	notify_touch(device->seat, &time, slot, x, y, touch_type);
 }
 
 static void
@@ -346,10 +347,13 @@ handle_touch_up(struct libinput_device *libinput_device,
 {
 	struct evdev_device *device =
 		libinput_device_get_user_data(libinput_device);
-	uint32_t time = libinput_event_touch_get_time(touch_event);
+	struct timespec time;
 	int32_t slot = libinput_event_touch_get_seat_slot(touch_event);
 
-	notify_touch(device->seat, time, slot, 0, 0, WL_TOUCH_UP);
+	timespec_from_usec(&time,
+			   libinput_event_touch_get_time_usec(touch_event));
+
+	notify_touch(device->seat, &time, slot, 0, 0, WL_TOUCH_UP);
 }
 
 static void
-- 
2.14.1



More information about the wayland-devel mailing list