2017-06-14 11:40:03 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <assert.h>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#include <libinput.h>
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-12 21:29:23 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <stdlib.h>
							 | 
						
					
						
							
								
									
										
										
										
											2017-07-11 19:18:34 +12:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <wlr/backend/session.h>
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 10:27:45 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <wlr/interfaces/wlr_touch.h>
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-12 21:29:23 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <wlr/types/wlr_input_device.h>
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-21 12:10:07 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include <wlr/util/log.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
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-04-25 23:24:58 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								struct wlr_touch *create_libinput_touch(
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-13 00:50:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct libinput_device *libinput_dev) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									assert(libinput_dev);
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-14 16:07:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct wlr_touch *wlr_touch = calloc(1, sizeof(struct wlr_touch));
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if (!wlr_touch) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-09 22:49:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										wlr_log(WLR_ERROR, "Unable to allocate wlr_touch");
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-14 16:07:00 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return NULL;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_touch_init(wlr_touch, NULL);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return wlr_touch;
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 11:40:03 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void handle_touch_down(struct libinput_event *event,
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-13 00:50:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct libinput_device *libinput_dev) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct wlr_input_device *wlr_dev =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if (!wlr_dev) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-09 22:49:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct libinput_event_touch *tevent =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										libinput_event_get_touch_event(event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-11 18:38:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct wlr_event_touch_down wlr_event = { 0 };
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-27 11:44:55 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.device = wlr_dev;
							 | 
						
					
						
							
								
									
										
										
										
											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);
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-12 09:12:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&wlr_dev->touch->events.down, &wlr_event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void handle_touch_up(struct libinput_event *event,
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-13 00:50:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct libinput_device *libinput_dev) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct wlr_input_device *wlr_dev =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if (!wlr_dev) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-09 22:49:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct libinput_event_touch *tevent =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										libinput_event_get_touch_event(event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-11 18:38:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct wlr_event_touch_up wlr_event = { 0 };
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-27 11:44:55 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.device = wlr_dev;
							 | 
						
					
						
							
								
									
										
										
										
											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-02-12 09:12:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&wlr_dev->touch->events.up, &wlr_event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void handle_touch_motion(struct libinput_event *event,
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-13 00:50:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct libinput_device *libinput_dev) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct wlr_input_device *wlr_dev =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if (!wlr_dev) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-09 22:49:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct libinput_event_touch *tevent =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										libinput_event_get_touch_event(event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-11 18:38:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct wlr_event_touch_motion wlr_event = { 0 };
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-27 11:44:55 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.device = wlr_dev;
							 | 
						
					
						
							
								
									
										
										
										
											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);
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-12 09:12:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&wlr_dev->touch->events.motion, &wlr_event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								void handle_touch_cancel(struct libinput_event *event,
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-13 00:50:09 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										struct libinput_device *libinput_dev) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct wlr_input_device *wlr_dev =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if (!wlr_dev) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-09 22:49:54 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
							 | 
						
					
						
							
								
									
										
										
										
											2017-06-14 14:50:09 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct libinput_event_touch *tevent =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										libinput_event_get_touch_event(event);
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-11 18:38:27 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct wlr_event_touch_cancel wlr_event = { 0 };
							 | 
						
					
						
							
								
									
										
										
										
											2017-08-27 11:44:55 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_event.device = wlr_dev;
							 | 
						
					
						
							
								
									
										
										
										
											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-02-12 09:12:31 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&wlr_dev->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,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										struct libinput_device *libinput_dev) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									struct wlr_input_device *wlr_dev =
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										get_appropriate_device(WLR_INPUT_DEVICE_TOUCH, libinput_dev);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if (!wlr_dev) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										wlr_log(WLR_DEBUG, "Got a touch event for a device with no touch?");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									wlr_signal_emit_safe(&wlr_dev->touch->events.frame, NULL);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |