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 ?? */
15 # include <linux/input.h>
17 # define BTN_LEFT 0x110
18 # define BTN_RIGHT 0x111
19 # define BTN_MIDDLE 0x112
20 # define BTN_SIDE 0x113
21 # define BTN_EXTRA 0x114
22 # define BTN_FORWARD 0x115
23 # define BTN_BACK 0x116
26 #include <X11/extensions/XKBcommon.h>
28 /* local function prototypes */
29 static Eina_Bool _ecore_wl_shutdown(Eina_Bool close_display);
30 static void _ecore_wl_cb_disp_handle_global(struct wl_display *disp, uint32_t id, const char *interface, uint32_t version __UNUSED__, void *data __UNUSED__);
31 static int _ecore_wl_cb_disp_event_mask_update(uint32_t mask, void *data __UNUSED__);
32 static void _ecore_wl_cb_disp_handle_geometry(void *data __UNUSED__, struct wl_output *output __UNUSED__, int x, int y, int pw __UNUSED__, int ph __UNUSED__, int subpixel __UNUSED__, const char *make __UNUSED__, const char *model __UNUSED__);
33 static void _ecore_wl_cb_disp_handle_mode(void *data __UNUSED__, struct wl_output *output __UNUSED__, uint32_t flags, int w, int h, int refresh __UNUSED__);
34 static Eina_Bool _ecore_wl_cb_fd_handle(void *data, Ecore_Fd_Handler *hdl __UNUSED__);
35 static void _ecore_wl_cb_handle_motion(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t, int32_t x, int32_t y, int32_t sx, int32_t sy);
36 static void _ecore_wl_cb_handle_button(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t, uint32_t btn, uint32_t state);
37 static void _ecore_wl_cb_handle_key(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t __UNUSED__, uint32_t key, uint32_t state);
38 static void _ecore_wl_cb_handle_pointer_focus(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t, struct wl_surface *surface, int32_t x, int32_t y, int32_t sx, int32_t sy);
39 static void _ecore_wl_cb_handle_keyboard_focus(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t __UNUSED__, struct wl_surface *surface, struct wl_array *keys);
40 static void _ecore_wl_cb_handle_touch_down(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__, uint32_t timestamp, struct wl_surface *surface, int32_t id, int32_t x, int32_t y);
41 static void _ecore_wl_cb_handle_touch_up(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__, uint32_t timestamp, int32_t id);
42 static void _ecore_wl_cb_handle_touch_motion(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__, uint32_t timestamp, int32_t id, int32_t x, int32_t y);
43 static void _ecore_wl_cb_handle_touch_frame(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__);
44 static void _ecore_wl_cb_handle_touch_cancel(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__);
45 static void _ecore_wl_cb_source_target(void *data, struct wl_data_source *source __UNUSED__, const char *mime_type __UNUSED__);
46 static void _ecore_wl_cb_source_send(void *data, struct wl_data_source *source, const char *mime_type, int32_t fd);
47 static void _ecore_wl_cb_source_cancelled(void *data, struct wl_data_source *source __UNUSED__);
48 static void _ecore_wl_cb_source_offer(void *data, struct wl_data_offer *offer __UNUSED__, const char *type);
49 static void _ecore_wl_cb_data_offer(void *data, struct wl_data_device *data_dev, uint32_t id);
50 static void _ecore_wl_cb_data_enter(void *data __UNUSED__, struct wl_data_device *data_dev, uint32_t timestamp, struct wl_surface *surface, int32_t x, int32_t y, struct wl_data_offer *offer);
51 static void _ecore_wl_cb_data_leave(void *data __UNUSED__, struct wl_data_device *data_dev);
52 static void _ecore_wl_cb_data_motion(void *data __UNUSED__, struct wl_data_device *data_dev, uint32_t timestamp, int32_t x, int32_t y);
53 static void _ecore_wl_cb_data_drop(void *data __UNUSED__, struct wl_data_device *data_dev);
54 static void _ecore_wl_cb_data_selection(void *data, struct wl_data_device *data_dev, struct wl_data_offer *offer);
56 static void _ecore_wl_mouse_move_send(uint32_t timestamp);
57 static void _ecore_wl_mouse_out_send(struct wl_surface *surface, uint32_t timestamp);
58 static void _ecore_wl_mouse_in_send(struct wl_surface *surface, uint32_t timestamp);
59 static void _ecore_wl_mouse_up_send(struct wl_surface *surface, uint32_t button, uint32_t timestamp);
60 static void _ecore_wl_mouse_down_send(struct wl_surface *surface, uint32_t button, uint32_t timestamp);
61 static void _ecore_wl_focus_out_send(struct wl_surface *surface, uint32_t timestamp);
62 static void _ecore_wl_focus_in_send(struct wl_surface *surface, uint32_t timestamp);
65 static int _ecore_wl_init_count = 0;
66 static struct wl_display *_ecore_wl_disp = NULL;
67 static uint32_t _ecore_wl_disp_mask = 0;
68 static uint32_t _ecore_wl_disp_format = WL_SHM_FORMAT_ARGB8888;
69 static Eina_Rectangle _ecore_wl_screen;
70 static Ecore_Fd_Handler *_ecore_wl_fd_hdl = NULL;
71 static int _ecore_wl_screen_x = 0;
72 static int _ecore_wl_screen_y = 0;
73 static int _ecore_wl_surface_x = 0;
74 static int _ecore_wl_surface_y = 0;
75 static int _ecore_wl_touch_x = 0;
76 static int _ecore_wl_touch_y = 0;
77 static int _ecore_wl_input_modifiers = 0;
78 static struct xkb_desc *_ecore_wl_xkb;
79 static uint32_t _ecore_wl_input_button = 0;
81 static struct wl_compositor *_ecore_wl_comp;
82 static struct wl_shm *_ecore_wl_shm;
83 static struct wl_shell *_ecore_wl_shell;
84 static struct wl_output *_ecore_wl_output;
85 static struct wl_input_device *_ecore_wl_input_dev;
86 static struct wl_surface *_ecore_wl_input_surface;
87 static struct wl_surface *_ecore_wl_touch_surface;
88 static struct wl_data_device_manager *_ecore_wl_data_manager;
89 static struct wl_data_device *_ecore_wl_data_dev;
91 static const struct wl_output_listener _ecore_wl_output_listener =
93 _ecore_wl_cb_disp_handle_geometry,
94 _ecore_wl_cb_disp_handle_mode
96 static const struct wl_input_device_listener _ecore_wl_input_listener =
98 _ecore_wl_cb_handle_motion,
99 _ecore_wl_cb_handle_button,
100 _ecore_wl_cb_handle_key,
101 _ecore_wl_cb_handle_pointer_focus,
102 _ecore_wl_cb_handle_keyboard_focus,
103 _ecore_wl_cb_handle_touch_down,
104 _ecore_wl_cb_handle_touch_up,
105 _ecore_wl_cb_handle_touch_motion,
106 _ecore_wl_cb_handle_touch_frame,
107 _ecore_wl_cb_handle_touch_cancel,
109 static const struct wl_data_source_listener _ecore_wl_source_listener =
111 _ecore_wl_cb_source_target,
112 _ecore_wl_cb_source_send,
113 _ecore_wl_cb_source_cancelled
115 static const struct wl_data_device_listener _ecore_wl_data_listener =
117 _ecore_wl_cb_data_offer,
118 _ecore_wl_cb_data_enter,
119 _ecore_wl_cb_data_leave,
120 _ecore_wl_cb_data_motion,
121 _ecore_wl_cb_data_drop,
122 _ecore_wl_cb_data_selection
124 static const struct wl_data_offer_listener _ecore_wl_offer_listener =
126 _ecore_wl_cb_source_offer,
129 /* external variables */
130 int _ecore_wl_log_dom = -1;
131 EAPI int ECORE_WL_EVENT_MOUSE_IN = 0;
132 EAPI int ECORE_WL_EVENT_MOUSE_OUT = 0;
133 EAPI int ECORE_WL_EVENT_FOCUS_IN = 0;
134 EAPI int ECORE_WL_EVENT_FOCUS_OUT = 0;
135 EAPI int ECORE_WL_EVENT_DRAG_START = 0;
136 EAPI int ECORE_WL_EVENT_DRAG_STOP = 0;
139 ecore_wl_init(const char *name)
141 struct xkb_rule_names xkb_names;
144 if (++_ecore_wl_init_count != 1)
145 return _ecore_wl_init_count;
147 LOGFN(__FILE__, __LINE__, __FUNCTION__);
149 if (!eina_init()) return --_ecore_wl_init_count;
152 eina_log_domain_register("ecore_wl", ECORE_WL_DEFAULT_LOG_COLOR);
153 if (_ecore_wl_log_dom < 0)
155 EINA_LOG_ERR("Cannot create a log domain for Ecore Wayland.");
157 return --_ecore_wl_init_count;
162 eina_log_domain_unregister(_ecore_wl_log_dom);
163 _ecore_wl_log_dom = -1;
165 return --_ecore_wl_init_count;
168 if (!ecore_event_init())
170 eina_log_domain_unregister(_ecore_wl_log_dom);
171 _ecore_wl_log_dom = -1;
174 return --_ecore_wl_init_count;
177 if (!ECORE_WL_EVENT_MOUSE_IN)
179 ECORE_WL_EVENT_MOUSE_IN = ecore_event_type_new();
180 ECORE_WL_EVENT_MOUSE_OUT = ecore_event_type_new();
181 ECORE_WL_EVENT_FOCUS_IN = ecore_event_type_new();
182 ECORE_WL_EVENT_FOCUS_OUT = ecore_event_type_new();
183 ECORE_WL_EVENT_DRAG_START = ecore_event_type_new();
184 ECORE_WL_EVENT_DRAG_STOP = ecore_event_type_new();
188 /* FIXME: Somehow make this portable to other languages/countries */
189 xkb_names.rules = "evdev";
190 xkb_names.model = "evdev";
191 xkb_names.layout = "us";
192 xkb_names.variant = "";
193 xkb_names.options = "";
194 if (!(_ecore_wl_xkb = xkb_compile_keymap_from_rules(&xkb_names)))
196 ERR("Could not compile keymap");
197 eina_log_domain_unregister(_ecore_wl_log_dom);
198 _ecore_wl_log_dom = -1;
199 ecore_event_shutdown();
202 return --_ecore_wl_init_count;
205 /* connect to the wayland display */
206 if (!(_ecore_wl_disp = wl_display_connect(name)))
208 eina_log_domain_unregister(_ecore_wl_log_dom);
209 _ecore_wl_log_dom = -1;
210 ecore_event_shutdown();
213 return --_ecore_wl_init_count;
216 /* setup handler for wayland interfaces */
217 wl_display_add_global_listener(_ecore_wl_disp,
218 _ecore_wl_cb_disp_handle_global, NULL);
220 /* process connection events */
221 wl_display_iterate(_ecore_wl_disp, WL_DISPLAY_READABLE);
223 fd = wl_display_get_fd(_ecore_wl_disp,
224 _ecore_wl_cb_disp_event_mask_update, NULL);
227 ecore_main_fd_handler_add(fd, ECORE_FD_READ, _ecore_wl_cb_fd_handle,
228 _ecore_wl_disp, NULL, NULL);
229 if (!_ecore_wl_fd_hdl)
231 wl_display_destroy(_ecore_wl_disp);
232 _ecore_wl_disp = NULL;
233 eina_log_domain_unregister(_ecore_wl_log_dom);
234 _ecore_wl_log_dom = -1;
235 ecore_event_shutdown();
238 return --_ecore_wl_init_count;
241 return _ecore_wl_init_count;
245 ecore_wl_shutdown(void)
247 return _ecore_wl_shutdown(EINA_TRUE);
250 EAPI struct wl_display *
251 ecore_wl_display_get(void)
253 return _ecore_wl_disp;
257 ecore_wl_shm_get(void)
259 return _ecore_wl_shm;
262 EAPI struct wl_compositor *
263 ecore_wl_compositor_get(void)
265 return _ecore_wl_comp;
268 EAPI struct wl_shell *
269 ecore_wl_shell_get(void)
271 return _ecore_wl_shell;
274 EAPI struct wl_input_device *
275 ecore_wl_input_device_get(void)
277 return _ecore_wl_input_dev;
281 ecore_wl_screen_size_get(int *w, int *h)
283 if (w) *w = _ecore_wl_screen.w;
284 if (h) *h = _ecore_wl_screen.h;
288 ecore_wl_format_get(void)
290 return _ecore_wl_disp_format;
296 wl_display_flush(_ecore_wl_disp);
302 wl_display_iterate(_ecore_wl_disp, WL_DISPLAY_READABLE);
306 ecore_wl_pointer_xy_get(int *x, int *y)
308 if (x) *x = _ecore_wl_screen_x;
309 if (y) *y = _ecore_wl_screen_y;
312 EAPI Ecore_Wl_Drag_Source *
313 ecore_wl_drag_source_create(int hotspot_x, int hotspot_y, int offset_x, int offset_y, const char *mimetype, unsigned int timestamp, void *data)
315 Ecore_Wl_Drag_Source *source;
317 if (!(source = calloc(1, sizeof(Ecore_Wl_Drag_Source)))) return NULL;
319 source->data_dev = _ecore_wl_data_dev;
320 source->hotspot_x = hotspot_x;
321 source->hotspot_y = hotspot_y;
322 source->offset_x = offset_x;
323 source->offset_y = offset_y;
324 source->mimetype = mimetype;
325 source->timestamp = timestamp;
328 source->data_source =
329 wl_data_device_manager_create_data_source(_ecore_wl_data_manager);
331 wl_data_source_add_listener(source->data_source,
332 &_ecore_wl_source_listener, source);
334 wl_data_source_offer(source->data_source, source->mimetype);
336 /* NB: Do we add some default mimetypes here ?? */
337 /* text/plain, etc */
343 ecore_wl_drag_start(Ecore_Wl_Drag_Source *source, struct wl_surface *surface, struct wl_buffer *buffer)
345 source->buffer = buffer;
347 wl_data_device_start_drag(source->data_dev, source->data_source,
348 surface, source->timestamp);
352 ecore_wl_drag_stop(void)
357 /* local functions */
359 _ecore_wl_shutdown(Eina_Bool close_display)
361 LOGFN(__FILE__, __LINE__, __FUNCTION__);
363 if (--_ecore_wl_init_count != 0)
364 return _ecore_wl_init_count;
366 if (!_ecore_wl_disp) return _ecore_wl_init_count;
368 if (_ecore_wl_xkb) free(_ecore_wl_xkb);
370 if (_ecore_wl_fd_hdl) ecore_main_fd_handler_del(_ecore_wl_fd_hdl);
371 _ecore_wl_fd_hdl = NULL;
375 if (_ecore_wl_data_dev) wl_data_device_destroy(_ecore_wl_data_dev);
376 if (_ecore_wl_input_dev) wl_input_device_destroy(_ecore_wl_input_dev);
377 if (_ecore_wl_data_manager)
378 wl_data_device_manager_destroy(_ecore_wl_data_manager);
379 if (_ecore_wl_shell) wl_shell_destroy(_ecore_wl_shell);
380 if (_ecore_wl_shm) wl_shm_destroy(_ecore_wl_shm);
381 if (_ecore_wl_comp) wl_compositor_destroy(_ecore_wl_comp);
384 wl_display_flush(_ecore_wl_disp);
385 wl_display_destroy(_ecore_wl_disp);
387 _ecore_wl_disp = NULL;
390 eina_log_domain_unregister(_ecore_wl_log_dom);
391 _ecore_wl_log_dom = -1;
393 ecore_event_shutdown();
397 return _ecore_wl_init_count;
401 _ecore_wl_cb_disp_handle_global(struct wl_display *disp, uint32_t id, const char *interface, uint32_t version __UNUSED__, void *data __UNUSED__)
403 // LOGFN(__FILE__, __LINE__, __FUNCTION__);
405 if (disp != _ecore_wl_disp) return;
406 if (!strcmp(interface, "wl_compositor"))
409 wl_display_bind(_ecore_wl_disp, id, &wl_compositor_interface);
411 else if (!strcmp(interface, "wl_shm"))
414 wl_display_bind(_ecore_wl_disp, id, &wl_shm_interface);
416 else if (!strcmp(interface, "wl_output"))
419 wl_display_bind(_ecore_wl_disp, id, &wl_output_interface);
420 wl_output_add_listener(_ecore_wl_output,
421 &_ecore_wl_output_listener, NULL);
423 else if (!strcmp(interface, "wl_shell"))
426 wl_display_bind(_ecore_wl_disp, id, &wl_shell_interface);
428 else if (!strcmp(interface, "wl_input_device"))
430 _ecore_wl_input_dev =
431 wl_display_bind(_ecore_wl_disp, id, &wl_input_device_interface);
432 wl_input_device_add_listener(_ecore_wl_input_dev,
433 &_ecore_wl_input_listener, NULL);
435 else if (!strcmp(interface, "wl_data_device_manager"))
437 _ecore_wl_data_manager =
438 wl_display_bind(_ecore_wl_disp, id,
439 &wl_data_device_manager_interface);
442 if ((_ecore_wl_input_dev) && (_ecore_wl_data_manager) && (!_ecore_wl_data_dev))
445 wl_data_device_manager_get_data_device(_ecore_wl_data_manager,
446 _ecore_wl_input_dev);
447 wl_data_device_add_listener(_ecore_wl_data_dev,
448 &_ecore_wl_data_listener, NULL);
453 _ecore_wl_cb_disp_event_mask_update(uint32_t mask, void *data __UNUSED__)
455 // LOGFN(__FILE__, __LINE__, __FUNCTION__);
457 _ecore_wl_disp_mask = mask;
463 _ecore_wl_cb_disp_handle_geometry(void *data __UNUSED__, struct wl_output *output __UNUSED__, int x, int y, int pw __UNUSED__, int ph __UNUSED__, int subpixel __UNUSED__, const char *make __UNUSED__, const char *model __UNUSED__)
465 _ecore_wl_screen.x = x;
466 _ecore_wl_screen.y = y;
470 _ecore_wl_cb_disp_handle_mode(void *data __UNUSED__, struct wl_output *output __UNUSED__, uint32_t flags, int w, int h, int refresh __UNUSED__)
472 if (flags & WL_OUTPUT_MODE_CURRENT)
474 _ecore_wl_screen.w = w;
475 _ecore_wl_screen.h = h;
480 _ecore_wl_cb_fd_handle(void *data, Ecore_Fd_Handler *hdl __UNUSED__)
482 struct wl_display *disp;
484 // LOGFN(__FILE__, __LINE__, __FUNCTION__);
486 if (!(disp = data)) return ECORE_CALLBACK_RENEW;
487 if (disp != _ecore_wl_disp) return ECORE_CALLBACK_RENEW;
489 if (_ecore_wl_disp_mask & WL_DISPLAY_WRITABLE)
490 wl_display_iterate(_ecore_wl_disp, WL_DISPLAY_WRITABLE);
492 if (_ecore_wl_disp_mask & WL_DISPLAY_READABLE)
493 wl_display_iterate(_ecore_wl_disp, WL_DISPLAY_READABLE);
495 return ECORE_CALLBACK_RENEW;
499 _ecore_wl_cb_handle_motion(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t, int32_t x, int32_t y, int32_t sx, int32_t sy)
501 if (dev != _ecore_wl_input_dev) return;
503 _ecore_wl_screen_x = x;
504 _ecore_wl_screen_y = y;
505 _ecore_wl_surface_x = sx;
506 _ecore_wl_surface_y = sy;
508 _ecore_wl_mouse_move_send(t);
512 _ecore_wl_cb_handle_button(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t, uint32_t btn, uint32_t state)
514 if (dev != _ecore_wl_input_dev) return;
516 if ((btn >= BTN_SIDE) && (btn <= BTN_BACK))
518 Ecore_Event_Mouse_Wheel *ev;
520 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Wheel)))) return;
523 ev->x = _ecore_wl_surface_x;
524 ev->y = _ecore_wl_surface_y;
525 ev->root.x = _ecore_wl_screen_x;
526 ev->root.y = _ecore_wl_screen_y;
527 ev->modifiers = _ecore_wl_input_modifiers;
530 if (_ecore_wl_input_surface)
534 if ((id = (unsigned int)wl_surface_get_user_data(_ecore_wl_input_surface)))
537 ev->event_window = id;
541 /* NB: (FIXME) Currently Wayland provides no measure of how much the
542 * wheel has scrolled (read: delta of movement). So for now, we will
543 * just assume that the amount scrolled is 1 */
544 if ((btn == BTN_EXTRA) || (btn == BTN_FORWARD)) // down
546 else if ((btn == BTN_SIDE) || (btn == BTN_BACK)) // up
549 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
555 _ecore_wl_input_button = btn;
556 _ecore_wl_mouse_down_send(_ecore_wl_input_surface, btn, t);
557 /* NB: Ideally, this is not the place to check for drags.
558 * IMO, drags should be handled by the client. EG: we raise the
559 * mouse_down to the client, and the client can 'request' a
560 * drag_start from ecore_wl */
561 if ((_ecore_wl_input_surface) || (_ecore_wl_touch_surface))
563 /* record item which was grabbed.
564 * create drag source. start drag */
569 if ((_ecore_wl_input_surface) || (_ecore_wl_touch_surface))
571 /* release grabbed button and finish drag */
572 if ((_ecore_wl_input_button) &&
573 (_ecore_wl_input_button == btn))
578 _ecore_wl_input_button = 0;
579 _ecore_wl_mouse_up_send(_ecore_wl_input_surface, btn, t);
585 _ecore_wl_cb_handle_key(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t __UNUSED__, uint32_t key, uint32_t state)
587 unsigned int keycode = 0;
589 if (dev != _ecore_wl_input_dev) return;
591 keycode = key + _ecore_wl_xkb->min_key_code;
594 _ecore_wl_input_modifiers |= _ecore_wl_xkb->map->modmap[keycode];
596 _ecore_wl_input_modifiers &= ~_ecore_wl_xkb->map->modmap[keycode];
600 _ecore_wl_cb_handle_pointer_focus(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t, struct wl_surface *surface, int32_t x, int32_t y, int32_t sx, int32_t sy)
602 if (dev != _ecore_wl_input_dev) return;
604 /* NB: Wayland pointer focus is weird. It's not pointer focus in the normal
605 * sense...Wayland 'moving/resizing' (and maybe other stuff) has a habit
606 * of stealing the pointer focus and thus this cannot be used to control
607 * normal pointer focus. On mouse down, the 'active' surface is stolen
608 * by Wayland for the grab, so 'surface' here ends up being NULL. When a
609 * move or resize is finished, we get this event again, but this time
610 * with an active surface */
611 _ecore_wl_screen_x = x;
612 _ecore_wl_screen_y = y;
613 _ecore_wl_surface_x = sx;
614 _ecore_wl_surface_y = sy;
616 if ((_ecore_wl_input_surface) && (_ecore_wl_input_surface != surface))
618 if (!_ecore_wl_input_button)
619 _ecore_wl_mouse_out_send(_ecore_wl_input_surface, t);
624 if (_ecore_wl_input_button)
626 _ecore_wl_mouse_up_send(surface, _ecore_wl_input_button, t);
627 _ecore_wl_input_button = 0;
630 _ecore_wl_mouse_in_send(surface, t);
635 _ecore_wl_cb_handle_keyboard_focus(void *data __UNUSED__, struct wl_input_device *dev, uint32_t t, struct wl_surface *surface, struct wl_array *keys)
637 unsigned int *keyend = 0, *i = 0;
639 if (dev != _ecore_wl_input_dev) return;
641 /* NB: Remove old keyboard focus */
642 if ((_ecore_wl_input_surface) && (_ecore_wl_input_surface != surface))
643 _ecore_wl_focus_out_send(_ecore_wl_input_surface, t);
645 _ecore_wl_input_surface = NULL;
647 keyend = keys->data + keys->size;
648 _ecore_wl_input_modifiers = 0;
649 for (i = keys->data; i < keyend; i++)
650 _ecore_wl_input_modifiers |= _ecore_wl_xkb->map->modmap[*i];
654 /* set new input surface */
655 _ecore_wl_input_surface = surface;
657 /* send mouse in to new surface */
658 /* _ecore_wl_mouse_in_send(surface, t); */
660 /* send focus to new surface */
661 _ecore_wl_focus_in_send(surface, t);
666 _ecore_wl_cb_handle_touch_down(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__, uint32_t timestamp, struct wl_surface *surface, int32_t id, int32_t x, int32_t y)
668 Ecore_Event_Mouse_Button *ev;
670 LOGFN(__FILE__, __LINE__, __FUNCTION__);
672 _ecore_wl_touch_surface = surface;
673 _ecore_wl_touch_x = x;
674 _ecore_wl_touch_y = y;
676 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Button)))) return;
678 ev->timestamp = timestamp;
680 /* NB: Need to verify using x,y for these */
689 /* FIXME: Need to get these from Wayland somehow */
690 ev->double_click = 0;
691 ev->triple_click = 0;
693 ev->multi.device = id;
694 ev->multi.radius = 1;
695 ev->multi.radius_x = 1;
696 ev->multi.radius_y = 1;
697 ev->multi.pressure = 1.0;
698 ev->multi.angle = 0.0;
699 /* NB: Need to verify using x,y for these */
702 ev->multi.root.x = x;
703 ev->multi.root.y = y;
708 if ((id = (unsigned int)wl_surface_get_user_data(surface)))
711 ev->event_window = id;
715 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
719 _ecore_wl_cb_handle_touch_up(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__, uint32_t timestamp, int32_t id)
721 Ecore_Event_Mouse_Button *ev;
723 LOGFN(__FILE__, __LINE__, __FUNCTION__);
725 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Button)))) return;
727 ev->timestamp = timestamp;
729 /* TODO: Need to verify using x,y for these */
730 ev->x = _ecore_wl_touch_x;
731 ev->y = _ecore_wl_touch_y;
732 ev->root.x = _ecore_wl_touch_x;
733 ev->root.y = _ecore_wl_touch_y;
738 /* FIXME: Need to get these from Wayland somehow */
739 ev->double_click = 0;
740 ev->triple_click = 0;
742 ev->multi.device = id;
743 ev->multi.radius = 1;
744 ev->multi.radius_x = 1;
745 ev->multi.radius_y = 1;
746 ev->multi.pressure = 1.0;
747 ev->multi.angle = 0.0;
749 /* TODO: Need to verify using x,y for these */
750 ev->multi.x = _ecore_wl_touch_x;
751 ev->multi.y = _ecore_wl_touch_y;
752 ev->multi.root.x = _ecore_wl_touch_x;
753 ev->multi.root.y = _ecore_wl_touch_y;
758 if ((id = (unsigned int)wl_surface_get_user_data(_ecore_wl_touch_surface)))
761 ev->event_window = id;
765 _ecore_wl_touch_surface = NULL;
767 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
771 _ecore_wl_cb_handle_touch_motion(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__, uint32_t timestamp, int32_t id, int32_t x, int32_t y)
773 Ecore_Event_Mouse_Move *ev;
775 LOGFN(__FILE__, __LINE__, __FUNCTION__);
777 if (!_ecore_wl_touch_surface) return;
779 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Move)))) return;
781 ev->timestamp = timestamp;
782 /* TODO: Need to verify using x,y for these */
787 ev->modifiers = 0; //_ecore_wl_input_modifiers;
790 ev->multi.device = id;
791 ev->multi.radius = 1;
792 ev->multi.radius_x = 1;
793 ev->multi.radius_y = 1;
794 ev->multi.pressure = 1.0;
795 ev->multi.angle = 0.0;
797 /* TODO: Need to verify using x,y for these */
800 ev->multi.root.x = x;
801 ev->multi.root.y = y;
806 if ((id = (unsigned int)wl_surface_get_user_data(_ecore_wl_touch_surface)))
809 ev->event_window = id;
813 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
817 _ecore_wl_cb_handle_touch_frame(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__)
819 LOGFN(__FILE__, __LINE__, __FUNCTION__);
821 /* FIXME: Need to get a device and actually test what happens here */
825 _ecore_wl_cb_handle_touch_cancel(void *data __UNUSED__, struct wl_input_device *dev __UNUSED__)
827 LOGFN(__FILE__, __LINE__, __FUNCTION__);
829 /* FIXME: Need to get a device and actually test what happens here */
830 _ecore_wl_touch_surface = NULL;
834 _ecore_wl_cb_source_target(void *data, struct wl_data_source *source __UNUSED__, const char *mime_type __UNUSED__)
836 Ecore_Wl_Drag_Source *s;
838 LOGFN(__FILE__, __LINE__, __FUNCTION__);
840 printf("Ecore_Wl Source Target\n");
841 if (!(s = data)) return;
842 printf("\tHave Drag Source\n");
844 /* FIXME: buffer here should really be the mouse cursor buffer */
845 wl_data_device_attach(s->data_dev, s->timestamp, s->buffer,
846 s->hotspot_x, s->hotspot_y);
850 _ecore_wl_cb_source_send(void *data, struct wl_data_source *source, const char *mime_type, int32_t fd)
852 Ecore_Wl_Drag_Source *s;
854 LOGFN(__FILE__, __LINE__, __FUNCTION__);
856 printf("Ecore_Wl Source Send\n");
857 if (!(s = data)) return;
858 printf("\tHave Drag Source\n");
860 /* FIXME: write message to fd */
862 /* NB: Wayland really sucks in this regard. Why should selection stuff
863 * require an 'fd' ?? */
867 _ecore_wl_cb_source_cancelled(void *data, struct wl_data_source *source __UNUSED__)
869 Ecore_Wl_Drag_Source *s;
871 LOGFN(__FILE__, __LINE__, __FUNCTION__);
873 /* The cancelled event usually means source is no longer in use by
874 * the drag (or selection). */
876 printf("Ecore_Wl Source Cancel\n");
877 if (!(s = data)) return;
878 printf("\tHave Drag Source\n");
880 /* FIXME: raise this to ecore_evas so the surface/buffer
881 * of the drag can be destroyed */
883 if (s->data_source) wl_data_source_destroy(s->data_source);
884 s->data_source = NULL;
890 _ecore_wl_cb_source_offer(void *data, struct wl_data_offer *offer __UNUSED__, const char *type)
892 Ecore_Wl_Dnd_Source *s;
894 if (!(s = data)) return;
895 eina_array_push(s->types, strdup(type));
899 _ecore_wl_cb_data_offer(void *data, struct wl_data_device *data_dev, uint32_t id)
901 Ecore_Wl_Dnd_Source *source;
903 /* create a new 'data offer' structure and setup a listener for it */
904 if (!(source = calloc(1, sizeof(Ecore_Wl_Dnd_Source)))) return;
906 source->types = eina_array_new(1);
910 /* FIXME: This will need to change when Wayland has typesafe wrappers for this */
911 source->offer = (struct wl_data_offer *)
912 wl_proxy_create_for_id((struct wl_proxy *)data_dev,
913 id, &wl_data_offer_interface);
915 wl_data_device_set_user_data(data_dev, source);
916 wl_data_offer_add_listener(source->offer, &_ecore_wl_offer_listener, source);
920 _ecore_wl_cb_data_enter(void *data __UNUSED__, struct wl_data_device *data_dev, uint32_t timestamp, struct wl_surface *surface, int32_t x, int32_t y, struct wl_data_offer *offer)
922 Ecore_Wl_Dnd_Source *source;
924 if (!(source = wl_data_device_get_user_data(data_dev))) return;
926 /* TODO: maybe set pointer focus here ?? */
928 source->timestamp = timestamp;
932 _ecore_wl_cb_data_leave(void *data __UNUSED__, struct wl_data_device *data_dev)
934 Ecore_Wl_Dnd_Source *source;
936 if (!(source = wl_data_device_get_user_data(data_dev))) return;
938 /* destroy drag offer */
939 wl_data_offer_destroy(source->offer);
941 while (eina_array_count(source->types))
942 free(eina_array_pop(source->types));
944 eina_array_free(source->types);
947 wl_data_device_set_user_data(data_dev, NULL);
951 _ecore_wl_cb_data_motion(void *data __UNUSED__, struct wl_data_device *data_dev, uint32_t timestamp, int32_t x, int32_t y)
953 Ecore_Wl_Dnd_Source *source;
955 if (!(source = wl_data_device_get_user_data(data_dev))) return;
956 /* TODO: Here we should raise motion events for dragging */
960 _ecore_wl_cb_data_drop(void *data __UNUSED__, struct wl_data_device *data_dev)
962 Ecore_Wl_Dnd_Source *source;
964 if (!(source = wl_data_device_get_user_data(data_dev))) return;
966 /* TODO: Raise event for drop */
968 wl_data_offer_accept(source->offer, source->timestamp, NULL);
969 // eina_array_data_get(source->types, 0));
973 _ecore_wl_cb_data_selection(void *data, struct wl_data_device *data_dev, struct wl_data_offer *offer)
975 Ecore_Wl_Dnd_Source *source;
977 printf("Ecore_Wl Data Selection\n");
978 if ((source = wl_data_device_get_user_data(data_dev)))
980 /* destroy old source */
981 wl_data_offer_destroy(source->offer);
983 while (eina_array_count(source->types))
984 free(eina_array_pop(source->types));
986 eina_array_free(source->types);
989 wl_data_device_set_user_data(data_dev, NULL);
994 _ecore_wl_mouse_move_send(uint32_t timestamp)
996 Ecore_Event_Mouse_Move *ev;
998 // if (!_ecore_wl_input_surface) return;
1000 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Move)))) return;
1002 ev->timestamp = timestamp;
1003 ev->x = _ecore_wl_surface_x;
1004 ev->y = _ecore_wl_surface_y;
1005 ev->root.x = _ecore_wl_screen_x;
1006 ev->root.y = _ecore_wl_screen_y;
1007 ev->modifiers = _ecore_wl_input_modifiers;
1009 ev->multi.device = 0;
1010 ev->multi.radius = 1;
1011 ev->multi.radius_x = 1;
1012 ev->multi.radius_y = 1;
1013 ev->multi.pressure = 1.0;
1014 ev->multi.angle = 0.0;
1015 ev->multi.x = _ecore_wl_surface_x;
1016 ev->multi.y = _ecore_wl_surface_y;
1017 ev->multi.root.x = _ecore_wl_screen_x;
1018 ev->multi.root.y = _ecore_wl_screen_y;
1021 unsigned int id = 0;
1023 if ((id = (unsigned int)wl_surface_get_user_data(_ecore_wl_input_surface)))
1026 ev->event_window = id;
1030 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
1034 _ecore_wl_mouse_out_send(struct wl_surface *surface, uint32_t timestamp)
1036 Ecore_Wl_Event_Mouse_Out *ev;
1038 if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Mouse_Out)))) return;
1040 ev->x = _ecore_wl_surface_x;
1041 ev->y = _ecore_wl_surface_y;
1042 ev->root.x = _ecore_wl_screen_x;
1043 ev->root.y = _ecore_wl_screen_y;
1044 ev->modifiers = _ecore_wl_input_modifiers;
1045 ev->time = timestamp;
1049 unsigned int id = 0;
1051 if ((id = (unsigned int)wl_surface_get_user_data(surface)))
1055 ecore_event_add(ECORE_WL_EVENT_MOUSE_OUT, ev, NULL, NULL);
1059 _ecore_wl_mouse_in_send(struct wl_surface *surface, uint32_t timestamp)
1061 Ecore_Wl_Event_Mouse_In *ev;
1063 if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Mouse_In)))) return;
1065 ev->x = _ecore_wl_surface_x;
1066 ev->y = _ecore_wl_surface_y;
1067 ev->root.x = _ecore_wl_screen_x;
1068 ev->root.y = _ecore_wl_screen_y;
1069 ev->modifiers = _ecore_wl_input_modifiers;
1070 ev->time = timestamp;
1074 unsigned int id = 0;
1076 if ((id = (unsigned int)wl_surface_get_user_data(surface)))
1080 ecore_event_add(ECORE_WL_EVENT_MOUSE_IN, ev, NULL, NULL);
1084 _ecore_wl_mouse_up_send(struct wl_surface *surface, uint32_t button, uint32_t timestamp)
1086 Ecore_Event_Mouse_Button *ev;
1088 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Button)))) return;
1090 if (button == BTN_LEFT)
1092 else if (button == BTN_MIDDLE)
1094 else if (button == BTN_RIGHT)
1097 ev->timestamp = timestamp;
1098 ev->x = _ecore_wl_surface_x;
1099 ev->y = _ecore_wl_surface_y;
1100 ev->root.x = _ecore_wl_screen_x;
1101 ev->root.y = _ecore_wl_screen_y;
1102 ev->modifiers = _ecore_wl_input_modifiers;
1104 /* FIXME: Need to get these from Wayland somehow */
1105 ev->double_click = 0;
1106 ev->triple_click = 0;
1108 ev->multi.device = 0;
1109 ev->multi.radius = 1;
1110 ev->multi.radius_x = 1;
1111 ev->multi.radius_y = 1;
1112 ev->multi.pressure = 1.0;
1113 ev->multi.angle = 0.0;
1114 ev->multi.x = _ecore_wl_surface_x;
1115 ev->multi.y = _ecore_wl_surface_y;
1116 ev->multi.root.x = _ecore_wl_screen_x;
1117 ev->multi.root.y = _ecore_wl_screen_y;
1120 unsigned int id = 0;
1122 if ((id = (unsigned int)wl_surface_get_user_data(surface)))
1125 ev->event_window = id;
1129 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
1133 _ecore_wl_mouse_down_send(struct wl_surface *surface, uint32_t button, uint32_t timestamp)
1135 Ecore_Event_Mouse_Button *ev;
1137 if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Button)))) return;
1139 if (button == BTN_LEFT)
1141 else if (button == BTN_MIDDLE)
1143 else if (button == BTN_RIGHT)
1146 ev->timestamp = timestamp;
1147 ev->x = _ecore_wl_surface_x;
1148 ev->y = _ecore_wl_surface_y;
1149 ev->root.x = _ecore_wl_screen_x;
1150 ev->root.y = _ecore_wl_screen_y;
1151 ev->modifiers = _ecore_wl_input_modifiers;
1153 /* FIXME: Need to get these from Wayland somehow */
1154 ev->double_click = 0;
1155 ev->triple_click = 0;
1157 ev->multi.device = 0;
1158 ev->multi.radius = 1;
1159 ev->multi.radius_x = 1;
1160 ev->multi.radius_y = 1;
1161 ev->multi.pressure = 1.0;
1162 ev->multi.angle = 0.0;
1163 ev->multi.x = _ecore_wl_surface_x;
1164 ev->multi.y = _ecore_wl_surface_y;
1165 ev->multi.root.x = _ecore_wl_screen_x;
1166 ev->multi.root.y = _ecore_wl_screen_y;
1169 unsigned int id = 0;
1171 if ((id = (unsigned int)wl_surface_get_user_data(surface)))
1174 ev->event_window = id;
1178 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
1182 _ecore_wl_focus_out_send(struct wl_surface *surface, uint32_t timestamp)
1184 Ecore_Wl_Event_Focus_Out *ev;
1186 if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Focus_Out)))) return;
1187 ev->time = timestamp;
1190 unsigned int id = 0;
1192 if ((id = (unsigned int)wl_surface_get_user_data(surface)))
1195 ecore_event_add(ECORE_WL_EVENT_FOCUS_OUT, ev, NULL, NULL);
1199 _ecore_wl_focus_in_send(struct wl_surface *surface, uint32_t timestamp)
1201 Ecore_Wl_Event_Focus_In *ev;
1203 if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Focus_In)))) return;
1204 ev->time = timestamp;
1207 unsigned int id = 0;
1209 if ((id = (unsigned int)wl_surface_get_user_data(surface)))
1212 ecore_event_add(ECORE_WL_EVENT_FOCUS_IN, ev, NULL, NULL);