8 #include "Ecore_Input.h"
10 #include "Ecore_Input_Evas.h"
11 #include "ecore_input_evas_private.h"
13 int _ecore_input_evas_log_dom = -1;
15 typedef struct _Ecore_Input_Window Ecore_Input_Window;
16 struct _Ecore_Input_Window
20 Ecore_Event_Mouse_Move_Cb move_mouse;
24 static int _ecore_event_evas_init_count = 0;
25 static Ecore_Event_Handler *ecore_event_evas_handlers[8];
26 static Eina_Hash *_window_hash = NULL;
29 ecore_event_evas_modifier_lock_update(Evas *e, unsigned int modifiers)
31 if (modifiers & ECORE_EVENT_MODIFIER_SHIFT)
32 evas_key_modifier_on(e, "Shift");
33 else evas_key_modifier_off(e, "Shift");
35 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
36 evas_key_modifier_on(e, "Control");
37 else evas_key_modifier_off(e, "Control");
39 if (modifiers & ECORE_EVENT_MODIFIER_ALT)
40 evas_key_modifier_on(e, "Alt");
41 else evas_key_modifier_off(e, "Alt");
43 if (modifiers & ECORE_EVENT_MODIFIER_WIN)
45 evas_key_modifier_on(e, "Super");
46 evas_key_modifier_on(e, "Hyper");
50 evas_key_modifier_off(e, "Super");
51 evas_key_modifier_off(e, "Hyper");
54 if (modifiers & ECORE_EVENT_LOCK_SCROLL)
55 evas_key_lock_on(e, "Scroll_Lock");
56 else evas_key_lock_off(e, "Scroll_Lock");
58 if (modifiers & ECORE_EVENT_LOCK_NUM)
59 evas_key_lock_on(e, "Num_Lock");
60 else evas_key_lock_off(e, "Num_Lock");
62 if (modifiers & ECORE_EVENT_LOCK_CAPS)
63 evas_key_lock_on(e, "Caps_Lock");
64 else evas_key_lock_off(e, "Caps_Lock");
68 ecore_event_window_register(Ecore_Window id, void *window, Evas *evas, Ecore_Event_Mouse_Move_Cb move_mouse)
70 Ecore_Input_Window *w;
72 w = calloc(1, sizeof(Ecore_Input_Window));
77 w->move_mouse = move_mouse;
80 eina_hash_add(_window_hash, &id, w);
82 evas_key_modifier_add(evas, "Shift");
83 evas_key_modifier_add(evas, "Control");
84 evas_key_modifier_add(evas, "Alt");
85 evas_key_modifier_add(evas, "Meta");
86 evas_key_modifier_add(evas, "Hyper");
87 evas_key_modifier_add(evas, "Super");
88 evas_key_lock_add(evas, "Caps_Lock");
89 evas_key_lock_add(evas, "Num_Lock");
90 evas_key_lock_add(evas, "Scroll_Lock");
94 ecore_event_window_unregister(Ecore_Window id)
96 eina_hash_del(_window_hash, &id, NULL);
100 ecore_event_window_match(Ecore_Window id)
102 Ecore_Input_Window *lookup;
104 lookup = eina_hash_find(_window_hash, &id);
105 if (lookup) return lookup->window;
110 ecore_event_window_ignore_events(Ecore_Window id, int ignore_event)
112 Ecore_Input_Window *lookup;
114 lookup = eina_hash_find(_window_hash, &id);
116 lookup->ignore_event = ignore_event;
119 static Ecore_Input_Window*
120 _ecore_event_window_match(Ecore_Window id)
122 Ecore_Input_Window *lookup;
124 lookup = eina_hash_find(_window_hash, &id);
125 if (!lookup) return NULL;
126 if (lookup->ignore_event) return NULL; /* Pass on event. */
131 _ecore_event_evas_key(Ecore_Event_Key *e, Ecore_Event_Press press)
133 Ecore_Input_Window *lookup;
135 lookup = _ecore_event_window_match(e->event_window);
136 if (!lookup) return ECORE_CALLBACK_RENEW;
137 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
138 if (press == ECORE_DOWN)
139 evas_event_feed_key_down(lookup->evas, e->keyname, e->key, e->string, e->compose, e->timestamp, NULL);
141 evas_event_feed_key_up(lookup->evas, e->keyname, e->key, e->string, e->compose, e->timestamp, NULL);
142 return ECORE_CALLBACK_RENEW;
146 _ecore_event_evas_mouse_button(Ecore_Event_Mouse_Button *e, Ecore_Event_Press press)
148 Ecore_Input_Window *lookup;
149 Evas_Button_Flags flags = EVAS_BUTTON_NONE;
151 lookup = _ecore_event_window_match(e->event_window);
152 if (!lookup) return ECORE_CALLBACK_RENEW;
153 if (e->double_click) flags |= EVAS_BUTTON_DOUBLE_CLICK;
154 if (e->triple_click) flags |= EVAS_BUTTON_TRIPLE_CLICK;
155 if (e->multi.device == 0)
157 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
158 if (press == ECORE_DOWN)
159 evas_event_feed_mouse_down(lookup->evas, e->buttons, flags, e->timestamp, NULL);
161 evas_event_feed_mouse_up(lookup->evas, e->buttons, flags, e->timestamp, NULL);
165 if (press == ECORE_DOWN)
166 evas_event_feed_multi_down(lookup->evas, e->multi.device, e->x, e->y, e->multi.radius, e->multi.radius_x, e->multi.radius_y, e->multi.pressure, e->multi.angle, e->multi.x, e->multi.y, flags, e->timestamp, NULL);
168 evas_event_feed_multi_up(lookup->evas, e->multi.device, e->x, e->y, e->multi.radius, e->multi.radius_x, e->multi.radius_y, e->multi.pressure, e->multi.angle, e->multi.x, e->multi.y, flags, e->timestamp, NULL);
170 return ECORE_CALLBACK_RENEW;
174 ecore_event_evas_mouse_move(void *data __UNUSED__, int type __UNUSED__, void *event)
176 Ecore_Event_Mouse_Move *e;
177 Ecore_Input_Window *lookup;
180 lookup = _ecore_event_window_match(e->event_window);
181 if (!lookup) return ECORE_CALLBACK_RENEW;
182 if (e->multi.device == 0)
184 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
185 lookup->move_mouse(lookup->window, e->x, e->y, e->timestamp);
189 evas_event_feed_multi_move(lookup->evas, e->multi.device, e->x, e->y, e->multi.radius, e->multi.radius_x, e->multi.radius_y, e->multi.pressure, e->multi.angle, e->multi.x, e->multi.y, e->timestamp, NULL);
191 return ECORE_CALLBACK_RENEW;
195 ecore_event_evas_mouse_button_down(void *data __UNUSED__, int type __UNUSED__, void *event)
197 return _ecore_event_evas_mouse_button((Ecore_Event_Mouse_Button *)event, ECORE_DOWN);
201 ecore_event_evas_mouse_button_up(void *data __UNUSED__, int type __UNUSED__, void *event)
203 return _ecore_event_evas_mouse_button((Ecore_Event_Mouse_Button *)event, ECORE_UP);
207 _ecore_event_evas_mouse_io(Ecore_Event_Mouse_IO *e, Ecore_Event_IO io)
209 Ecore_Input_Window *lookup;
211 lookup = _ecore_event_window_match(e->event_window);
212 if (!lookup) return ECORE_CALLBACK_RENEW;
213 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
217 evas_event_feed_mouse_in(lookup->evas, e->timestamp, NULL);
220 evas_event_feed_mouse_out(lookup->evas, e->timestamp, NULL);
226 lookup->move_mouse(lookup->window, e->x, e->y, e->timestamp);
227 return ECORE_CALLBACK_RENEW;
231 ecore_event_evas_key_down(void *data __UNUSED__, int type __UNUSED__, void *event)
233 return _ecore_event_evas_key((Ecore_Event_Key *)event, ECORE_DOWN);
237 ecore_event_evas_key_up(void *data __UNUSED__, int type __UNUSED__, void *event)
239 return _ecore_event_evas_key((Ecore_Event_Key *)event, ECORE_UP);
243 ecore_event_evas_mouse_wheel(void *data __UNUSED__, int type __UNUSED__, void *event)
245 Ecore_Event_Mouse_Wheel *e;
246 Ecore_Input_Window *lookup;
249 lookup = _ecore_event_window_match(e->event_window);
250 if (!lookup) return ECORE_CALLBACK_RENEW;
251 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
252 evas_event_feed_mouse_wheel(lookup->evas, e->direction, e->z, e->timestamp, NULL);
253 return ECORE_CALLBACK_RENEW;
257 ecore_event_evas_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event)
259 return _ecore_event_evas_mouse_io((Ecore_Event_Mouse_IO *)event, ECORE_IN);
263 ecore_event_evas_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event)
265 return _ecore_event_evas_mouse_io((Ecore_Event_Mouse_IO *)event, ECORE_OUT);
269 ecore_event_evas_init(void)
271 if (++_ecore_event_evas_init_count != 1)
272 return _ecore_event_evas_init_count;
274 _ecore_input_evas_log_dom = eina_log_domain_register
275 ("ecore_input_evas", ECORE_INPUT_EVAS_DEFAULT_LOG_COLOR);
276 if (_ecore_input_evas_log_dom < 0)
278 EINA_LOG_ERR("Impossible to create a log domain for the ecore input evas_module.");
279 return --_ecore_event_evas_init_count;
284 return --_ecore_event_evas_init_count;
287 if (!ecore_event_init())
292 ecore_event_evas_handlers[0] = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
293 ecore_event_evas_key_down,
295 ecore_event_evas_handlers[1] = ecore_event_handler_add(ECORE_EVENT_KEY_UP,
296 ecore_event_evas_key_up,
298 ecore_event_evas_handlers[2] = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
299 ecore_event_evas_mouse_button_down,
301 ecore_event_evas_handlers[3] = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
302 ecore_event_evas_mouse_button_up,
304 ecore_event_evas_handlers[4] = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
305 ecore_event_evas_mouse_move,
307 ecore_event_evas_handlers[5] = ecore_event_handler_add(ECORE_EVENT_MOUSE_WHEEL,
308 ecore_event_evas_mouse_wheel,
310 ecore_event_evas_handlers[6] = ecore_event_handler_add(ECORE_EVENT_MOUSE_IN,
311 ecore_event_evas_mouse_in,
313 ecore_event_evas_handlers[7] = ecore_event_handler_add(ECORE_EVENT_MOUSE_OUT,
314 ecore_event_evas_mouse_out,
317 _window_hash = eina_hash_pointer_new(free);
319 return _ecore_event_evas_init_count;
324 return --_ecore_event_evas_init_count;
328 ecore_event_evas_shutdown(void)
332 if (--_ecore_event_evas_init_count != 0)
333 return _ecore_event_evas_init_count;
335 eina_hash_free(_window_hash);
337 for (i = 0; i < sizeof(ecore_event_evas_handlers) / sizeof(Ecore_Event_Handler *); i++)
339 ecore_event_handler_del(ecore_event_evas_handlers[i]);
340 ecore_event_evas_handlers[i] = NULL;
343 ecore_event_shutdown();
346 eina_log_domain_unregister(_ecore_input_evas_log_dom);
347 _ecore_input_evas_log_dom = -1;
349 return _ecore_event_evas_init_count;