wlr-seat: refactor touch grab interface
This commit is contained in:
		
							parent
							
								
									b310fdac82
								
							
						
					
					
						commit
						4eab61f86f
					
				|  | @ -24,6 +24,22 @@ struct wlr_seat_client { | ||||||
| 	struct wl_list link; | 	struct wl_list link; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | struct wlr_touch_point { | ||||||
|  | 	int32_t touch_id; | ||||||
|  | 	struct wlr_surface *surface; | ||||||
|  | 	struct wlr_seat_client *client; | ||||||
|  | 	double sx, sy; | ||||||
|  | 
 | ||||||
|  | 	struct wl_listener surface_destroy; | ||||||
|  | 	struct wl_listener resource_destroy; | ||||||
|  | 
 | ||||||
|  | 	struct { | ||||||
|  | 		struct wl_signal destroy; | ||||||
|  | 	} events; | ||||||
|  | 
 | ||||||
|  | 	struct wl_list link; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| struct wlr_seat_pointer_grab; | struct wlr_seat_pointer_grab; | ||||||
| 
 | 
 | ||||||
| struct wlr_pointer_grab_interface { | struct wlr_pointer_grab_interface { | ||||||
|  | @ -52,11 +68,12 @@ struct wlr_keyboard_grab_interface { | ||||||
| struct wlr_seat_touch_grab; | struct wlr_seat_touch_grab; | ||||||
| 
 | 
 | ||||||
| struct wlr_touch_grab_interface { | struct wlr_touch_grab_interface { | ||||||
| 	void (*down)(struct wlr_seat_touch_grab *grab, struct wlr_surface *surface, | 	void (*down)(struct wlr_seat_touch_grab *grab, uint32_t time, | ||||||
| 			uint32_t time, int32_t touch_id, double sx, double sy); | 			struct wlr_touch_point *point); | ||||||
| 	void (*up)(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t touch_id); | 	void (*up)(struct wlr_seat_touch_grab *grab, uint32_t time, | ||||||
| 	void (*motion)(struct wlr_seat_touch_grab *grab, uint32_t time, int32_t | 			struct wlr_touch_point *point); | ||||||
| 			touch_id, double sx, double sy); | 	void (*motion)(struct wlr_seat_touch_grab *grab, uint32_t time, | ||||||
|  | 			struct wlr_touch_point *point); | ||||||
| 	// XXX this will conflict with the actual touch cancel which is different so
 | 	// XXX this will conflict with the actual touch cancel which is different so
 | ||||||
| 	// we need to rename this
 | 	// we need to rename this
 | ||||||
| 	void (*cancel)(struct wlr_seat_touch_grab *grab); | 	void (*cancel)(struct wlr_seat_touch_grab *grab); | ||||||
|  | @ -127,18 +144,6 @@ struct wlr_seat_keyboard_state { | ||||||
| 	struct wlr_seat_keyboard_grab *default_grab; | 	struct wlr_seat_keyboard_grab *default_grab; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| struct wlr_touch_point { |  | ||||||
| 	int32_t touch_id; |  | ||||||
| 	struct wlr_surface *surface; |  | ||||||
| 	struct wlr_seat_client *client; |  | ||||||
| 	double sx, sy; |  | ||||||
| 
 |  | ||||||
| 	struct wl_listener surface_destroy; |  | ||||||
| 	struct wl_listener resource_destroy; |  | ||||||
| 
 |  | ||||||
| 	struct wl_list link; |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| struct wlr_seat_touch_state { | struct wlr_seat_touch_state { | ||||||
| 	struct wlr_seat *seat; | 	struct wlr_seat *seat; | ||||||
| 	struct wl_list touch_points; // wlr_touch_point::link
 | 	struct wl_list touch_points; // wlr_touch_point::link
 | ||||||
|  | @ -414,10 +419,13 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Notify the seat that the touch point given by `touch_id` has moved. Defers to |  * Notify the seat that the touch point given by `touch_id` has moved. Defers to | ||||||
|  * any grab of the touch device. |  * any grab of the touch device. The seat should be notified of touch motion | ||||||
|  |  * even if the surface is not the owner of the touch point for processing by | ||||||
|  |  * grabs. | ||||||
|  */ |  */ | ||||||
| void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, | void wlr_seat_touch_notify_motion(struct wlr_seat *seat, | ||||||
| 		int32_t touch_id, double sx, double sy); | 		struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, | ||||||
|  | 		double sy); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Send a touch down event to the client of the given surface. All future touch |  * Send a touch down event to the client of the given surface. All future touch | ||||||
|  | @ -442,7 +450,7 @@ void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time, | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Send a touch motion event for the touch point given by the `touch_id`. The |  * Send a touch motion event for the touch point given by the `touch_id`. The | ||||||
|  * event will go to the cleint for the surface given in the corresponding touch |  * event will go to the client for the surface given in the corresponding touch | ||||||
|  * down event. Compositors should use `wlr_seat_touch_notify_motion()` to |  * down event. Compositors should use `wlr_seat_touch_notify_motion()` to | ||||||
|  * respect any grabs of the touch device. |  * respect any grabs of the touch device. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
|  | @ -261,8 +261,8 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, | ||||||
| 	double sx, sy; | 	double sx, sy; | ||||||
| 	view_at(desktop, lx, ly, &surface, &sx, &sy); | 	view_at(desktop, lx, ly, &surface, &sx, &sy); | ||||||
| 
 | 
 | ||||||
| 	if (surface == point->surface) { | 	if (surface) { | ||||||
| 		wlr_seat_touch_notify_motion(cursor->seat->seat, event->time_msec, | 		wlr_seat_touch_notify_motion(cursor->seat->seat, surface, event->time_msec, | ||||||
| 			event->slot, sx, sy); | 			event->slot, sx, sy); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -527,15 +527,14 @@ wlr_pointer_grab_interface wlr_data_device_pointer_drag_interface = { | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| static void touch_drag_down(struct wlr_seat_touch_grab *grab, | static void touch_drag_down(struct wlr_seat_touch_grab *grab, | ||||||
| 		struct wlr_surface *surface, | 		uint32_t time, struct wlr_touch_point *point) { | ||||||
| 			uint32_t time, int32_t touch_id, double sx, double sy) { |  | ||||||
| 	// eat the event
 | 	// eat the event
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, | static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, | ||||||
| 		int32_t touch_id) { | 		struct wlr_touch_point *point) { | ||||||
| 	struct wlr_drag *drag = grab->data; | 	struct wlr_drag *drag = grab->data; | ||||||
| 	if (drag->grab_touch_id != touch_id) { | 	if (drag->grab_touch_id != point->touch_id) { | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | @ -547,11 +546,11 @@ static void touch_drag_up(struct wlr_seat_touch_grab *grab, uint32_t time, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time, | static void touch_drag_motion(struct wlr_seat_touch_grab *grab, uint32_t time, | ||||||
| 		int32_t touch_id, double sx, double sy) { | 		struct wlr_touch_point *point) { | ||||||
| 	struct wlr_drag *drag = grab->data; | 	struct wlr_drag *drag = grab->data; | ||||||
| 	if (drag->focus && drag->focus_client && drag->focus_client->data_device) { | 	if (drag->focus && drag->focus_client && drag->focus_client->data_device) { | ||||||
| 		wl_data_device_send_motion(drag->focus_client->data_device, time, | 		wl_data_device_send_motion(drag->focus_client->data_device, time, | ||||||
| 			wl_fixed_from_double(sx), wl_fixed_from_double(sy)); | 			wl_fixed_from_double(point->sx), wl_fixed_from_double(point->sy)); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -300,20 +300,21 @@ static const struct wlr_keyboard_grab_interface default_keyboard_grab_impl = { | ||||||
| 	.cancel = default_keyboard_cancel, | 	.cancel = default_keyboard_cancel, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| static void default_touch_down(struct wlr_seat_touch_grab *grab, | static void default_touch_down(struct wlr_seat_touch_grab *grab, uint32_t time, | ||||||
| 		struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, | 		struct wlr_touch_point *point) { | ||||||
| 		double sy) { | 	wlr_seat_touch_send_down(grab->seat, point->surface, time, point->touch_id, | ||||||
| 	wlr_seat_touch_send_down(grab->seat, surface, time, touch_id, sx, sy); | 		point->sx, point->sy); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void default_touch_up(struct wlr_seat_touch_grab *grab, uint32_t time, | static void default_touch_up(struct wlr_seat_touch_grab *grab, uint32_t time, | ||||||
| 		int32_t touch_id) { | 		struct wlr_touch_point *point) { | ||||||
| 	wlr_seat_touch_send_up(grab->seat, time, touch_id); | 	wlr_seat_touch_send_up(grab->seat, time, point->touch_id); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void default_touch_motion(struct wlr_seat_touch_grab *grab, | static void default_touch_motion(struct wlr_seat_touch_grab *grab, | ||||||
| 		uint32_t time, int32_t touch_id, double sx, double sy) { | 		uint32_t time, struct wlr_touch_point *point) { | ||||||
| 	wlr_seat_touch_send_motion(grab->seat, time, touch_id, sx, sy); | 	wlr_seat_touch_send_motion(grab->seat, time, point->touch_id, point->sx, | ||||||
|  | 		point->sy); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void default_touch_cancel(struct wlr_seat_touch_grab *grab) { | static void default_touch_cancel(struct wlr_seat_touch_grab *grab) { | ||||||
|  | @ -894,6 +895,7 @@ void wlr_seat_touch_end_grab(struct wlr_seat *wlr_seat) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void touch_point_destroy(struct wlr_touch_point *point) { | static void touch_point_destroy(struct wlr_touch_point *point) { | ||||||
|  | 	wl_signal_emit(&point->events.destroy, point); | ||||||
| 	wl_list_remove(&point->surface_destroy.link); | 	wl_list_remove(&point->surface_destroy.link); | ||||||
| 	wl_list_remove(&point->resource_destroy.link); | 	wl_list_remove(&point->resource_destroy.link); | ||||||
| 	wl_list_remove(&point->link); | 	wl_list_remove(&point->link); | ||||||
|  | @ -936,6 +938,8 @@ static struct wlr_touch_point *touch_point_create( | ||||||
| 	point->sx = sx; | 	point->sx = sx; | ||||||
| 	point->sy = sy; | 	point->sy = sy; | ||||||
| 
 | 
 | ||||||
|  | 	wl_signal_init(&point->events.destroy); | ||||||
|  | 
 | ||||||
| 	wl_signal_add(&surface->events.destroy, &point->surface_destroy); | 	wl_signal_add(&surface->events.destroy, &point->surface_destroy); | ||||||
| 	point->surface_destroy.notify = handle_touch_point_surface_destroy; | 	point->surface_destroy.notify = handle_touch_point_surface_destroy; | ||||||
| 	wl_resource_add_destroy_listener(surface->resource, | 	wl_resource_add_destroy_listener(surface->resource, | ||||||
|  | @ -971,7 +975,8 @@ void wlr_seat_touch_notify_down(struct wlr_seat *seat, | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	grab->interface->down(grab, surface, time, touch_id, sx, sy); | 	grab->interface->down(grab, time, point); | ||||||
|  | 
 | ||||||
| 	if (wl_list_length(&seat->touch_state.touch_points) == 1) { | 	if (wl_list_length(&seat->touch_state.touch_points) == 1) { | ||||||
| 		seat->touch_state.grab_serial = wl_display_get_serial(seat->display); | 		seat->touch_state.grab_serial = wl_display_get_serial(seat->display); | ||||||
| 		seat->touch_state.grab_id = touch_id; | 		seat->touch_state.grab_id = touch_id; | ||||||
|  | @ -988,12 +993,14 @@ void wlr_seat_touch_notify_up(struct wlr_seat *seat, uint32_t time, | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	grab->interface->up(grab, time, touch_id); | 	grab->interface->up(grab, time, point); | ||||||
|  | 
 | ||||||
| 	touch_point_destroy(point); | 	touch_point_destroy(point); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, | void wlr_seat_touch_notify_motion(struct wlr_seat *seat, | ||||||
| 		int32_t touch_id, double sx, double sy) { | 		struct wlr_surface *surface, uint32_t time, int32_t touch_id, double sx, | ||||||
|  | 		double sy) { | ||||||
| 	clock_gettime(CLOCK_MONOTONIC, &seat->last_event); | 	clock_gettime(CLOCK_MONOTONIC, &seat->last_event); | ||||||
| 	struct wlr_seat_touch_grab *grab = seat->touch_state.grab; | 	struct wlr_seat_touch_grab *grab = seat->touch_state.grab; | ||||||
| 	struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); | 	struct wlr_touch_point *point = wlr_seat_touch_get_point(seat, touch_id); | ||||||
|  | @ -1005,7 +1012,7 @@ void wlr_seat_touch_notify_motion(struct wlr_seat *seat, uint32_t time, | ||||||
| 	point->sx = sx; | 	point->sx = sx; | ||||||
| 	point->sy = sy; | 	point->sy = sy; | ||||||
| 
 | 
 | ||||||
| 	grab->interface->motion(grab, time, touch_id, sx, sy); | 	grab->interface->motion(grab, time, point); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void wlr_seat_touch_send_down(struct wlr_seat *seat, | void wlr_seat_touch_send_down(struct wlr_seat *seat, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue