mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	Some kind of support for touchscreen
This commit is contained in:
		
							parent
							
								
									43db4015f9
								
							
						
					
					
						commit
						96c8be98a6
					
				
					 1 changed files with 32 additions and 16 deletions
				
			
		| 
						 | 
					@ -39,6 +39,7 @@ struct evdev_input_device {
 | 
				
			||||||
	int tool, new_x, new_y;
 | 
						int tool, new_x, new_y;
 | 
				
			||||||
	int base_x, base_y;
 | 
						int base_x, base_y;
 | 
				
			||||||
	int fd;
 | 
						int fd;
 | 
				
			||||||
 | 
						int min_x, max_x, min_y, max_y;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void evdev_input_device_data(int fd, uint32_t mask, void *data)
 | 
					static void evdev_input_device_data(int fd, uint32_t mask, void *data)
 | 
				
			||||||
| 
						 | 
					@ -50,6 +51,10 @@ static void evdev_input_device_data(int fd, uint32_t mask, void *data)
 | 
				
			||||||
	int x, y;
 | 
						int x, y;
 | 
				
			||||||
	uint32_t time;
 | 
						uint32_t time;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* FIXME: Obviously we need to not hardcode these here, but
 | 
				
			||||||
 | 
						 * instead get the values from the output it's associated with. */
 | 
				
			||||||
 | 
						const int screen_width = 1024, screen_height = 600;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ec = (struct wlsc_compositor *)
 | 
						ec = (struct wlsc_compositor *)
 | 
				
			||||||
		device->master->base.input_device.compositor;
 | 
							device->master->base.input_device.compositor;
 | 
				
			||||||
	if (!ec->focus)
 | 
						if (!ec->focus)
 | 
				
			||||||
| 
						 | 
					@ -88,21 +93,16 @@ static void evdev_input_device_data(int fd, uint32_t mask, void *data)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case EV_ABS:
 | 
							case EV_ABS:
 | 
				
			||||||
			absolute_event = 1;
 | 
					 | 
				
			||||||
			switch (e->code) {
 | 
								switch (e->code) {
 | 
				
			||||||
			case ABS_X:
 | 
								case ABS_X:
 | 
				
			||||||
				if (device->new_x) {
 | 
									absolute_event = device->tool;
 | 
				
			||||||
					device->base_x = x - value;
 | 
									x = (value - device->min_x) * screen_width /
 | 
				
			||||||
					device->new_x = 0;
 | 
										(device->max_x - device->min_x);
 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				x = device->base_x + value;
 | 
					 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case ABS_Y:
 | 
								case ABS_Y:
 | 
				
			||||||
				if (device->new_y) {
 | 
									absolute_event = device->tool;
 | 
				
			||||||
					device->base_y = y - value;
 | 
									y = (value - device->min_y) * screen_height /
 | 
				
			||||||
					device->new_y = 0;
 | 
										(device->max_y - device->min_y);
 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				y = device->base_y + value;
 | 
					 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
| 
						 | 
					@ -121,10 +121,6 @@ static void evdev_input_device_data(int fd, uint32_t mask, void *data)
 | 
				
			||||||
			case BTN_TOOL_FINGER:
 | 
								case BTN_TOOL_FINGER:
 | 
				
			||||||
			case BTN_TOOL_MOUSE:
 | 
								case BTN_TOOL_MOUSE:
 | 
				
			||||||
			case BTN_TOOL_LENS:
 | 
								case BTN_TOOL_LENS:
 | 
				
			||||||
				if (device->tool == 0 && value) {
 | 
					 | 
				
			||||||
					device->new_x = 1;
 | 
					 | 
				
			||||||
					device->new_y = 1;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				device->tool = value ? e->code : 0;
 | 
									device->tool = value ? e->code : 0;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -151,16 +147,21 @@ static void evdev_input_device_data(int fd, uint32_t mask, void *data)
 | 
				
			||||||
	if (dx != 0 || dy != 0)
 | 
						if (dx != 0 || dy != 0)
 | 
				
			||||||
		notify_motion(&device->master->base.input_device,
 | 
							notify_motion(&device->master->base.input_device,
 | 
				
			||||||
			      time, x + dx, y + dy);
 | 
								      time, x + dx, y + dy);
 | 
				
			||||||
	if (absolute_event && device->tool)
 | 
						if (absolute_event)
 | 
				
			||||||
		notify_motion(&device->master->base.input_device, time, x, y);
 | 
							notify_motion(&device->master->base.input_device, time, x, y);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define TEST_BIT(b, i) (b[(i) / 32] & (1 << (i & 31)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct evdev_input_device *
 | 
					static struct evdev_input_device *
 | 
				
			||||||
evdev_input_device_create(struct evdev_input *master,
 | 
					evdev_input_device_create(struct evdev_input *master,
 | 
				
			||||||
			  struct wl_display *display, const char *path)
 | 
								  struct wl_display *display, const char *path)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct evdev_input_device *device;
 | 
						struct evdev_input_device *device;
 | 
				
			||||||
	struct wl_event_loop *loop;
 | 
						struct wl_event_loop *loop;
 | 
				
			||||||
 | 
						struct input_absinfo absinfo;
 | 
				
			||||||
 | 
						uint32_t ev_bits[EV_MAX];
 | 
				
			||||||
 | 
						uint32_t key_bits[KEY_MAX];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	device = malloc(sizeof *device);
 | 
						device = malloc(sizeof *device);
 | 
				
			||||||
	if (device == NULL)
 | 
						if (device == NULL)
 | 
				
			||||||
| 
						 | 
					@ -178,6 +179,21 @@ evdev_input_device_create(struct evdev_input *master,
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ioctl(device->fd, EVIOCGBIT(0, EV_MAX), ev_bits);
 | 
				
			||||||
 | 
						if (TEST_BIT(ev_bits, EV_ABS)) {
 | 
				
			||||||
 | 
							ioctl(device->fd, EVIOCGBIT(EV_ABS, EV_MAX), key_bits);
 | 
				
			||||||
 | 
							if (TEST_BIT(key_bits, ABS_X)) {
 | 
				
			||||||
 | 
								ioctl(device->fd, EVIOCGABS(ABS_X), &absinfo);
 | 
				
			||||||
 | 
								device->min_x = absinfo.minimum;
 | 
				
			||||||
 | 
								device->max_x = absinfo.maximum;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (TEST_BIT(key_bits, ABS_Y)) {
 | 
				
			||||||
 | 
								ioctl(device->fd, EVIOCGABS(ABS_Y), &absinfo);
 | 
				
			||||||
 | 
								device->min_y = absinfo.minimum;
 | 
				
			||||||
 | 
								device->max_y = absinfo.maximum;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	loop = wl_display_get_event_loop(display);
 | 
						loop = wl_display_get_event_loop(display);
 | 
				
			||||||
	device->source = wl_event_loop_add_fd(loop, device->fd,
 | 
						device->source = wl_event_loop_add_fd(loop, device->fd,
 | 
				
			||||||
					      WL_EVENT_READABLE,
 | 
										      WL_EVENT_READABLE,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue