commit c617c37

Michael Forney  ·  2016-12-30 04:34:34 +0000 UTC
parent 94322e5
Handle absolute pointer devices
5 files changed,  +54, -3
+31, -1
 1@@ -95,8 +95,18 @@ handle_rel_event(struct evdev_device *device, struct input_event *ev)
 2 }
 3 
 4 static void
 5-handle_abs_event(struct evdev_device *device, struct input_event *input_event)
 6+handle_abs_event(struct evdev_device *device, struct input_event *ev)
 7 {
 8+	switch (ev->code) {
 9+	case ABS_X:
10+		device->abs.x = ev->value;
11+		device->abs.pending = true;
12+		break;
13+	case ABS_Y:
14+		device->abs.y = ev->value;
15+		device->abs.pending = true;
16+		break;
17+	}
18 }
19 
20 static void (*event_handlers[])(struct evdev_device *device, struct input_event *ev) = {
21@@ -115,6 +125,15 @@ is_motion_event(struct input_event *ev)
22 static void
23 handle_motion_events(struct evdev_device *device, uint32_t time)
24 {
25+	if (device->abs.pending) {
26+		int32_t x = device->abs.x - device->abs.info.x->minimum;
27+		int32_t max_x = device->abs.info.x->maximum - device->abs.info.x->minimum;
28+		int32_t y = device->abs.y - device->abs.info.y->minimum;
29+		int32_t max_y = device->abs.info.y->maximum - device->abs.info.y->minimum;
30+
31+		device->handler->absolute_motion(time, x, max_x, y, max_y);
32+		device->abs.pending = false;
33+	}
34 	if (device->rel.pending) {
35 		wl_fixed_t dx = wl_fixed_from_int(device->rel.dx);
36 		wl_fixed_t dy = wl_fixed_from_int(device->rel.dy);
37@@ -221,6 +240,9 @@ evdev_device_new(const char *path, const struct evdev_device_handler *handler)
38 	device->needs_sync = false;
39 	device->handler = handler;
40 	device->capabilities = 0;
41+	device->abs.info.x = libevdev_get_abs_info(device->dev, ABS_X);
42+	device->abs.info.y = libevdev_get_abs_info(device->dev, ABS_Y);
43+	device->abs.pending = false;
44 	memset(&device->rel, 0, sizeof(device->rel));
45 
46 	if (libevdev_has_event_code(device->dev, EV_KEY, KEY_ENTER)) {
47@@ -236,6 +258,14 @@ evdev_device_new(const char *path, const struct evdev_device_handler *handler)
48 		DEBUG("\tThis device is a pointer\n");
49 	}
50 
51+	if (libevdev_has_event_code(device->dev, EV_ABS, ABS_X)
52+	 && libevdev_has_event_code(device->dev, EV_ABS, ABS_Y)
53+	 && libevdev_has_event_code(device->dev, EV_KEY, BTN_MOUSE)
54+	 && !libevdev_has_event_code(device->dev, EV_KEY, BTN_TOOL_FINGER))
55+	{
56+		device->capabilities |= WL_SEAT_CAPABILITY_POINTER;
57+	}
58+
59 	/* XXX: touch devices */
60 
61 	return device;
+2, -1
 1@@ -40,6 +40,7 @@ struct evdev_device_handler {
 2 	void (*button)(uint32_t time, uint32_t key, uint32_t state);
 3 	void (*axis)(uint32_t time, uint32_t axis, wl_fixed_t amount);
 4 	void (*relative_motion)(uint32_t time, wl_fixed_t dx, wl_fixed_t dy);
 5+	void (*absolute_motion)(uint32_t time, int32_t x, int32_t y, int32_t max_x, int32_t max_y);
 6 };
 7 
 8 struct evdev_device {
 9@@ -52,7 +53,7 @@ struct evdev_device {
10 
11 	struct {
12 		struct {
13-			struct input_absinfo x, y;
14+			const struct input_absinfo *x, *y;
15 		} info;
16 
17 		int32_t x, y;
+7, -1
 1@@ -403,10 +403,16 @@ pointer_handle_axis(struct pointer *pointer, uint32_t time, uint32_t axis, wl_fi
 2 
 3 void
 4 pointer_handle_relative_motion(struct pointer *pointer, uint32_t time, wl_fixed_t dx, wl_fixed_t dy)
 5+{
 6+	pointer_handle_absolute_motion(pointer, time, pointer->x + dx, pointer->y + dy);
 7+}
 8+
 9+void
10+pointer_handle_absolute_motion(struct pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y)
11 {
12 	struct pointer_handler *handler;
13 
14-	clip_position(pointer, pointer->x + dx, pointer->y + dy);
15+	clip_position(pointer, x, y);
16 
17 	wl_list_for_each (handler, &pointer->handlers, link) {
18 		if (handler->motion && handler->motion(handler, time, pointer->x, pointer->y))
+1, -0
1@@ -81,5 +81,6 @@ struct wl_resource *pointer_bind(struct pointer *pointer, struct wl_client *clie
2 void pointer_handle_button(struct pointer *pointer, uint32_t time, uint32_t button, uint32_t state);
3 void pointer_handle_axis(struct pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t amount);
4 void pointer_handle_relative_motion(struct pointer *pointer, uint32_t time, wl_fixed_t dx, wl_fixed_t dy);
5+void pointer_handle_absolute_motion(struct pointer *pointer, uint32_t time, wl_fixed_t x, wl_fixed_t y);
6 
7 #endif
+13, -0
 1@@ -30,6 +30,7 @@
 2 #include "keyboard.h"
 3 #include "launch.h"
 4 #include "pointer.h"
 5+#include "screen.h"
 6 #include "surface.h"
 7 #include "util.h"
 8 
 9@@ -96,6 +97,17 @@ handle_relative_motion(uint32_t time, wl_fixed_t dx, wl_fixed_t dy)
10 	pointer_handle_relative_motion(&seat.pointer, time, dx, dy);
11 }
12 
13+static void
14+handle_absolute_motion(uint32_t time, int32_t x, int32_t max_x, int32_t y, int32_t max_y)
15+{
16+	struct screen *screen = wl_container_of(swc.screens.next, screen, link);
17+	struct swc_rectangle *rect = &screen->base.geometry;
18+	wl_fixed_t fx = wl_fixed_from_int(x * rect->width / max_x + rect->x);
19+	wl_fixed_t fy = wl_fixed_from_int(y * rect->height / max_y + rect->y);
20+
21+	pointer_handle_absolute_motion(&seat.pointer, time, fx, fy);
22+}
23+
24 static void
25 handle_keyboard_focus_event(struct wl_listener *listener, void *data)
26 {
27@@ -390,6 +402,7 @@ const static struct evdev_device_handler evdev_handler = {
28 	.button = handle_button,
29 	.axis = handle_axis,
30 	.relative_motion = handle_relative_motion,
31+	.absolute_motion = handle_absolute_motion,
32 };
33 
34 static void