cc654a7abe3337d2c8f479e6ab15793c2ca0fe32
[framework/uifw/ecore.git] / src / lib / ecore_wayland / ecore_wl_input.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include "Ecore.h"
6 #include "ecore_private.h"
7 #include "Ecore_Input.h"
8 #include "ecore_wl_private.h"
9 #include "Ecore_Wayland.h"
10
11 /* FIXME: This gives BTN_LEFT/RIGHT/MIDDLE for linux systems ... 
12  *        What about other OSs ?? */
13 #ifdef __linux__
14 # include <linux/input.h>
15 #else
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
23 #endif
24
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);
44
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);
54
55 /* wayland interfaces */
56 static const struct wl_input_device_listener _ecore_wl_input_listener = 
57 {
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
70 };
71
72 static const struct wl_data_device_listener _ecore_wl_data_listener = 
73 {
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
80 };
81
82 /* local variables */
83 static int _pointer_x, _pointer_y;
84
85 EAPI void 
86 ecore_wl_input_grab(Ecore_Wl_Input *input, Ecore_Wl_Window *win, unsigned int button)
87 {
88    LOGFN(__FILE__, __LINE__, __FUNCTION__);
89
90    input->grab = win;
91    input->grab_button = button;
92 }
93
94 EAPI void 
95 ecore_wl_input_ungrab(Ecore_Wl_Input *input, unsigned int timestamp)
96 {
97    LOGFN(__FILE__, __LINE__, __FUNCTION__);
98
99    input->grab = NULL;
100    if (input->pointer_focus)
101      {
102         printf("Ungrab: %d\n", timestamp);
103      }
104 }
105
106 void 
107 _ecore_wl_input_add(Ecore_Wl_Display *ewd, unsigned int id)
108 {
109    Ecore_Wl_Input *input;
110
111    LOGFN(__FILE__, __LINE__, __FUNCTION__);
112
113    if (!(input = malloc(sizeof(Ecore_Wl_Input)))) return;
114
115    memset(input, 0, sizeof(Ecore_Wl_Input));
116
117    input->display = ewd;
118    input->pointer_focus = NULL;
119    input->keyboard_focus = NULL;
120
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);
127
128    input->data_device = 
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);
133    ewd->input = input;
134 }
135
136 void 
137 _ecore_wl_input_del(Ecore_Wl_Input *input)
138 {
139    if (!input) return;
140
141    _ecore_wl_input_keyboard_focus_remove(input, 0);
142    _ecore_wl_input_pointer_focus_remove(input, 0);
143
144    if (input->drag_source) _ecore_wl_dnd_del(input->drag_source);
145    input->drag_source = NULL;
146
147    if (input->selection_source) _ecore_wl_dnd_del(input->selection_source);
148    input->selection_source = NULL;
149
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);
153    free(input);
154 }
155
156 void 
157 _ecore_wl_input_pointer_xy_get(int *x, int *y)
158 {
159    if (x) *x = _pointer_x;
160    if (y) *y = _pointer_y;
161 }
162
163 /* local functions */
164 static void 
165 _ecore_wl_input_cb_motion(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, int sx, int sy)
166 {
167    Ecore_Wl_Input *input;
168
169    LOGFN(__FILE__, __LINE__, __FUNCTION__);
170
171    if (!(input = data)) return;
172
173    _pointer_x = sx;
174    _pointer_y = sy;
175
176    input->sx = sx;
177    input->sy = sy;
178
179    /* TODO: FIXME: NB: Weston window code has set pointer image here also */
180    _ecore_wl_input_mouse_move_send(input, timestamp);
181 }
182
183 static void 
184 _ecore_wl_input_cb_button(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, unsigned int button, unsigned int state)
185 {
186    Ecore_Wl_Input *input;
187
188    LOGFN(__FILE__, __LINE__, __FUNCTION__);
189
190    if (!(input = data)) return;
191
192    input->timestamp = timestamp;
193
194    if ((input->pointer_focus) && (!input->grab) && (state))
195      ecore_wl_input_grab(input, input->pointer_focus, button);
196
197 //   _ecore_wl_input_mouse_move_send(input, timestamp);
198
199    if ((button >= BTN_SIDE) && (button <= BTN_BACK))
200      {
201         /* TODO: raise mouse wheel */
202         printf("Raise Mouse Wheel Event\n");
203      }
204    else
205      {
206         if (state)
207           {
208              input->button = button;
209              _ecore_wl_input_mouse_down_send(input, timestamp);
210           }
211         else
212           {
213              _ecore_wl_input_mouse_up_send(input, timestamp);
214              input->button = 0;
215
216              if ((input->grab) && (input->grab_button == button))
217                ecore_wl_input_ungrab(input, timestamp);
218           }
219      }
220 }
221
222 static void 
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)
224 {
225    Ecore_Wl_Input *input;
226    Ecore_Wl_Window *win;
227    unsigned int keycode = 0;
228
229    LOGFN(__FILE__, __LINE__, __FUNCTION__);
230
231    if (!(input = data)) return;
232
233    win = input->keyboard_focus;
234    if ((!win) || (win->keyboard_device != input)) return;
235
236    /* FIXME: NB: I believe this should be min_key_code rather than 8, 
237     * but weston code has it like this */
238    keycode = key + 8;
239
240    /* if ((input->modifiers & XKB_COMMON_SHIFT_MASK) &&  */
241    /*     (XkbKeyGroupWidth(_ecore_wl_disp->xkb, keycode, 0) > 1))  */
242    /*   level = 1; */
243    /* keysym = XkbKeySymEntry(_ecore_wl_disp->xkb, keycode, level, 0); */
244
245    if (state)
246      input->modifiers |= _ecore_wl_disp->xkb->map->modmap[keycode];
247    else
248      input->modifiers &= ~_ecore_wl_disp->xkb->map->modmap[keycode];
249 }
250
251 static void 
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)
253 {
254    Ecore_Wl_Input *input;
255    Ecore_Wl_Window *win = NULL;
256
257    LOGFN(__FILE__, __LINE__, __FUNCTION__);
258
259    if (!(input = data)) return;
260
261    /* _pointer_x = sx; */
262    /* _pointer_y = sy; */
263
264    /* input->sx = sx; */
265    /* input->sy = sy; */
266
267 //   _ecore_wl_input_mouse_move_send(input, timestamp);
268
269    win = input->pointer_focus;
270    if ((win) && (win->surface != surface))
271      {
272         if (!input->button)
273           _ecore_wl_input_pointer_focus_remove(input, timestamp);
274      }
275
276    if (surface)
277      {
278         if ((win = wl_surface_get_user_data(surface)))
279           {
280              input->pointer_focus = win;
281              win->pointer_device = input;
282           }
283         /* if (input->button) */
284         /*   { */
285         /*      _ecore_wl_input_mouse_up_send(input, timestamp); */
286         /*      input->button = 0; */
287         /*   } */
288         /* else */
289           _ecore_wl_input_mouse_in_send(input, timestamp);
290      }
291 }
292
293 static void 
294 _ecore_wl_input_cb_pointer_leave(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface __UNUSED__)
295 {
296    Ecore_Wl_Input *input;
297
298    LOGFN(__FILE__, __LINE__, __FUNCTION__);
299
300    if (!(input = data)) return;
301    _ecore_wl_input_pointer_focus_remove(input, timestamp);
302 }
303
304 static void 
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)
306 {
307    Ecore_Wl_Input *input;
308    Ecore_Wl_Window *win = NULL;
309    unsigned int *k, *end;
310
311    LOGFN(__FILE__, __LINE__, __FUNCTION__);
312
313    if (!(input = data)) return;
314
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];
319
320    if (surface)
321      {
322         if ((win = wl_surface_get_user_data(surface)))
323           {
324              input->keyboard_focus = win;
325              win->keyboard_device = input;
326           }
327         else
328           input->keyboard_focus = NULL;
329         _ecore_wl_input_focus_in_send(input, timestamp);
330      }
331 }
332
333 static void 
334 _ecore_wl_input_cb_keyboard_leave(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, struct wl_surface *surface __UNUSED__)
335 {
336    Ecore_Wl_Input *input;
337
338    LOGFN(__FILE__, __LINE__, __FUNCTION__);
339
340    if (!(input = data)) return;
341    _ecore_wl_input_keyboard_focus_remove(input, timestamp);
342 }
343
344 static void 
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)
346 {
347    Ecore_Wl_Input *input;
348
349    LOGFN(__FILE__, __LINE__, __FUNCTION__);
350
351    if (!(input = data)) return;
352
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; */
356    input->button = 0;
357    input->sx = x;
358    input->sy = y;
359    _ecore_wl_input_mouse_down_send(input, timestamp);
360 }
361
362 static void 
363 _ecore_wl_input_cb_touch_up(void *data, struct wl_input_device *input_device __UNUSED__, unsigned int timestamp, int id __UNUSED__)
364 {
365    Ecore_Wl_Input *input;
366
367    LOGFN(__FILE__, __LINE__, __FUNCTION__);
368
369    if (!(input = data)) return;
370
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; */
374    input->button = 0;
375    _ecore_wl_input_mouse_up_send(input, timestamp);
376 }
377
378 static void 
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)
380 {
381    Ecore_Wl_Input *input;
382
383    LOGFN(__FILE__, __LINE__, __FUNCTION__);
384
385    if (!(input = data)) return;
386
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; */
390    input->sx = x;
391    input->sy = y;
392
393    _ecore_wl_input_mouse_move_send(input, timestamp);
394 }
395
396 static void 
397 _ecore_wl_input_cb_touch_frame(void *data __UNUSED__, struct wl_input_device *input_device __UNUSED__)
398 {
399    LOGFN(__FILE__, __LINE__, __FUNCTION__);
400 }
401
402 static void 
403 _ecore_wl_input_cb_touch_cancel(void *data __UNUSED__, struct wl_input_device *input_device __UNUSED__)
404 {
405    LOGFN(__FILE__, __LINE__, __FUNCTION__);
406 }
407
408 static void 
409 _ecore_wl_input_cb_data_offer(void *data, struct wl_data_device *data_device, unsigned int id)
410 {
411    LOGFN(__FILE__, __LINE__, __FUNCTION__);
412
413    _ecore_wl_dnd_add(data, data_device, id);
414 }
415
416 static void 
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)
418 {
419    LOGFN(__FILE__, __LINE__, __FUNCTION__);
420
421    _ecore_wl_dnd_enter(data, data_device, timestamp, surface, x, y, offer);
422 }
423
424 static void 
425 _ecore_wl_input_cb_data_leave(void *data, struct wl_data_device *data_device)
426 {
427    LOGFN(__FILE__, __LINE__, __FUNCTION__);
428
429    _ecore_wl_dnd_leave(data, data_device);
430 }
431
432 static void 
433 _ecore_wl_input_cb_data_motion(void *data, struct wl_data_device *data_device, unsigned int timestamp, int x, int y)
434 {
435    LOGFN(__FILE__, __LINE__, __FUNCTION__);
436
437    _ecore_wl_dnd_motion(data, data_device, timestamp, x, y);
438 }
439
440 static void 
441 _ecore_wl_input_cb_data_drop(void *data, struct wl_data_device *data_device)
442 {
443    LOGFN(__FILE__, __LINE__, __FUNCTION__);
444
445    _ecore_wl_dnd_drop(data, data_device);
446 }
447
448 static void 
449 _ecore_wl_input_cb_data_selection(void *data, struct wl_data_device *data_device, struct wl_data_offer *offer)
450 {
451    LOGFN(__FILE__, __LINE__, __FUNCTION__);
452
453    _ecore_wl_dnd_selection(data, data_device, offer);
454 }
455
456 static void 
457 _ecore_wl_input_keyboard_focus_remove(Ecore_Wl_Input *input, unsigned int timestamp)
458 {
459    Ecore_Wl_Window *win;
460
461    LOGFN(__FILE__, __LINE__, __FUNCTION__);
462
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;
467 }
468
469 static void 
470 _ecore_wl_input_pointer_focus_remove(Ecore_Wl_Input *input, unsigned int timestamp)
471 {
472    Ecore_Wl_Window *win;
473
474    LOGFN(__FILE__, __LINE__, __FUNCTION__);
475
476    if (!input->button)
477      _ecore_wl_input_mouse_out_send(input, timestamp);
478
479    if ((win = input->pointer_focus))
480      win->pointer_device = NULL;
481
482    input->pointer_focus = NULL;
483 }
484
485 static void 
486 _ecore_wl_input_mouse_move_send(Ecore_Wl_Input *input, unsigned int timestamp)
487 {
488    Ecore_Event_Mouse_Move *ev;
489 //   Ecore_Event *event;
490
491    LOGFN(__FILE__, __LINE__, __FUNCTION__);
492
493    if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Move)))) return;
494
495    ev->timestamp = timestamp;
496    ev->x = input->sx;
497    ev->y = input->sy;
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;
509
510    if (input->grab)
511      {
512         ev->window = input->grab->id;
513         ev->event_window = input->grab->id;
514      }
515    else if (input->pointer_focus) 
516      {
517         ev->window = input->pointer_focus->id;
518         ev->event_window = input->pointer_focus->id;
519      }
520
521    ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
522 }
523
524 static void 
525 _ecore_wl_input_mouse_in_send(Ecore_Wl_Input *input, unsigned int timestamp)
526 {
527    Ecore_Wl_Event_Mouse_In *ev;
528
529    LOGFN(__FILE__, __LINE__, __FUNCTION__);
530
531    if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Mouse_In)))) return;
532
533    ev->x = input->sx;
534    ev->y = input->sy;
535    ev->root.x = input->sx;
536    ev->root.y = input->sy;
537    ev->modifiers = input->modifiers;
538    ev->timestamp = timestamp;
539
540    if (input->pointer_focus)
541      {
542         ev->win = input->pointer_focus->id;
543         ev->event_win = input->pointer_focus->id;
544      }
545
546    ecore_event_add(ECORE_WL_EVENT_MOUSE_IN, ev, NULL, NULL);
547 }
548
549 static void 
550 _ecore_wl_input_mouse_out_send(Ecore_Wl_Input *input, unsigned int timestamp)
551 {
552    Ecore_Wl_Event_Mouse_Out *ev;
553
554    LOGFN(__FILE__, __LINE__, __FUNCTION__);
555
556    if (!(ev = calloc(1, sizeof(Ecore_Wl_Event_Mouse_Out)))) return;
557
558    ev->x = input->sx;
559    ev->y = input->sy;
560    ev->root.x = input->sx;
561    ev->root.y = input->sy;
562    ev->modifiers = input->modifiers;
563    ev->timestamp = timestamp;
564
565    if (input->pointer_focus)
566      {
567         ev->win = input->pointer_focus->id;
568         ev->event_win = input->pointer_focus->id;
569      }
570
571    ecore_event_add(ECORE_WL_EVENT_MOUSE_OUT, ev, NULL, NULL);
572 }
573
574 static void 
575 _ecore_wl_input_focus_in_send(Ecore_Wl_Input *input, unsigned int timestamp)
576 {
577    Ecore_Wl_Event_Focus_In *ev;
578
579    LOGFN(__FILE__, __LINE__, __FUNCTION__);
580
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);
586 }
587
588 static void 
589 _ecore_wl_input_focus_out_send(Ecore_Wl_Input *input, unsigned int timestamp)
590 {
591    Ecore_Wl_Event_Focus_Out *ev;
592
593    LOGFN(__FILE__, __LINE__, __FUNCTION__);
594
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);
600 }
601
602 static void 
603 _ecore_wl_input_mouse_down_send(Ecore_Wl_Input *input, unsigned int timestamp)
604 {
605    Ecore_Event_Mouse_Button *ev;
606
607    LOGFN(__FILE__, __LINE__, __FUNCTION__);
608
609    if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Button)))) return;
610
611    if (input->button == BTN_LEFT)
612      ev->buttons = 1;
613    else if (input->button == BTN_MIDDLE)
614      ev->buttons = 2;
615    else if (input->button == BTN_RIGHT)
616      ev->buttons = 3;
617    else
618      ev->buttons = input->button;
619
620    ev->timestamp = timestamp;
621    ev->x = input->sx;
622    ev->y = input->sy;
623    ev->root.x = input->sx;
624    ev->root.y = input->sy;
625    ev->modifiers = input->modifiers;
626
627    /* FIXME: Need to get these from wayland somehow */
628    ev->double_click = 0;
629    ev->triple_click = 0;
630
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;
639
640    if (input->pointer_focus)
641      {
642         ev->window = input->pointer_focus->id;
643         ev->event_window = input->pointer_focus->id;
644      }
645
646    ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
647 }
648
649 static void 
650 _ecore_wl_input_mouse_up_send(Ecore_Wl_Input *input, unsigned int timestamp)
651 {
652    Ecore_Event_Mouse_Button *ev;
653
654    LOGFN(__FILE__, __LINE__, __FUNCTION__);
655
656    if (!(ev = malloc(sizeof(Ecore_Event_Mouse_Button)))) return;
657
658    if (input->button == BTN_LEFT)
659      ev->buttons = 1;
660    else if (input->button == BTN_MIDDLE)
661      ev->buttons = 2;
662    else if (input->button == BTN_RIGHT)
663      ev->buttons = 3;
664    else
665      ev->buttons = input->button;
666
667    ev->timestamp = timestamp;
668    ev->x = input->sx;
669    ev->y = input->sy;
670    ev->root.x = input->sx;
671    ev->root.y = input->sy;
672    ev->modifiers = input->modifiers;
673
674    /* FIXME: Need to get these from wayland somehow */
675    ev->double_click = 0;
676    ev->triple_click = 0;
677
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;
686
687    if (input->pointer_focus)
688      {
689         ev->window = input->pointer_focus->id;
690         ev->event_window = input->pointer_focus->id;
691      }
692
693    ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
694 }