2017-06-14 11:40:03 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <assert.h>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <libinput.h>
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 10:27:45 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <wlr/interfaces/wlr_touch.h>
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 11:40:03 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include "backend/libinput.h"
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-12 21:29:23 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "util/signal.h"
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 11:40:03 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const struct wlr_touch_impl libinput_touch_impl = {
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-02 16:07:40 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									.name = "libinput-touch",
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-09 16:03:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								void init_device_touch(struct wlr_libinput_input_device *dev) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									const char *name = libinput_device_get_name(dev->handle);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct wlr_touch *wlr_touch = &dev->touch;
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-09 16:03:12 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_touch_init(wlr_touch, &libinput_touch_impl, name);
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_touch->base.vendor = libinput_device_get_id_vendor(dev->handle);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_touch->base.product = libinput_device_get_id_product(dev->handle);
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-08 16:54:28 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									libinput_device_get_size(dev->handle, &wlr_touch->width_mm,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										&wlr_touch->height_mm);
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								struct wlr_libinput_input_device *device_from_touch(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										struct wlr_touch *wlr_touch) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									assert(wlr_touch->impl == &libinput_touch_impl);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct wlr_libinput_input_device *dev =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										wl_container_of(wlr_touch, dev, touch);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return dev;
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 11:40:03 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void handle_touch_down(struct libinput_event *event,
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct wlr_touch *touch) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct libinput_event_touch *tevent =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										libinput_event_get_touch_event(event);
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-09 16:01:14 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct wlr_touch_down_event wlr_event = { 0 };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_event.touch = touch;
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-30 15:43:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.time_msec =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										usec_to_msec(libinput_event_touch_get_time_usec(tevent));
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-15 13:49:46 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent);
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-28 11:04:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1);
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&touch->events.down, &wlr_event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void handle_touch_up(struct libinput_event *event,
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct wlr_touch *touch) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct libinput_event_touch *tevent =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										libinput_event_get_touch_event(event);
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-09 16:01:14 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct wlr_touch_up_event wlr_event = { 0 };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_event.touch = touch;
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-30 15:43:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.time_msec =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										usec_to_msec(libinput_event_touch_get_time_usec(tevent));
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-19 14:13:52 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent);
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&touch->events.up, &wlr_event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void handle_touch_motion(struct libinput_event *event,
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct wlr_touch *touch) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct libinput_event_touch *tevent =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										libinput_event_get_touch_event(event);
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-09 16:01:14 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct wlr_touch_motion_event wlr_event = { 0 };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_event.touch = touch;
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-30 15:43:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.time_msec =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										usec_to_msec(libinput_event_touch_get_time_usec(tevent));
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-19 14:13:52 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent);
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-28 11:04:40 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.x = libinput_event_touch_get_x_transformed(tevent, 1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_event.y = libinput_event_touch_get_y_transformed(tevent, 1);
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&touch->events.motion, &wlr_event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void handle_touch_cancel(struct libinput_event *event,
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct wlr_touch *touch) {
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct libinput_event_touch *tevent =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										libinput_event_get_touch_event(event);
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-09 16:01:14 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct wlr_touch_cancel_event wlr_event = { 0 };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_event.touch = touch;
							 | 
						
					
						
							
								
									
										
										
										
											2017-10-30 15:43:06 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.time_msec =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										usec_to_msec(libinput_event_touch_get_time_usec(tevent));
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-19 14:13:52 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.touch_id = libinput_event_touch_get_seat_slot(tevent);
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&touch->events.cancel, &wlr_event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-30 11:39:17 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void handle_touch_frame(struct libinput_event *event,
							 | 
						
					
						
							
								
									
										
										
										
											2022-02-23 14:06:02 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct wlr_touch *touch) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&touch->events.frame, NULL);
							 | 
						
					
						
							
								
									
										
										
										
											2021-06-30 11:39:17 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 |