From 52996b1cf446506ac73cb2c3e5477111395aee06 Mon Sep 17 00:00:00 2001 From: Chris Michael Date: Wed, 23 Sep 2015 11:07:00 -0400 Subject: [PATCH] ecore-wl2: Add functions to send mouse in/out events and call them during pointer enter/leave Signed-off-by: Chris Michael --- src/lib/ecore_wl2/ecore_wl2_input.c | 64 +++++++++++++++++++++++++++++++++-- src/lib/ecore_wl2/ecore_wl2_private.h | 4 +++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/src/lib/ecore_wl2/ecore_wl2_input.c b/src/lib/ecore_wl2/ecore_wl2_input.c index 8a612f3..45f2fd1 100644 --- a/src/lib/ecore_wl2/ecore_wl2_input.c +++ b/src/lib/ecore_wl2/ecore_wl2_input.c @@ -2,11 +2,59 @@ # include #endif +#ifdef __linux__ +# include +#else +# define BTN_LEFT 0x110 +# define BTN_RIGHT 0x111 +# define BTN_MIDDLE 0x112 +# define BTN_SIDE 0x113 +# define BTN_EXTRA 0x114 +# define BTN_FORWARD 0x115 +# define BTN_BACK 0x116 +#endif + #include #include #include "ecore_wl2_private.h" static void +_ecore_wl2_input_mouse_in_send(Ecore_Wl2_Input *input, Ecore_Wl2_Window *window) +{ + Ecore_Event_Mouse_IO *ev; + + ev = calloc(1, sizeof(Ecore_Event_Mouse_IO)); + if (!ev) return; + + ev->x = input->pointer.sx; + ev->y = input->pointer.sy; + ev->window = window; + ev->event_window = window; + ev->timestamp = input->timestamp; + ev->modifiers = input->keyboard.modifiers; + + ecore_event_add(ECORE_EVENT_MOUSE_IN, ev, NULL, NULL); +} + +static void +_ecore_wl2_input_mouse_out_send(Ecore_Wl2_Input *input, Ecore_Wl2_Window *window) +{ + Ecore_Event_Mouse_IO *ev; + + ev = calloc(1, sizeof(Ecore_Event_Mouse_IO)); + if (!ev) return; + + ev->x = input->pointer.sx; + ev->y = input->pointer.sy; + ev->window = window; + ev->event_window = window; + ev->timestamp = input->timestamp; + ev->modifiers = input->keyboard.modifiers; + + ecore_event_add(ECORE_EVENT_MOUSE_OUT, ev, NULL, NULL); +} + +static void _pointer_cb_enter(void *data, struct wl_pointer *pointer EINA_UNUSED, unsigned int serial, struct wl_surface *surface, wl_fixed_t sx, wl_fixed_t sy) { Ecore_Wl2_Input *input; @@ -18,6 +66,15 @@ _pointer_cb_enter(void *data, struct wl_pointer *pointer EINA_UNUSED, unsigned i /* trap for a surface that was just destroyed */ if (!surface) return; + if (!input->timestamp) + { + struct timeval tv; + + gettimeofday(&tv, NULL); + input->timestamp = (tv.tv_sec * 1000 + tv.tv_usec / 1000); + } + + input->display->serial = serial; input->pointer.enter_serial = serial; input->pointer.sx = wl_fixed_to_double(sx); input->pointer.sy = wl_fixed_to_double(sy); @@ -28,11 +85,11 @@ _pointer_cb_enter(void *data, struct wl_pointer *pointer EINA_UNUSED, unsigned i input->focus.pointer = window; - /* TODO: send mouse in event */ + _ecore_wl2_input_mouse_in_send(input, window); } static void -_pointer_cb_leave(void *data, struct wl_pointer *pointer EINA_UNUSED, unsigned int serial EINA_UNUSED, struct wl_surface *surface) +_pointer_cb_leave(void *data, struct wl_pointer *pointer EINA_UNUSED, unsigned int serial, struct wl_surface *surface) { Ecore_Wl2_Input *input; Ecore_Wl2_Window *window; @@ -40,6 +97,7 @@ _pointer_cb_leave(void *data, struct wl_pointer *pointer EINA_UNUSED, unsigned i input = data; if (!input) return; + input->display->serial = serial; input->focus.pointer = NULL; /* trap for a surface that was just destroyed */ @@ -49,7 +107,7 @@ _pointer_cb_leave(void *data, struct wl_pointer *pointer EINA_UNUSED, unsigned i window = _ecore_wl2_display_window_surface_find(input->display, surface); if (!window) return; - /* TODO: send mouse out event */ + _ecore_wl2_input_mouse_out_send(input, window); } static void diff --git a/src/lib/ecore_wl2/ecore_wl2_private.h b/src/lib/ecore_wl2/ecore_wl2_private.h index bace079..8cf8d2d 100644 --- a/src/lib/ecore_wl2/ecore_wl2_private.h +++ b/src/lib/ecore_wl2/ecore_wl2_private.h @@ -54,6 +54,8 @@ struct _Ecore_Wl2_Display struct xdg_shell *xdg_shell; } wl; + uint32_t serial; + struct xkb_context *xkb_context; Ecore_Fd_Handler *fd_hdl; @@ -113,6 +115,8 @@ struct _Ecore_Wl2_Input Ecore_Wl2_Display *display; + unsigned int timestamp; + struct { struct wl_seat *seat; -- 2.7.4