summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm/ecore_drm_evdev.c
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2014-12-09 15:13:49 -0500
committerChris Michael <cp.michael@samsung.com>2014-12-09 15:13:49 -0500
commit33e3e9c8a23a78c789a011d262862867c823b001 (patch)
treed7045dc55475f6096c10b4253cab679be167cdb3 /src/lib/ecore_drm/ecore_drm_evdev.c
parenta5654dbb247e23e54d741a801f3543613935f852 (diff)
ecore-drm: Port ecore_drm to use libinput
Summary: This ports the input code of ecore_drm to make use of libinput for handling of devices, events, etc @feature Signed-off-by: Chris Michael <cp.michael@samsung.com>
Diffstat (limited to '')
-rw-r--r--src/lib/ecore_drm/ecore_drm_evdev.c800
1 files changed, 288 insertions, 512 deletions
diff --git a/src/lib/ecore_drm/ecore_drm_evdev.c b/src/lib/ecore_drm/ecore_drm_evdev.c
index e78ef179d2..5b8afcaf27 100644
--- a/src/lib/ecore_drm/ecore_drm_evdev.c
+++ b/src/lib/ecore_drm/ecore_drm_evdev.c
@@ -2,22 +2,70 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5/* copied from udev/extras/input_id/input_id.c */
6/* we must use this kernel-compatible implementation */
7#define BITS_PER_LONG (sizeof(unsigned long) * 8)
8#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
9#define OFF(x) ((x)%BITS_PER_LONG)
10#define BIT(x) (1UL<<OFF(x))
11#define LONG(x) ((x)/BITS_PER_LONG)
12#define TEST_BIT(array, bit) ((array[LONG(bit)] >> OFF(bit)) & 1)
13/* end copied */
14
15#include "ecore_drm_private.h" 5#include "ecore_drm_private.h"
16#include <sys/ioctl.h>
17#include <linux/input.h>
18#include <ctype.h> 6#include <ctype.h>
19 7
20/* local functions */ 8static void
9_device_calibration_set(Ecore_Drm_Evdev *edev)
10{
11 const char *sysname;
12 int w = 0, h = 0;
13 float cal[6];
14 const char *device;
15 Eina_List *devices;
16 const char *vals;
17 enum libinput_config_status status;
18
19 ecore_drm_output_size_get(edev->seat->input->dev,
20 edev->seat->input->dev->window, &w, &h);
21 if ((w == 0) || (h == 0)) return;
22
23 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
24 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
25 return;
26
27 sysname = libinput_device_get_sysname(edev->device);
28
29 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
30 if (eina_list_count(devices) < 1) return;
31
32 EINA_LIST_FREE(devices, device)
33 {
34 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
35 if ((!vals) ||
36 (sscanf(vals, "%f %f %f %f %f %f",
37 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
38 goto cont;
39
40 cal[2] /= w;
41 cal[5] /= h;
42
43 status =
44 libinput_device_config_calibration_set_matrix(edev->device, cal);
45
46 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
47 ERR("Failed to apply calibration");
48
49cont:
50 eina_stringshare_del(device);
51 continue;
52 }
53}
54
55static void
56_device_configure(Ecore_Drm_Evdev *edev)
57{
58 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
59 {
60 Eina_Bool tap = EINA_FALSE;
61
62 tap = libinput_device_config_tap_get_default_enabled(edev->device);
63 libinput_device_config_tap_set_enabled(edev->device, tap);
64 }
65
66 _device_calibration_set(edev);
67}
68
21static void 69static void
22_device_keyboard_setup(Ecore_Drm_Evdev *edev) 70_device_keyboard_setup(Ecore_Drm_Evdev *edev)
23{ 71{
@@ -60,169 +108,6 @@ _device_keyboard_setup(Ecore_Drm_Evdev *edev)
60 1 << xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift"); 108 1 << xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
61} 109}
62 110
63static Eina_Bool
64_device_configure(Ecore_Drm_Evdev *edev)
65{
66 Eina_Bool ret = EINA_FALSE;
67
68 if (!edev) return EINA_FALSE;
69
70 if ((edev->caps & (EVDEV_MOTION_ABS | EVDEV_MOTION_REL)) &&
71 (edev->caps & EVDEV_BUTTON))
72 {
73 DBG("\tInput device %s is a pointer", edev->name);
74 edev->seat_caps |= EVDEV_SEAT_POINTER;
75
76 /* FIXME: make this configurable */
77 edev->mouse.threshold = 0.25;
78
79 ret = EINA_TRUE;
80 }
81
82 if (edev->caps & EVDEV_KEYBOARD)
83 {
84 DBG("\tInput device %s is a keyboard", edev->name);
85 edev->seat_caps |= EVDEV_SEAT_KEYBOARD;
86 _device_keyboard_setup(edev);
87 ret = EINA_TRUE;
88 }
89
90 if (edev->caps & EVDEV_TOUCH)
91 {
92 DBG("\tInput device %s is a touchpad", edev->name);
93 edev->seat_caps |= EVDEV_SEAT_TOUCH;
94 ret = EINA_TRUE;
95 }
96
97 return ret;
98}
99
100static void
101_device_axis_update(Ecore_Drm_Evdev *dev)
102{
103 if (!dev) return;
104
105 if ((dev->abs.rel_w < 0) || (dev->abs.rel_h < 0))
106 {
107 int w = 0, h = 0;
108
109 ecore_drm_output_size_get(dev->seat->input->dev,
110 dev->seat->input->dev->window, &w, &h);
111 if ((w) && (h))
112 ecore_drm_inputs_device_axis_size_set(dev, w, h);
113 }
114}
115
116static Eina_Bool
117_device_handle(Ecore_Drm_Evdev *edev)
118{
119 struct input_absinfo absinfo;
120 unsigned long dev_bits[NBITS(EV_MAX)];
121 unsigned long abs_bits[NBITS(ABS_MAX)];
122 unsigned long rel_bits[NBITS(REL_MAX)];
123 unsigned long key_bits[NBITS(KEY_MAX)];
124 /* Eina_Bool have_key = EINA_FALSE; */
125 Eina_Bool have_abs = EINA_FALSE;
126
127 if (!edev) return EINA_FALSE;
128
129 ioctl(edev->fd, EVIOCGBIT(0, sizeof(dev_bits)), dev_bits);
130 if (TEST_BIT(dev_bits, EV_ABS))
131 {
132 have_abs = EINA_TRUE;
133
134 ioctl(edev->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)), abs_bits);
135
136 if ((TEST_BIT(abs_bits, ABS_WHEEL)) ||
137 (TEST_BIT(abs_bits, ABS_GAS)) ||
138 (TEST_BIT(abs_bits, ABS_BRAKE)) ||
139 (TEST_BIT(abs_bits, ABS_HAT0X)))
140 {
141 /* ignore joystick */
142 return EINA_FALSE;
143 }
144
145 if (TEST_BIT(abs_bits, ABS_X))
146 {
147 ioctl(edev->fd, EVIOCGABS(ABS_X), &absinfo);
148 edev->abs.min_x = absinfo.minimum;
149 edev->abs.max_x = absinfo.maximum;
150 edev->abs.rel_w = -1;
151 edev->mouse.x = -1;
152 edev->caps |= EVDEV_MOTION_ABS;
153 }
154
155 if (TEST_BIT(abs_bits, ABS_Y))
156 {
157 ioctl(edev->fd, EVIOCGABS(ABS_Y), &absinfo);
158 edev->abs.min_y = absinfo.minimum;
159 edev->abs.max_y = absinfo.maximum;
160 edev->abs.rel_h = -1;
161 edev->mouse.y = -1;
162 edev->caps |= EVDEV_MOTION_ABS;
163 }
164
165 if ((TEST_BIT(abs_bits, ABS_MT_POSITION_X)) &&
166 (TEST_BIT(abs_bits, ABS_MT_POSITION_Y)))
167 {
168 DBG("Handle MultiTouch Device: %s", edev->path);
169 }
170 }
171
172 if (TEST_BIT(dev_bits, EV_REL))
173 {
174 ioctl(edev->fd, EVIOCGBIT(EV_REL, sizeof(rel_bits)), rel_bits);
175
176 if ((TEST_BIT(rel_bits, REL_X)) || (TEST_BIT(rel_bits, REL_Y)))
177 edev->caps |= EVDEV_MOTION_REL;
178 }
179
180 if (TEST_BIT(dev_bits, EV_KEY))
181 {
182 unsigned int i = 0;
183
184 /* have_key = EINA_TRUE; */
185
186 ioctl(edev->fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), key_bits);
187
188 if (have_abs)
189 {
190 if ((TEST_BIT(key_bits, BTN_TOOL_FINGER)) &&
191 (!TEST_BIT(key_bits, BTN_TOOL_PEN)))
192 {
193 DBG("Device Is Touchpad: %s", edev->path);
194 }
195 }
196
197 for (i = KEY_ESC; i < KEY_MAX; i++)
198 {
199 if ((i >= BTN_MISC) && (i < KEY_OK)) continue;
200 if (TEST_BIT(key_bits, i))
201 {
202 edev->caps |= EVDEV_KEYBOARD;
203 break;
204 }
205 }
206
207 if (TEST_BIT(key_bits, BTN_TOUCH))
208 edev->caps |= EVDEV_TOUCH;
209
210 for (i = BTN_MISC; i < BTN_JOYSTICK; i++)
211 {
212 if (TEST_BIT(key_bits, i))
213 {
214 edev->caps |= EVDEV_BUTTON;
215 edev->caps &= ~EVDEV_TOUCH;
216 break;
217 }
218 }
219 }
220
221 if (TEST_BIT(dev_bits, EV_LED)) edev->caps |= EVDEV_KEYBOARD;
222
223 return EINA_TRUE;
224}
225
226static int 111static int
227_device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes) 112_device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
228{ 113{
@@ -304,28 +189,32 @@ _device_modifiers_update(Ecore_Drm_Evdev *edev)
304} 189}
305 190
306static void 191static void
307_device_notify_key(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned int timestamp) 192_device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
308{ 193{
309 unsigned int code, nsyms; 194 Ecore_Drm_Evdev *edev;
310 /* unsigned int *keycode; */ 195 Ecore_Drm_Input *input;
196 uint32_t timestamp;
197 uint32_t code, nsyms;
311 const xkb_keysym_t *syms; 198 const xkb_keysym_t *syms;
199 enum libinput_key_state state;
312 xkb_keysym_t sym = XKB_KEY_NoSymbol; 200 xkb_keysym_t sym = XKB_KEY_NoSymbol;
313 char key[256], keyname[256], compose_buffer[256]; 201 char key[256], keyname[256], compose_buffer[256];
314 Ecore_Event_Key *e; 202 Ecore_Event_Key *e;
315 Ecore_Drm_Input *input; 203 char *tmp = NULL, *compose = NULL;
316 char *tmp = NULL; 204
317 char *compose = NULL; 205 if (!(edev = libinput_device_get_user_data(device))) return;
318 206
319 if (!(input = dev->seat->input)) return; 207 if (!(input = edev->seat->input)) return;
320 208
321 /* xkb rules reflect X broken keycodes, so offset by 8 */ 209 timestamp = libinput_event_keyboard_get_time(event);
322 code = event->code + 8; 210 code = libinput_event_keyboard_get_key(event) + 8;
211 state = libinput_event_keyboard_get_key_state(event);
323 212
324 xkb_state_update_key(dev->xkb.state, code, 213 xkb_state_update_key(edev->xkb.state, code,
325 (event->value ? XKB_KEY_DOWN : XKB_KEY_UP)); 214 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
326 215
327 /* get the keysym for this code */ 216 /* get the keysym for this code */
328 nsyms = xkb_key_get_syms(dev->xkb.state, code, &syms); 217 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
329 if (nsyms == 1) sym = syms[0]; 218 if (nsyms == 1) sym = syms[0];
330 219
331 /* get the keyname for this sym */ 220 /* get the keyname for this sym */
@@ -339,8 +228,8 @@ _device_notify_key(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned int
339 snprintf(keyname, sizeof(keyname), "Keycode-%u", code); 228 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
340 229
341 /* if shift is active, we need to transform the key to lower */ 230 /* if shift is active, we need to transform the key to lower */
342 if (xkb_state_mod_index_is_active(dev->xkb.state, 231 if (xkb_state_mod_index_is_active(edev->xkb.state,
343 xkb_map_mod_get_index(dev->xkb.keymap, 232 xkb_map_mod_get_index(edev->xkb.keymap,
344 XKB_MOD_NAME_SHIFT), 233 XKB_MOD_NAME_SHIFT),
345 XKB_STATE_MODS_EFFECTIVE)) 234 XKB_STATE_MODS_EFFECTIVE))
346 { 235 {
@@ -349,23 +238,20 @@ _device_notify_key(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned int
349 } 238 }
350 239
351 memset(compose_buffer, 0, sizeof(compose_buffer)); 240 memset(compose_buffer, 0, sizeof(compose_buffer));
352 if (_device_keysym_translate(sym, dev->xkb.modifiers, compose_buffer, sizeof(compose_buffer))) 241 if (_device_keysym_translate(sym, edev->xkb.modifiers,
242 compose_buffer, sizeof(compose_buffer)))
353 { 243 {
354 compose = eina_str_convert("ISO8859-1", "UTF-8", 244 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
355 compose_buffer);
356 if (!compose) 245 if (!compose)
357 { 246 {
358 ERR("Ecore_DRM cannot convert input key string '%s' to UTF-8. " 247 ERR("Ecore_DRM cannot convert input key string '%s' to UTF-8. "
359 "Is Eina built with iconv support?", compose_buffer); 248 "Is Eina built with iconv support?", compose_buffer);
360 } 249 }
361 else 250 else
362 { 251 tmp = compose;
363 tmp = compose;
364 }
365 } 252 }
366 253
367 if (!compose) 254 if (!compose) compose = compose_buffer;
368 compose = compose_buffer;
369 255
370 e = malloc(sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) + 256 e = malloc(sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
371 ((compose[0] != '\0') ? strlen(compose) : 0) + 3); 257 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
@@ -388,44 +274,45 @@ _device_notify_key(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned int
388 e->keycode = code; 274 e->keycode = code;
389 e->data = NULL; 275 e->data = NULL;
390 276
391 _device_modifiers_update(dev); 277 _device_modifiers_update(edev);
392 e->modifiers = dev->xkb.modifiers; 278
279 e->modifiers = edev->xkb.modifiers;
393 280
394 if (event->value) 281 if (state)
395 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL); 282 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
396 else 283 else
397 ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL); 284 ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
398 285
399 if (tmp) 286 if (tmp) free(tmp);
400 free(tmp);
401} 287}
402 288
403static void 289static void
404_device_notify_motion(Ecore_Drm_Evdev *dev, unsigned int timestamp) 290_device_pointer_motion(Ecore_Drm_Evdev *edev, struct libinput_event_pointer *event)
405{ 291{
406 Ecore_Drm_Input *input; 292 Ecore_Drm_Input *input;
407 Ecore_Event_Mouse_Move *ev; 293 Ecore_Event_Mouse_Move *ev;
408 294
409 if (!(input = dev->seat->input)) return; 295 if (!(input = edev->seat->input)) return;
296
410 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return; 297 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
411 298
412 ev->window = (Ecore_Window)input->dev->window; 299 ev->window = (Ecore_Window)input->dev->window;
413 ev->event_window = (Ecore_Window)input->dev->window; 300 ev->event_window = (Ecore_Window)input->dev->window;
414 ev->root_window = (Ecore_Window)input->dev->window; 301 ev->root_window = (Ecore_Window)input->dev->window;
415 ev->timestamp = timestamp; 302 ev->timestamp = libinput_event_pointer_get_time(event);
416 ev->same_screen = 1; 303 ev->same_screen = 1;
417 304
418 /* NB: Commented out. This borks mouse movement if no key has been 305 /* NB: Commented out. This borks mouse movement if no key has been
419 * pressed yet due to 'state' not being set */ 306 * pressed yet due to 'state' not being set */
420// _device_modifiers_update(dev); 307// _device_modifiers_update(dev);
421 ev->modifiers = dev->xkb.modifiers; 308 ev->modifiers = edev->xkb.modifiers;
422 309
423 ev->x = dev->mouse.x; 310 ev->x = edev->mouse.x;
424 ev->y = dev->mouse.y; 311 ev->y = edev->mouse.y;
425 ev->root.x = ev->x; 312 ev->root.x = ev->x;
426 ev->root.y = ev->y; 313 ev->root.y = ev->y;
427 314
428 ev->multi.device = dev->mt_slot; 315 ev->multi.device = edev->mt_slot;
429 ev->multi.radius = 1; 316 ev->multi.radius = 1;
430 ev->multi.radius_x = 1; 317 ev->multi.radius_x = 1;
431 ev->multi.radius_y = 1; 318 ev->multi.radius_y = 1;
@@ -440,45 +327,54 @@ _device_notify_motion(Ecore_Drm_Evdev *dev, unsigned int timestamp)
440} 327}
441 328
442static void 329static void
443_device_notify_wheel(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned int timestamp) 330_device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
444{ 331{
445 Ecore_Drm_Input *input; 332 Ecore_Drm_Evdev *edev;
446 Ecore_Event_Mouse_Wheel *ev;
447 333
448 if (!(input = dev->seat->input)) return; 334 if (!(edev = libinput_device_get_user_data(device))) return;
449 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel)))) return;
450 335
451 ev->window = (Ecore_Window)input->dev->window; 336 edev->mouse.x += libinput_event_pointer_get_dx(event);
452 ev->event_window = (Ecore_Window)input->dev->window; 337 edev->mouse.y += libinput_event_pointer_get_dy(event);
453 ev->root_window = (Ecore_Window)input->dev->window;
454 ev->timestamp = timestamp;
455 ev->same_screen = 1;
456 338
457 /* NB: Commented out. This borks mouse wheel if no key has been 339 _device_pointer_motion(edev, event);
458 * pressed yet due to 'state' not being set */ 340}
459// _device_modifiers_update(dev);
460 ev->modifiers = dev->xkb.modifiers;
461 341
462 ev->x = dev->mouse.x; 342static void
463 ev->y = dev->mouse.y; 343_device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
464 ev->root.x = ev->x; 344{
465 ev->root.y = ev->y; 345 Ecore_Drm_Evdev *edev;
466 if (event->value == REL_HWHEEL) ev->direction = 1; 346 int x, y;
467 ev->z = -event->value;
468 347
469 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL); 348 if (!(edev = libinput_device_get_user_data(device))) return;
349
350 edev->mouse.x = libinput_event_pointer_get_absolute_x(event);
351 edev->mouse.y = libinput_event_pointer_get_absolute_y(event);
352
353 _device_pointer_motion(edev, event);
470} 354}
471 355
472static void 356static void
473_device_notify_button(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned int timestamp) 357_device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
474{ 358{
359 Ecore_Drm_Evdev *edev;
475 Ecore_Drm_Input *input; 360 Ecore_Drm_Input *input;
476 Ecore_Event_Mouse_Button *ev; 361 Ecore_Event_Mouse_Button *ev;
477 int button; 362 enum libinput_button_state state;
363 uint32_t button, timestamp;
364
365 if (!(edev = libinput_device_get_user_data(device))) return;
366 if (!(input = edev->seat->input)) return;
478 367
479 if (!(input = dev->seat->input)) return;
480 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return; 368 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
481 369
370 state = libinput_event_pointer_get_button_state(event);
371 button = libinput_event_pointer_get_button(event);
372 timestamp = libinput_event_pointer_get_time(event);
373
374 button = ((button & 0x00F) + 1);
375 if (button == 3) button = 2;
376 else if (button == 2) button = 3;
377
482 ev->window = (Ecore_Window)input->dev->window; 378 ev->window = (Ecore_Window)input->dev->window;
483 ev->event_window = (Ecore_Window)input->dev->window; 379 ev->event_window = (Ecore_Window)input->dev->window;
484 ev->root_window = (Ecore_Window)input->dev->window; 380 ev->root_window = (Ecore_Window)input->dev->window;
@@ -488,14 +384,14 @@ _device_notify_button(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned
488 /* NB: Commented out. This borks mouse button if no key has been 384 /* NB: Commented out. This borks mouse button if no key has been
489 * pressed yet due to 'state' not being set */ 385 * pressed yet due to 'state' not being set */
490// _device_modifiers_update(dev); 386// _device_modifiers_update(dev);
491 ev->modifiers = dev->xkb.modifiers; 387 ev->modifiers = edev->xkb.modifiers;
492 388
493 ev->x = dev->mouse.x; 389 ev->x = edev->mouse.x;
494 ev->y = dev->mouse.y; 390 ev->y = edev->mouse.y;
495 ev->root.x = ev->x; 391 ev->root.x = ev->x;
496 ev->root.y = ev->y; 392 ev->root.y = ev->y;
497 393
498 ev->multi.device = dev->mt_slot; 394 ev->multi.device = edev->mt_slot;
499 ev->multi.radius = 1; 395 ev->multi.radius = 1;
500 ev->multi.radius_x = 1; 396 ev->multi.radius_x = 1;
501 ev->multi.radius_y = 1; 397 ev->multi.radius_y = 1;
@@ -506,324 +402,189 @@ _device_notify_button(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned
506 ev->multi.root.x = ev->x; 402 ev->multi.root.x = ev->x;
507 ev->multi.root.y = ev->y; 403 ev->multi.root.y = ev->y;
508 404
509 button = ((event->code & 0x00F) + 1); 405 if (state)
510
511 /* swap buttons 2 & 3 so behaviour is like X */
512 if (button == 3) button = 2;
513 else if (button == 2) button = 3;
514
515 if (event->value)
516 { 406 {
517 unsigned int current; 407 unsigned int current;
518 408
519 current = timestamp; 409 current = timestamp;
520 dev->mouse.did_double = EINA_FALSE; 410 edev->mouse.did_double = EINA_FALSE;
521 dev->mouse.did_triple = EINA_FALSE; 411 edev->mouse.did_triple = EINA_FALSE;
522 412
523 if (((current - dev->mouse.prev) <= dev->mouse.threshold) && 413 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
524 (button == dev->mouse.prev_button)) 414 (button == edev->mouse.prev_button))
525 { 415 {
526 dev->mouse.did_double = EINA_TRUE; 416 edev->mouse.did_double = EINA_TRUE;
527 if (((current - dev->mouse.last) <= (2 * dev->mouse.threshold)) && 417 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
528 (button == dev->mouse.last_button)) 418 (button == edev->mouse.last_button))
529 { 419 {
530 dev->mouse.did_triple = EINA_TRUE; 420 edev->mouse.did_triple = EINA_TRUE;
531 dev->mouse.prev = 0; 421 edev->mouse.prev = 0;
532 dev->mouse.last = 0; 422 edev->mouse.last = 0;
533 current = 0; 423 current = 0;
534 } 424 }
535 } 425 }
536 426
537 dev->mouse.last = dev->mouse.prev; 427 edev->mouse.last = edev->mouse.prev;
538 dev->mouse.prev = current; 428 edev->mouse.prev = current;
539 dev->mouse.last_button = dev->mouse.prev_button; 429 edev->mouse.last_button = edev->mouse.prev_button;
540 dev->mouse.prev_button = button; 430 edev->mouse.prev_button = button;
541 } 431 }
542 432
543 ev->buttons = button; 433 ev->buttons = button;
544 if (dev->mouse.did_double) 434
435 if (edev->mouse.did_double)
545 ev->double_click = 1; 436 ev->double_click = 1;
546 if (dev->mouse.did_triple) 437 if (edev->mouse.did_triple)
547 ev->triple_click = 1; 438 ev->triple_click = 1;
548 439
549 if (event->value) 440 if (state)
550 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL); 441 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
551 else 442 else
552 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL); 443 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
553} 444}
554 445
555static void 446static void
556_device_process_flush(Ecore_Drm_Evdev *dev, unsigned int timestamp) 447_device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
557{ 448{
558 switch (dev->pending_event) 449 Ecore_Drm_Evdev *edev;
559 { 450 Ecore_Drm_Input *input;
560 case EVDEV_NONE: 451 Ecore_Event_Mouse_Wheel *ev;
561 return; 452 uint32_t timestamp;
562 case EVDEV_RELATIVE_MOTION: 453 enum libinput_pointer_axis axis;
563 _device_notify_motion(dev, timestamp);
564 /* dev->mouse.x = 0; */
565 /* dev->mouse.y = 0; */
566 goto out;
567 break;
568 case EVDEV_ABSOLUTE_MT_DOWN:
569 goto out;
570 break;
571 case EVDEV_ABSOLUTE_MT_MOTION:
572 goto out;
573 break;
574 case EVDEV_ABSOLUTE_MT_UP:
575 goto out;
576 break;
577 case EVDEV_ABSOLUTE_TOUCH_DOWN:
578 case EVDEV_ABSOLUTE_TOUCH_UP:
579 {
580 struct input_event event;
581
582 event.code = 0;
583 event.value = dev->abs.pt[dev->mt_slot].down;
584 454
585 dev->mouse.x = dev->abs.pt[dev->mt_slot].x[0]; 455 if (!(edev = libinput_device_get_user_data(device))) return;
586 dev->mouse.y = dev->abs.pt[dev->mt_slot].y[0]; 456 if (!(input = edev->seat->input)) return;
587 457
588 _device_notify_motion(dev, timestamp); 458 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel)))) return;
589 _device_notify_button(dev, &event, timestamp);
590 459
591 break; 460 axis = libinput_event_pointer_get_axis(event);
592 } 461 timestamp = libinput_event_pointer_get_time(event);
593 case EVDEV_ABSOLUTE_MOTION:
594 dev->mouse.x = dev->abs.pt[dev->mt_slot].x[0];
595 dev->mouse.y = dev->abs.pt[dev->mt_slot].y[0];
596 462
597 _device_notify_motion(dev, timestamp); 463 ev->window = (Ecore_Window)input->dev->window;
598 break; 464 ev->event_window = (Ecore_Window)input->dev->window;
599 } 465 ev->root_window = (Ecore_Window)input->dev->window;
466 ev->timestamp = timestamp;
467 ev->same_screen = 1;
600 468
601out: 469 /* NB: Commented out. This borks mouse wheel if no key has been
602 dev->pending_event = EVDEV_NONE; 470 * pressed yet due to 'state' not being set */
603} 471// _device_modifiers_update(dev);
472 ev->modifiers = edev->xkb.modifiers;
604 473
605static void 474 ev->x = edev->mouse.x;
606_device_process_key(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned int timestamp) 475 ev->y = edev->mouse.y;
607{ 476 ev->root.x = ev->x;
608 /* ignore key repeat */ 477 ev->root.y = ev->y;
609 if (event->value == 2) return;
610 478
611 _device_process_flush(dev, timestamp); 479 if (axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL) ev->direction = 1;
480 ev->z = -libinput_event_pointer_get_axis_value(event);
612 481
613 if ((event->code >= BTN_LEFT) && (event->code <= BTN_TASK)) 482 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
614 _device_notify_button(dev, event, timestamp);
615 else if ((event->code >= KEY_ESC) && (event->code <= KEY_MICMUTE))
616 _device_notify_key(dev, event, timestamp);
617 else if ((event->code == BTN_TOUCH) && (dev->caps & EVDEV_MOTION_ABS))
618 dev->abs.pt[dev->mt_slot].down = event->value;
619} 483}
620 484
621static void 485Ecore_Drm_Evdev *
622_device_process_absolute(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned int timestamp EINA_UNUSED) 486_ecore_drm_evdev_device_create(Ecore_Drm_Seat *seat, struct libinput_device *device)
623{ 487{
624 _device_axis_update(dev); 488 Ecore_Drm_Evdev *edev;
625
626 switch (event->code)
627 {
628 case ABS_X:
629 if (dev->abs.pt[dev->mt_slot].down == 0)
630 return;
631 case ABS_MT_POSITION_X:
632 dev->abs.pt[dev->mt_slot].x[0] =
633 (int)((double)(event->value - dev->abs.min_x) / dev->abs.rel_w);
634
635 if (dev->pending_event != EVDEV_ABSOLUTE_TOUCH_DOWN)
636 if (dev->pending_event != EVDEV_ABSOLUTE_TOUCH_UP)
637 dev->pending_event = EVDEV_ABSOLUTE_MOTION;
638 489
639 break; 490 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
640 case ABS_Y:
641 if (dev->abs.pt[dev->mt_slot].down == 0)
642 return;
643 case ABS_MT_POSITION_Y:
644 dev->abs.pt[dev->mt_slot].y[0] =
645 (int)((double)(event->value - dev->abs.min_y) / dev->abs.rel_h);
646 491
647 if (dev->pending_event != EVDEV_ABSOLUTE_TOUCH_DOWN) 492 /* try to allocate space for new evdev */
648 if (dev->pending_event != EVDEV_ABSOLUTE_TOUCH_UP) 493 if (!(edev = calloc(1, sizeof(Ecore_Drm_Evdev)))) return NULL;
649 dev->pending_event = EVDEV_ABSOLUTE_MOTION;
650 494
651 break; 495 edev->seat = seat;
652 case ABS_MT_SLOT: 496 edev->device = device;
653 if ((event->value >= 0) && (event->value < EVDEV_MAX_SLOTS)) 497 edev->path = eina_stringshare_add(libinput_device_get_sysname(device));
654 dev->mt_slot = event->value;
655
656 break;
657 case ABS_MT_TRACKING_ID:
658 if (event->value < 0)
659 {
660 dev->abs.pt[dev->mt_slot].down = 0;
661 dev->pending_event = EVDEV_ABSOLUTE_TOUCH_UP;
662 }
663 else
664 {
665 dev->abs.pt[dev->mt_slot].down = 1;
666 dev->pending_event = EVDEV_ABSOLUTE_TOUCH_DOWN;
667 }
668 break;
669 }
670}
671 498
672static void 499 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
673_device_process_relative(Ecore_Drm_Evdev *dev, struct input_event *event, unsigned int timestamp)
674{
675 switch (event->code)
676 { 500 {
677 case REL_X: 501 edev->seat_caps |= EVDEV_SEAT_KEYBOARD;
678 if (dev->pending_event != EVDEV_RELATIVE_MOTION) 502 _device_keyboard_setup(edev);
679 _device_process_flush(dev, timestamp);
680 dev->mouse.x += event->value;
681 dev->pending_event = EVDEV_RELATIVE_MOTION;
682 break;
683 case REL_Y:
684 if (dev->pending_event != EVDEV_RELATIVE_MOTION)
685 _device_process_flush(dev, timestamp);
686 dev->mouse.y += event->value;
687 dev->pending_event = EVDEV_RELATIVE_MOTION;
688 break;
689 case REL_WHEEL:
690 case REL_HWHEEL:
691 _device_process_flush(dev, timestamp);
692 _device_notify_wheel(dev, event, timestamp);
693 break;
694 } 503 }
695}
696
697static void
698_device_process(Ecore_Drm_Evdev *dev, struct input_event *event, int count)
699{
700 struct input_event *ev, *end;
701 unsigned int timestamp = 0;
702 504
703 ev = event; 505 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
704 end = ev + count;
705 for (ev = event; ev < end; ev++)
706 { 506 {
707 timestamp = (ev->time.tv_sec * 1000) + (ev->time.tv_usec / 1000); 507 edev->seat_caps |= EVDEV_SEAT_POINTER;
708 508
709 switch (ev->type) 509 /* TODO: make this configurable */
710 { 510 edev->mouse.threshold = 0.25;
711 case EV_KEY:
712 _device_process_key(dev, ev, timestamp);
713 break;
714 case EV_REL:
715 _device_process_relative(dev, ev, timestamp);
716 break;
717 case EV_ABS:
718 _device_process_absolute(dev, ev, timestamp);
719 break;
720 case EV_SYN:
721 _device_process_flush(dev, timestamp);
722 break;
723 default:
724 break;
725 }
726 } 511 }
727}
728
729static Eina_Bool
730_cb_device_data(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
731{
732 Ecore_Drm_Evdev *edev;
733 struct input_event ev[32];
734 int len = 0;
735 512
736 if (!(edev = data)) return EINA_TRUE; 513 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
737
738 do
739 { 514 {
740 len = read(edev->fd, &ev, sizeof(ev)); 515 edev->seat_caps |= EVDEV_SEAT_TOUCH;
741 516 }
742 if ((len < 0) || ((len % sizeof(ev[0])) != 0))
743 {
744 if ((len < 0) && (errno != EAGAIN) && (errno != EINTR))
745 {
746 ERR("Device Died");
747 }
748
749 return EINA_TRUE;
750 }
751 517
752 edev->event_process(edev, ev, (len / sizeof(ev[0]))); 518 libinput_device_set_user_data(device, edev);
519 libinput_device_ref(device);
753 520
754 } while (len > 0); 521 /* configure device */
522 _device_configure(edev);
755 523
756 return EINA_TRUE; 524 return edev;
757} 525}
758 526
759/* external functions */ 527void
760Ecore_Drm_Evdev * 528_ecore_drm_evdev_device_destroy(Ecore_Drm_Evdev *edev)
761_ecore_drm_evdev_device_create(Ecore_Drm_Seat *seat, const char *path, int fd)
762{ 529{
763 Ecore_Drm_Evdev *edev; 530 EINA_SAFETY_ON_NULL_RETURN(edev);
764 char name[256] = "unknown";
765
766 if (!(edev = calloc(1, sizeof(Ecore_Drm_Evdev))))
767 return NULL;
768
769 edev->seat = seat;
770 edev->path = eina_stringshare_add(path);
771 edev->fd = fd;
772 edev->mt_slot = 0;
773 531
774 if (ioctl(edev->fd, EVIOCGNAME(sizeof(name)), name) < 0) 532 if (edev->seat_caps & EVDEV_SEAT_KEYBOARD)
775 ERR("Error getting device name: %m");
776
777 name[sizeof(name) - 1] = '\0';
778 edev->name = eina_stringshare_add(name);
779
780 if (!_device_handle(edev))
781 { 533 {
782 ERR("Unhandled Input Device: %s", name); 534 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
783 _ecore_drm_evdev_device_destroy(edev); 535 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
784 return NULL;
785 } 536 }
786 537
787 if (!_device_configure(edev)) 538 if (edev->path) eina_stringshare_del(edev->path);
788 { 539 if (edev->device) libinput_device_unref(edev->device);
789 ERR("\tCould not configure input device: %s", name);
790 _ecore_drm_evdev_device_destroy(edev);
791 return NULL;
792 }
793 540
794 edev->event_process = _device_process; 541 free(edev);
795
796 edev->hdlr =
797 ecore_main_fd_handler_add(edev->fd, ECORE_FD_READ,
798 _cb_device_data, edev, NULL, NULL);
799 if (!edev->hdlr)
800 {
801 ERR("\tCould not create fd handler");
802 _ecore_drm_evdev_device_destroy(edev);
803 return NULL;
804 }
805
806 return edev;
807} 542}
808 543
809void 544Eina_Bool
810_ecore_drm_evdev_device_destroy(Ecore_Drm_Evdev *dev) 545_ecore_drm_evdev_event_process(struct libinput_event *event)
811{ 546{
812 if (!dev) return; 547 struct libinput_device *device;
548 Eina_Bool ret = EINA_TRUE;
813 549
814 if (dev->xkb.state) xkb_state_unref(dev->xkb.state); 550 /* TODO: Finish Touch Events */
815 if (dev->xkb.keymap) xkb_map_unref(dev->xkb.keymap);
816 551
817 if (dev->path) eina_stringshare_del(dev->path); 552 device = libinput_event_get_device(event);
818 if (dev->name) eina_stringshare_del(dev->name); 553 switch (libinput_event_get_type(event))
819 if (dev->hdlr) ecore_main_fd_handler_del(dev->hdlr); 554 {
820 555 case LIBINPUT_EVENT_KEYBOARD_KEY:
821 close(dev->fd); 556 _device_handle_key(device, libinput_event_get_keyboard_event(event));
557 break;
558 case LIBINPUT_EVENT_POINTER_MOTION:
559 _device_handle_pointer_motion(device,
560 libinput_event_get_pointer_event(event));
561 break;
562 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
563 _device_handle_pointer_motion_absolute(device,
564 libinput_event_get_pointer_event(event));
565 break;
566 case LIBINPUT_EVENT_POINTER_BUTTON:
567 _device_handle_button(device, libinput_event_get_pointer_event(event));
568 break;
569 case LIBINPUT_EVENT_POINTER_AXIS:
570 _device_handle_axis(device, libinput_event_get_pointer_event(event));
571 break;
572 case LIBINPUT_EVENT_TOUCH_DOWN:
573 break;
574 case LIBINPUT_EVENT_TOUCH_MOTION:
575 break;
576 case LIBINPUT_EVENT_TOUCH_UP:
577 break;
578 case LIBINPUT_EVENT_TOUCH_FRAME:
579 break;
580 default:
581 ret = EINA_FALSE;
582 break;
583 }
822 584
823 free(dev); 585 return ret;
824} 586}
825 587
826
827/** 588/**
828 * @brief Set the axis size of the given device. 589 * @brief Set the axis size of the given device.
829 * 590 *
@@ -837,30 +598,45 @@ _ecore_drm_evdev_device_destroy(Ecore_Drm_Evdev *dev)
837 * not, unsupported device. 598 * not, unsupported device.
838 */ 599 */
839EAPI void 600EAPI void
840ecore_drm_inputs_device_axis_size_set(Ecore_Drm_Evdev *dev, int w, int h) 601ecore_drm_inputs_device_axis_size_set(Ecore_Drm_Evdev *edev, int w, int h)
841{ 602{
842 if (!dev) return; 603 const char *sysname;
843 if ((w < 0) || (h < 0)) return; 604 float cal[6];
605 const char *device;
606 Eina_List *devices;
607 const char *vals;
608 enum libinput_config_status status;
844 609
845 if (dev->caps & EVDEV_MOTION_ABS) 610 if ((w == 0) || (h == 0)) return;
846 { 611
847 /* FIXME looks like some kernels dont include this struct */ 612 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
848 struct input_absinfo abs_features; 613 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
849
850 ioctl(dev->fd, EVIOCGABS(ABS_X), &abs_features);
851 dev->abs.rel_w =
852 (double)(abs_features.maximum - abs_features.minimum)/(double)(w);
853 dev->abs.min_x = abs_features.minimum;
854
855 ioctl(dev->fd, EVIOCGABS(ABS_Y), &abs_features);
856 dev->abs.rel_h =
857 (double)(abs_features.maximum - abs_features.minimum)/(double)(h);
858 dev->abs.min_y = abs_features.minimum;
859 }
860 else if (!(dev->caps & EVDEV_MOTION_REL))
861 return; 614 return;
862 615
863 /* update the local values */ 616 sysname = libinput_device_get_sysname(edev->device);
864 if (dev->mouse.x > w - 1) dev->mouse.x = w - 1; 617
865 if (dev->mouse.y > h - 1) dev->mouse.y = h - 1; 618 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
619 if (eina_list_count(devices) < 1) return;
620
621 EINA_LIST_FREE(devices, device)
622 {
623 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
624 if ((!vals) ||
625 (sscanf(vals, "%f %f %f %f %f %f",
626 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
627 goto cont;
628
629 cal[2] /= w;
630 cal[5] /= h;
631
632 status =
633 libinput_device_config_calibration_set_matrix(edev->device, cal);
634
635 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
636 ERR("Failed to apply calibration");
637
638cont:
639 eina_stringshare_del(device);
640 continue;
641 }
866} 642}