6 #include "ecore_private.h"
7 #include "Ecore_Input.h"
8 #include "ecore_wl_private.h"
9 #include "Ecore_Wayland.h"
11 /* FIXME: This gives BTN_LEFT/RIGHT/MIDDLE for linux systems ...
12 * What about other OSs ?? */
14 # include <linux/input.h>
16 # define BTN_LEFT 0x110
17 # define BTN_RIGHT 0x111
18 # define BTN_MIDDLE 0x112
19 # define BTN_SIDE 0x113
20 # define BTN_EXTRA 0x114
21 # define BTN_FORWARD 0x115
22 # define BTN_BACK 0x116
25 /* local function prototypes */
26 static void _ecore_wl_input_cb_motion(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, int sx, int sy);
27 static void _ecore_wl_input_cb_button(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, unsigned int button, unsigned int state);
28 static void _ecore_wl_input_cb_key(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp __UNUSED__, unsigned int key, unsigned int state);
29 static void _ecore_wl_input_cb_pointer_enter(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface, int sx, int sy);
30 static void _ecore_wl_input_cb_pointer_leave(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface __UNUSED__);
31 static void _ecore_wl_input_cb_keyboard_enter(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface, struct wl_array *keys);
32 static void _ecore_wl_input_cb_keyboard_leave(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface __UNUSED__);
33 static void _ecore_wl_input_cb_touch_down(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface __UNUSED__, int id __UNUSED__, int x, int y);
34 static void _ecore_wl_input_cb_touch_up(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, int id __UNUSED__);
35 static void _ecore_wl_input_cb_touch_motion(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, int id __UNUSED__, int x, int y);
36 static void _ecore_wl_input_cb_touch_frame(void *data __UNUSED__, struct wl_input_device *input_device __UNUSED__);
37 static void _ecore_wl_input_cb_touch_cancel(void *data __UNUSED__, struct wl_input_device *input_device __UNUSED__);
38 static void _ecore_wl_input_cb_data_offer(void *data, struct wl_data_device *data_device, unsigned int id);
39 static void _ecore_wl_input_cb_data_enter(void *data, struct wl_data_device *data_device, unsigned int timestamp, struct wl_surface *surface, int x, int y, struct wl_data_offer *offer);
40 static void _ecore_wl_input_cb_data_leave(void *data, struct wl_data_device *data_device);
41 static void _ecore_wl_input_cb_data_motion(void *data, struct wl_data_device *data_device, unsigned int timestamp, int x, int y);
42 static void _ecore_wl_input_cb_data_drop(void *data, struct wl_data_device *data_device);
43 static void _ecore_wl_input_cb_data_selection(void *data, struct wl_data_device *data_device, struct wl_data_offer *offer);
45 static void _ecore_wl_input_keyboard_focus_remove(Ecore_Wl_Input *input, unsigned int timestamp);
46 static void _ecore_wl_input_pointer_focus_remove(Ecore_Wl_Input *input, unsigned int timestamp);
47 static void _ecore_wl_input_mouse_move_send(Ecore_Wl_Input *input, unsigned int timestamp);
48 static void _ecore_wl_input_mouse_in_send(Ecore_Wl_Input *input, unsigned int timestamp);
49 static void _ecore_wl_input_mouse_out_send(Ecore_Wl_Input *input, unsigned int timestamp);
50 static void _ecore_wl_input_focus_in_send(Ecore_Wl_Input *input, unsigned int timestamp);
51 static void _ecore_wl_input_focus_out_send(Ecore_Wl_Input *input, unsigned int timestamp);
52 static void _ecore_wl_input_mouse_down_send(Ecore_Wl_Input *input, unsigned int timestamp);
53 static void _ecore_wl_input_mouse_up_send(Ecore_Wl_Input *input, unsigned int timestamp);
55 /* wayland interfaces */
56 static const struct wl_input_device_listener _ecore_wl_input_listener =
58 _ecore_wl_input_cb_motion,
59 _ecore_wl_input_cb_button,
60 _ecore_wl_input_cb_key,
61 _ecore_wl_input_cb_pointer_enter,
62 _ecore_wl_input_cb_pointer_leave,
63 _ecore_wl_input_cb_keyboard_enter,
64 _ecore_wl_input_cb_keyboard_leave,
65 _ecore_wl_input_cb_touch_down,
66 _ecore_wl_input_cb_touch_up,
67 _ecore_wl_input_cb_touch_motion,
68 _ecore_wl_input_cb_touch_frame,
69 _ecore_wl_input_cb_touch_cancel
72 static const struct wl_data_device_listener _ecore_wl_data_listener =
74 _ecore_wl_input_cb_data_offer,
75 _ecore_wl_input_cb_data_enter,
76 _ecore_wl_input_cb_data_leave,
77 _ecore_wl_input_cb_data_motion,
78 _ecore_wl_input_cb_data_drop,
79 _ecore_wl_input_cb_data_selection
83 static int _pointer_x, _pointer_y;
86 ecore_wl_input_grab(Ecore_Wl_Input *input, Ecore_Wl_Window *win, unsigned int button)
88 LOGFN(__FILE__, __LINE__, __FUNCTION__);
91 input->grab_button = button;
95 ecore_wl_input_ungrab(Ecore_Wl_Input *input, unsigned int timestamp)
97 LOGFN(__FILE__, __LINE__, __FUNCTION__);
100 if (input->pointer_focus)
102 printf("Ungrab: %d\n", timestamp);
107 _ecore_wl_input_add(Ecore_Wl_Display *ewd, unsigned int id)
109 Ecore_Wl_Input *input;
111 LOGFN(__FILE__, __LINE__, __FUNCTION__);
113 if (!(input = malloc(sizeof(Ecore_Wl_Input)))) return;
115 memset(input, 0, sizeof(Ecore_Wl_Input));
117 input->display = ewd;
118 input->pointer_focus = NULL;
119 input->keyboard_focus = NULL;
121 input->input_device =
122 wl_display_bind(ewd->wl.display, id, &wl_input_device_interface);
123 wl_list_insert(ewd->inputs.prev, &input->link);
124 wl_input_device_add_listener(input->input_device,
125 &_ecore_wl_input_listener, input);
126 wl_input_device_set_user_data(input->input_device, input);
129 wl_data_device_manager_get_data_device(ewd->wl.data_device_manager,
130 input->input_device);
131 wl_data_device_add_listener(input->data_device,
132 &_ecore_wl_data_listener, input);
137 _ecore_wl_input_del(Ecore_Wl_Input *input)
141 _ecore_wl_input_keyboard_focus_remove(input, 0);
142 _ecore_wl_input_pointer_focus_remove(input, 0);
144 if (input->drag_source) _ecore_wl_dnd_del(input->drag_source);
145 input->drag_source = NULL;
147 if (input->selection_source) _ecore_wl_dnd_del(input->selection_source);
148 input->selection_source = NULL;
150 if (input->data_device) wl_data_device_destroy(input->data_device);
151 if (input->input_device) wl_input_device_destroy(input->input_device);
152 wl_list_remove(&input->link);
157 _ecore_wl_input_pointer_xy_get(int *x, int *y)
159 if (x) *x = _pointer_x;
160 if (y) *y = _pointer_y;
163 /* local functions */
165 _ecore_wl_input_cb_motion(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, int sx, int sy)
167 Ecore_Wl_Input *input;
169 LOGFN(__FILE__, __LINE__, __FUNCTION__);
171 if (!(input = data)) return;
179 /* TODO: FIXME: NB: Weston window code has set pointer image here also */
180 _ecore_wl_input_mouse_move_send(input, timestamp);
184 _ecore_wl_input_cb_button(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, unsigned int button, unsigned int state)
186 Ecore_Wl_Input *input;
188 LOGFN(__FILE__, __LINE__, __FUNCTION__);
190 if (!(input = data)) return;
192 input->timestamp = timestamp;
194 if ((input->pointer_focus) && (!input->grab) && (state))
195 ecore_wl_input_grab(input, input->pointer_focus, button);
197 // _ecore_wl_input_mouse_move_send(input, timestamp);
199 if ((button >= BTN_SIDE) && (button <= BTN_BACK))
201 /* TODO: raise mouse wheel */
202 printf("Raise Mouse Wheel Event\n");
208 input->button = button;
209 _ecore_wl_input_mouse_down_send(input, timestamp);
213 _ecore_wl_input_mouse_up_send(input, timestamp);
216 if ((input->grab) && (input->grab_button == button))
217 ecore_wl_input_ungrab(input, timestamp);
223 _ecore_wl_input_cb_key(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp __UNUSED__, unsigned int key, unsigned int state)
225 Ecore_Wl_Input *input;
226 Ecore_Wl_Window *win;
227 unsigned int keycode = 0;
229 LOGFN(__FILE__, __LINE__, __FUNCTION__);
231 if (!(input = data)) return;
233 win = input->keyboard_focus;
234 if ((!win) || (win->keyboard_device != input)) return;
236 /* FIXME: NB: I believe this should be min_key_code rather than 8,
237 * but weston code has it like this */
240 /* if ((input->modifiers & XKB_COMMON_SHIFT_MASK) && */
241 /* (XkbKeyGroupWidth(_ecore_wl_disp->xkb, keycode, 0) > 1)) */
243 /* keysym = XkbKeySymEntry(_ecore_wl_disp->xkb, keycode, level, 0); */
246 input->modifiers |= _ecore_wl_disp->xkb->map->modmap[keycode];
248 input->modifiers &= ~_ecore_wl_disp->xkb->map->modmap[keycode];
252 _ecore_wl_input_cb_pointer_enter(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface, int sx, int sy)
254 Ecore_Wl_Input *input;
255 Ecore_Wl_Window *win = NULL;
257 LOGFN(__FILE__, __LINE__, __FUNCTION__);
259 if (!(input = data)) return;
261 /* _pointer_x = sx; */
262 /* _pointer_y = sy; */
264 /* input->sx = sx; */
265 /* input->sy = sy; */
267 // _ecore_wl_input_mouse_move_send(input, timestamp);
269 win = input->pointer_focus;
270 if ((win) && (win->surface != surface))
273 _ecore_wl_input_pointer_focus_remove(input, timestamp);
278 if ((win = wl_surface_get_user_data(surface)))
280 input->pointer_focus = win;
281 win->pointer_device = input;
283 /* if (input->button) */
285 /* _ecore_wl_input_mouse_up_send(input, timestamp); */
286 /* input->button = 0; */
289 _ecore_wl_input_mouse_in_send(input, timestamp);
294 _ecore_wl_input_cb_pointer_leave(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface __UNUSED__)
296 Ecore_Wl_Input *input;
298 LOGFN(__FILE__, __LINE__, __FUNCTION__);
300 if (!(input = data)) return;
301 _ecore_wl_input_pointer_focus_remove(input, timestamp);
305 _ecore_wl_input_cb_keyboard_enter(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface, struct wl_array *keys)
307 Ecore_Wl_Input *input;
308 Ecore_Wl_Window *win = NULL;
309 unsigned int *k, *end;
311 LOGFN(__FILE__, __LINE__, __FUNCTION__);
313 if (!(input = data)) return;
315 end = keys->data + keys->size;
316 input->modifiers = 0;
317 for (k = keys->data; k < end; k++)
318 input->modifiers |= _ecore_wl_disp->xkb->map->modmap[*k];
322 if ((win = wl_surface_get_user_data(surface)))
324 input->keyboard_focus = win;
325 win->keyboard_device = input;
328 input->keyboard_focus = NULL;
329 _ecore_wl_input_focus_in_send(input, timestamp);
334 _ecore_wl_input_cb_keyboard_leave(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface __UNUSED__)
336 Ecore_Wl_Input *input;
338 LOGFN(__FILE__, __LINE__, __FUNCTION__);
340 if (!(input = data)) return;
341 _ecore_wl_input_keyboard_focus_remove(input, timestamp);
345 _ecore_wl_input_cb_touch_down(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface __UNUSED__, int id __UNUSED__, int x, int y)
347 Ecore_Wl_Input *input;
349 LOGFN(__FILE__, __LINE__, __FUNCTION__);
351 if (!(input = data)) return;
353 /* FIXME: NB: Not sure yet if input->timestamp should be set here.
354 * This needs to be tested with an actual touch device */
355 /* input->timestamp = timestamp; */
359 _ecore_wl_input_mouse_down_send(input, timestamp);
363 _ecore_wl_input_cb_touch_up(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, int id __UNUSED__)
365 Ecore_Wl_Input *input;
367 LOGFN(__FILE__, __LINE__, __FUNCTION__);
369 if (!(input = data)) return;
371 /* FIXME: NB: Not sure yet if input->timestamp should be set here.
372 * This needs to be tested with an actual touch device */
373 /* input->timestamp = timestamp; */
375 _ecore_wl_input_mouse_up_send(input, timestamp);
379 _ecore_wl_input_cb_touch_motion(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, int id __UNUSED__, int x, int y)
381 Ecore_Wl_Input *input;
383 LOGFN(__FILE__, __LINE__, __FUNCTION__);
385 if (!(input = data)) return;
387 /* FIXME: NB: Not sure yet if input->timestamp should be set here.
388 * This needs to be tested with an actual touch device */
389 /* input->timestamp = timestamp; */
393 _ecore_wl_input_mouse_move_send(input, timestamp);
397 _ecore_wl_input_cb_touch_frame(void *data __UNUSED__, struct wl_input_device *input_device __UNUSED__)
399 LOGFN(__FILE__, __LINE__, __FUNCTION__);
403 _ecore_wl_input_cb_touch_cancel(void *data __UNUSED__, struct wl_input_device *input_device __UNUSED__)
405 LOGFN(__FILE__, __LINE__, __FUNCTION__);
409 _ecore_wl_input_cb_data_offer(void *data, struct wl_data_device *data_device, unsigned int id)
411 LOGFN(__FILE__, __LINE__, __FUNCTION__);
413 _ecore_wl_dnd_add(data, data_device, id);
417 _ecore_wl_input_cb_data_enter(void *data, struct wl_data_device *data_device, unsigned int timestamp, struct wl_surface *surface, int x, int y, struct wl_data_offer *offer)
419 LOGFN(__FILE__, __LINE__, __FUNCTION__);
421 _ecore_wl_dnd_enter(data, data_device, timestamp, surface, x, y, offer);
425 _ecore_wl_input_cb_data_leave(void *data, struct wl_data_device *data_device)
427 LOGFN(__FILE__, __LINE__, __FUNCTION__);
429 _ecore_wl_dnd_leave(data, data_device);
433 _ecore_wl_input_cb_data_motion(void *data, struct wl_data_device *data_device, unsigned int timestamp, int x, int y)
435 LOGFN(__FILE__, __LINE__, __FUNCTION__);
437 _ecore_wl_dnd_motion(data, data_device, timestamp, x, y);
441 _ecore_wl_input_cb_data_drop(void *data, struct wl_data_device *data_device)
443 LOGFN(__FILE__, __LINE__, __FUNCTION__);
445 _ecore_wl_dnd_drop(data, data_device);
449 _ecore_wl_input_cb_data_selection(void *data, struct wl_data_device *data_device, struct wl_data_offer *offer)
451 LOGFN(__FILE__, __LINE__, __FUNCTION__);
453 _ecore_wl_dnd_selection(data, data_device, offer);
457 _ecore_wl_input_keyboard_focus_remove(Ecore_Wl_Input *input, unsigned int timestamp)
459 Ecore_Wl_Window *win;
461 LOGFN(__FILE__, __LINE__, __FUNCTION__);
463 _ecore_wl_input_focus_out_send(input, timestamp);
464 if ((win = input->keyboard_focus))
465 win->keyboard_device = NULL;
466 input->keyboard_focus = NULL;
470 _ecore_wl_input_pointer_focus_remove(Ecore_Wl_Input *input, unsigned int timestamp)
472 Ecore_Wl_Window *win;
474 LOGFN(__FILE__, __LINE__, __FUNCTION__);
477 _ecore_wl_input_mouse_out_send(input, timestamp);
479 if ((win = input->pointer_focus))
480 win->pointer_device = NULL;
482 input->pointer_focus = NULL;
486 _ecore_wl_input_mouse_move_send(Ecore_Wl_Input *input, unsigned int timestamp)
488 Ecore_Event_Mouse_Move *ev;
489 // Ecore_Event *event;
491 LOGFN(__FILE__, __LINE__, __FUNCTION__);
493 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Move)))) return;
495 ev->timestamp = timestamp;
498 ev->root.x = input->sx;
499 ev->root.y = input->sy;
500 ev->modifiers = input->modifiers;
501 ev->multi.device = 0;
502 ev->multi.radius = 1;
503 ev->multi.radius_x = 1;
504 ev->multi.radius_y = 1;
505 ev->multi.pressure = 1.0;
506 ev->multi.angle = 0.0;
507 ev->multi.x = input->sx;
508 ev->multi.y = input->sy;
512 ev->window = input->grab->id;
513 ev->event_window = input->grab->id;
515 else if (input->pointer_focus)
517 ev->window = input->pointer_focus->id;
518 ev->event_window = input->pointer_focus->id;
521 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
525 _ecore_wl_input_mouse_in_send(Ecore_Wl_Input *input, unsigned int timestamp)
527 Ecore_Wl_Event_Mouse_In *ev;
529 LOGFN(__FILE__, __LINE__, __FUNCTION__);
531 if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Mouse_In)))) return;
535 ev->root.x = input->sx;
536 ev->root.y = input->sy;
537 ev->modifiers = input->modifiers;
538 ev->timestamp = timestamp;
540 if (input->pointer_focus)
542 ev->win = input->pointer_focus->id;
543 ev->event_win = input->pointer_focus->id;
546 ecore_event_add(ECORE_WL_EVENT_MOUSE_IN, ev, NULL, NULL);
550 _ecore_wl_input_mouse_out_send(Ecore_Wl_Input *input, unsigned int timestamp)
552 Ecore_Wl_Event_Mouse_Out *ev;
554 LOGFN(__FILE__, __LINE__, __FUNCTION__);
556 if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Mouse_Out)))) return;
560 ev->root.x = input->sx;
561 ev->root.y = input->sy;
562 ev->modifiers = input->modifiers;
563 ev->timestamp = timestamp;
565 if (input->pointer_focus)
567 ev->win = input->pointer_focus->id;
568 ev->event_win = input->pointer_focus->id;
571 ecore_event_add(ECORE_WL_EVENT_MOUSE_OUT, ev, NULL, NULL);
575 _ecore_wl_input_focus_in_send(Ecore_Wl_Input *input, unsigned int timestamp)
577 Ecore_Wl_Event_Focus_In *ev;
579 LOGFN(__FILE__, __LINE__, __FUNCTION__);
581 if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Focus_In)))) return;
582 ev->timestamp = timestamp;
583 if (input->keyboard_focus)
584 ev->win = input->keyboard_focus->id;
585 ecore_event_add(ECORE_WL_EVENT_FOCUS_IN, ev, NULL, NULL);
589 _ecore_wl_input_focus_out_send(Ecore_Wl_Input *input, unsigned int timestamp)
591 Ecore_Wl_Event_Focus_Out *ev;
593 LOGFN(__FILE__, __LINE__, __FUNCTION__);
595 if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Focus_Out)))) return;
596 ev->timestamp = timestamp;
597 if (input->keyboard_focus)
598 ev->win = input->keyboard_focus->id;
599 ecore_event_add(ECORE_WL_EVENT_FOCUS_OUT, ev, NULL, NULL);
603 _ecore_wl_input_mouse_down_send(Ecore_Wl_Input *input, unsigned int timestamp)
605 Ecore_Event_Mouse_Button *ev;
607 LOGFN(__FILE__, __LINE__, __FUNCTION__);
609 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Button)))) return;
611 if (input->button == BTN_LEFT)
613 else if (input->button == BTN_MIDDLE)
615 else if (input->button == BTN_RIGHT)
618 ev->buttons = input->button;
620 ev->timestamp = timestamp;
623 ev->root.x = input->sx;
624 ev->root.y = input->sy;
625 ev->modifiers = input->modifiers;
627 /* FIXME: Need to get these from wayland somehow */
628 ev->double_click = 0;
629 ev->triple_click = 0;
631 ev->multi.device = 0;
632 ev->multi.radius = 1;
633 ev->multi.radius_x = 1;
634 ev->multi.radius_y = 1;
635 ev->multi.pressure = 1.0;
636 ev->multi.angle = 0.0;
637 ev->multi.x = input->sx;
638 ev->multi.y = input->sy;
640 if (input->pointer_focus)
642 ev->window = input->pointer_focus->id;
643 ev->event_window = input->pointer_focus->id;
646 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
650 _ecore_wl_input_mouse_up_send(Ecore_Wl_Input *input, unsigned int timestamp)
652 Ecore_Event_Mouse_Button *ev;
654 LOGFN(__FILE__, __LINE__, __FUNCTION__);
656 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Button)))) return;
658 if (input->button == BTN_LEFT)
660 else if (input->button == BTN_MIDDLE)
662 else if (input->button == BTN_RIGHT)
665 ev->buttons = input->button;
667 ev->timestamp = timestamp;
670 ev->root.x = input->sx;
671 ev->root.y = input->sy;
672 ev->modifiers = input->modifiers;
674 /* FIXME: Need to get these from wayland somehow */
675 ev->double_click = 0;
676 ev->triple_click = 0;
678 ev->multi.device = 0;
679 ev->multi.radius = 1;
680 ev->multi.radius_x = 1;
681 ev->multi.radius_y = 1;
682 ev->multi.pressure = 1.0;
683 ev->multi.angle = 0.0;
684 ev->multi.x = input->sx;
685 ev->multi.y = input->sy;
687 if (input->pointer_focus)
689 ev->window = input->pointer_focus->id;
690 ev->event_window = input->pointer_focus->id;
693 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);