aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_input_evas/ecore_input_evas.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/lib/ecore_input_evas/ecore_input_evas.c')
-rw-r--r--libraries/ecore/src/lib/ecore_input_evas/ecore_input_evas.c412
1 files changed, 412 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_input_evas/ecore_input_evas.c b/libraries/ecore/src/lib/ecore_input_evas/ecore_input_evas.c
new file mode 100644
index 0000000..0cfe20a
--- /dev/null
+++ b/libraries/ecore/src/lib/ecore_input_evas/ecore_input_evas.c
@@ -0,0 +1,412 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <string.h>
6
7#include "Ecore.h"
8#include "Ecore_Input.h"
9
10#include "Ecore_Input_Evas.h"
11#include "ecore_input_evas_private.h"
12
13int _ecore_input_evas_log_dom = -1;
14
15typedef struct _Ecore_Input_Window Ecore_Input_Window;
16struct _Ecore_Input_Window
17{
18 Evas *evas;
19 void *window;
20 Ecore_Event_Mouse_Move_Cb move_mouse;
21 Ecore_Event_Multi_Move_Cb move_multi;
22 Ecore_Event_Multi_Down_Cb down_multi;
23 Ecore_Event_Multi_Up_Cb up_multi;
24 int ignore_event;
25};
26
27static int _ecore_event_evas_init_count = 0;
28static Ecore_Event_Handler *ecore_event_evas_handlers[8];
29static Eina_Hash *_window_hash = NULL;
30
31EAPI void
32ecore_event_evas_modifier_lock_update(Evas *e, unsigned int modifiers)
33{
34 if (modifiers & ECORE_EVENT_MODIFIER_SHIFT)
35 evas_key_modifier_on(e, "Shift");
36 else evas_key_modifier_off(e, "Shift");
37
38 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
39 evas_key_modifier_on(e, "Control");
40 else evas_key_modifier_off(e, "Control");
41
42 if (modifiers & ECORE_EVENT_MODIFIER_ALT)
43 evas_key_modifier_on(e, "Alt");
44 else evas_key_modifier_off(e, "Alt");
45
46 if (modifiers & ECORE_EVENT_MODIFIER_WIN)
47 {
48 evas_key_modifier_on(e, "Super");
49 evas_key_modifier_on(e, "Hyper");
50 }
51 else
52 {
53 evas_key_modifier_off(e, "Super");
54 evas_key_modifier_off(e, "Hyper");
55 }
56
57 if (modifiers & ECORE_EVENT_LOCK_SCROLL)
58 evas_key_lock_on(e, "Scroll_Lock");
59 else evas_key_lock_off(e, "Scroll_Lock");
60
61 if (modifiers & ECORE_EVENT_LOCK_NUM)
62 evas_key_lock_on(e, "Num_Lock");
63 else evas_key_lock_off(e, "Num_Lock");
64
65 if (modifiers & ECORE_EVENT_LOCK_CAPS)
66 evas_key_lock_on(e, "Caps_Lock");
67 else evas_key_lock_off(e, "Caps_Lock");
68
69 if (modifiers & ECORE_EVENT_LOCK_SHIFT)
70 evas_key_lock_on(e, "Shift_Lock");
71 else evas_key_lock_off(e, "Shift_Lock");
72}
73
74EAPI void
75ecore_event_window_register(Ecore_Window id, void *window, Evas *evas,
76 Ecore_Event_Mouse_Move_Cb move_mouse,
77 Ecore_Event_Multi_Move_Cb move_multi,
78 Ecore_Event_Multi_Down_Cb down_multi,
79 Ecore_Event_Multi_Up_Cb up_multi)
80{
81 Ecore_Input_Window *w;
82
83 w = calloc(1, sizeof(Ecore_Input_Window));
84 if (!w) return;
85
86 w->evas = evas;
87 w->window = window;
88 w->move_mouse = move_mouse;
89 w->move_multi = move_multi;
90 w->down_multi = down_multi;
91 w->up_multi = up_multi;
92 w->ignore_event = 0;
93
94 eina_hash_add(_window_hash, &id, w);
95
96 evas_key_modifier_add(evas, "Shift");
97 evas_key_modifier_add(evas, "Control");
98 evas_key_modifier_add(evas, "Alt");
99 evas_key_modifier_add(evas, "Meta");
100 evas_key_modifier_add(evas, "Hyper");
101 evas_key_modifier_add(evas, "Super");
102 evas_key_lock_add(evas, "Caps_Lock");
103 evas_key_lock_add(evas, "Num_Lock");
104 evas_key_lock_add(evas, "Scroll_Lock");
105}
106
107EAPI void
108ecore_event_window_unregister(Ecore_Window id)
109{
110 eina_hash_del(_window_hash, &id, NULL);
111}
112
113EAPI void *
114ecore_event_window_match(Ecore_Window id)
115{
116 Ecore_Input_Window *lookup;
117
118 lookup = eina_hash_find(_window_hash, &id);
119 if (lookup) return lookup->window;
120 return NULL;
121}
122
123EAPI void
124ecore_event_window_ignore_events(Ecore_Window id, int ignore_event)
125{
126 Ecore_Input_Window *lookup;
127
128 lookup = eina_hash_find(_window_hash, &id);
129 if (!lookup) return;
130 lookup->ignore_event = ignore_event;
131}
132
133static Ecore_Input_Window*
134_ecore_event_window_match(Ecore_Window id)
135{
136 Ecore_Input_Window *lookup;
137
138 lookup = eina_hash_find(_window_hash, &id);
139 if (!lookup) return NULL;
140 if (lookup->ignore_event) return NULL; /* Pass on event. */
141 return lookup;
142}
143
144static Eina_Bool
145_ecore_event_evas_key(Ecore_Event_Key *e, Ecore_Event_Press press)
146{
147 Ecore_Input_Window *lookup;
148
149 lookup = _ecore_event_window_match(e->event_window);
150 if (!lookup) return ECORE_CALLBACK_RENEW;
151 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
152 if (press == ECORE_DOWN)
153 evas_event_feed_key_down(lookup->evas, e->keyname, e->key, e->string, e->compose, e->timestamp, NULL);
154 else
155 evas_event_feed_key_up(lookup->evas, e->keyname, e->key, e->string, e->compose, e->timestamp, NULL);
156 return ECORE_CALLBACK_RENEW;
157}
158
159static Eina_Bool
160_ecore_event_evas_mouse_button(Ecore_Event_Mouse_Button *e, Ecore_Event_Press press)
161{
162 Ecore_Input_Window *lookup;
163 Evas_Button_Flags flags = EVAS_BUTTON_NONE;
164
165 lookup = _ecore_event_window_match(e->event_window);
166 if (!lookup) return ECORE_CALLBACK_RENEW;
167 if (e->double_click) flags |= EVAS_BUTTON_DOUBLE_CLICK;
168 if (e->triple_click) flags |= EVAS_BUTTON_TRIPLE_CLICK;
169 if (e->multi.device == 0)
170 {
171 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
172 if (press == ECORE_DOWN)
173 evas_event_feed_mouse_down(lookup->evas, e->buttons, flags,
174 e->timestamp, NULL);
175 else
176 evas_event_feed_mouse_up(lookup->evas, e->buttons, flags,
177 e->timestamp, NULL);
178 }
179 else
180 {
181 if (press == ECORE_DOWN)
182 {
183 if (lookup->down_multi)
184 lookup->down_multi(lookup->window, e->multi.device,
185 e->x, e->y, e->multi.radius,
186 e->multi.radius_x, e->multi.radius_y,
187 e->multi.pressure, e->multi.angle,
188 e->multi.x, e->multi.y, flags,
189 e->timestamp);
190 else
191 evas_event_feed_multi_down(lookup->evas, e->multi.device,
192 e->x, e->y, e->multi.radius,
193 e->multi.radius_x, e->multi.radius_y,
194 e->multi.pressure, e->multi.angle,
195 e->multi.x, e->multi.y, flags,
196 e->timestamp, NULL);
197 }
198 else
199 {
200 if (lookup->up_multi)
201 lookup->up_multi(lookup->window, e->multi.device,
202 e->x, e->y, e->multi.radius,
203 e->multi.radius_x, e->multi.radius_y,
204 e->multi.pressure, e->multi.angle,
205 e->multi.x, e->multi.y, flags,
206 e->timestamp);
207 else
208 evas_event_feed_multi_up(lookup->evas, e->multi.device,
209 e->x, e->y, e->multi.radius,
210 e->multi.radius_x, e->multi.radius_y,
211 e->multi.pressure, e->multi.angle,
212 e->multi.x, e->multi.y, flags,
213 e->timestamp, NULL);
214 }
215 }
216 return ECORE_CALLBACK_RENEW;
217}
218
219EAPI Eina_Bool
220ecore_event_evas_mouse_move(void *data __UNUSED__, int type __UNUSED__, void *event)
221{
222 Ecore_Event_Mouse_Move *e;
223 Ecore_Input_Window *lookup;
224
225 e = event;
226 lookup = _ecore_event_window_match(e->event_window);
227 if (!lookup) return ECORE_CALLBACK_RENEW;
228 if (e->multi.device == 0)
229 {
230 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
231 if (lookup->move_mouse)
232 lookup->move_mouse(lookup->window, e->x, e->y, e->timestamp);
233 else
234 evas_event_feed_mouse_move(lookup->evas, e->x, e->y, e->timestamp,
235 NULL);
236 }
237 else
238 {
239 if (lookup->move_multi)
240 lookup->move_multi(lookup->window, e->multi.device,
241 e->x, e->y, e->multi.radius,
242 e->multi.radius_x, e->multi.radius_y,
243 e->multi.pressure, e->multi.angle,
244 e->multi.x, e->multi.y, e->timestamp);
245 else
246 evas_event_feed_multi_move(lookup->evas, e->multi.device,
247 e->x, e->y, e->multi.radius,
248 e->multi.radius_x, e->multi.radius_y,
249 e->multi.pressure, e->multi.angle,
250 e->multi.x, e->multi.y, e->timestamp,
251 NULL);
252 }
253 return ECORE_CALLBACK_RENEW;
254}
255
256EAPI Eina_Bool
257ecore_event_evas_mouse_button_down(void *data __UNUSED__, int type __UNUSED__, void *event)
258{
259 return _ecore_event_evas_mouse_button((Ecore_Event_Mouse_Button *)event, ECORE_DOWN);
260}
261
262EAPI Eina_Bool
263ecore_event_evas_mouse_button_up(void *data __UNUSED__, int type __UNUSED__, void *event)
264{
265 return _ecore_event_evas_mouse_button((Ecore_Event_Mouse_Button *)event, ECORE_UP);
266}
267
268static Eina_Bool
269_ecore_event_evas_mouse_io(Ecore_Event_Mouse_IO *e, Ecore_Event_IO io)
270{
271 Ecore_Input_Window *lookup;
272
273 lookup = _ecore_event_window_match(e->event_window);
274 if (!lookup) return ECORE_CALLBACK_RENEW;
275 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
276 switch (io)
277 {
278 case ECORE_IN:
279 evas_event_feed_mouse_in(lookup->evas, e->timestamp, NULL);
280 break;
281 case ECORE_OUT:
282 evas_event_feed_mouse_out(lookup->evas, e->timestamp, NULL);
283 break;
284 default:
285 break;
286 }
287
288 lookup->move_mouse(lookup->window, e->x, e->y, e->timestamp);
289 return ECORE_CALLBACK_RENEW;
290}
291
292EAPI Eina_Bool
293ecore_event_evas_key_down(void *data __UNUSED__, int type __UNUSED__, void *event)
294{
295 return _ecore_event_evas_key((Ecore_Event_Key *)event, ECORE_DOWN);
296}
297
298EAPI Eina_Bool
299ecore_event_evas_key_up(void *data __UNUSED__, int type __UNUSED__, void *event)
300{
301 return _ecore_event_evas_key((Ecore_Event_Key *)event, ECORE_UP);
302}
303
304EAPI Eina_Bool
305ecore_event_evas_mouse_wheel(void *data __UNUSED__, int type __UNUSED__, void *event)
306{
307 Ecore_Event_Mouse_Wheel *e;
308 Ecore_Input_Window *lookup;
309
310 e = event;
311 lookup = _ecore_event_window_match(e->event_window);
312 if (!lookup) return ECORE_CALLBACK_RENEW;
313 ecore_event_evas_modifier_lock_update(lookup->evas, e->modifiers);
314 evas_event_feed_mouse_wheel(lookup->evas, e->direction, e->z, e->timestamp, NULL);
315 return ECORE_CALLBACK_RENEW;
316}
317
318EAPI Eina_Bool
319ecore_event_evas_mouse_in(void *data __UNUSED__, int type __UNUSED__, void *event)
320{
321 return _ecore_event_evas_mouse_io((Ecore_Event_Mouse_IO *)event, ECORE_IN);
322}
323
324EAPI Eina_Bool
325ecore_event_evas_mouse_out(void *data __UNUSED__, int type __UNUSED__, void *event)
326{
327 return _ecore_event_evas_mouse_io((Ecore_Event_Mouse_IO *)event, ECORE_OUT);
328}
329
330EAPI int
331ecore_event_evas_init(void)
332{
333 if (++_ecore_event_evas_init_count != 1)
334 return _ecore_event_evas_init_count;
335
336 _ecore_input_evas_log_dom = eina_log_domain_register
337 ("ecore_input_evas", ECORE_INPUT_EVAS_DEFAULT_LOG_COLOR);
338 if (_ecore_input_evas_log_dom < 0)
339 {
340 EINA_LOG_ERR("Impossible to create a log domain for the ecore input evas_module.");
341 return --_ecore_event_evas_init_count;
342 }
343
344 if (!ecore_init())
345 {
346 return --_ecore_event_evas_init_count;
347 }
348
349 if (!ecore_event_init())
350 {
351 goto shutdown_ecore;
352 }
353
354 ecore_event_evas_handlers[0] = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
355 ecore_event_evas_key_down,
356 NULL);
357 ecore_event_evas_handlers[1] = ecore_event_handler_add(ECORE_EVENT_KEY_UP,
358 ecore_event_evas_key_up,
359 NULL);
360 ecore_event_evas_handlers[2] = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
361 ecore_event_evas_mouse_button_down,
362 NULL);
363 ecore_event_evas_handlers[3] = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
364 ecore_event_evas_mouse_button_up,
365 NULL);
366 ecore_event_evas_handlers[4] = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE,
367 ecore_event_evas_mouse_move,
368 NULL);
369 ecore_event_evas_handlers[5] = ecore_event_handler_add(ECORE_EVENT_MOUSE_WHEEL,
370 ecore_event_evas_mouse_wheel,
371 NULL);
372 ecore_event_evas_handlers[6] = ecore_event_handler_add(ECORE_EVENT_MOUSE_IN,
373 ecore_event_evas_mouse_in,
374 NULL);
375 ecore_event_evas_handlers[7] = ecore_event_handler_add(ECORE_EVENT_MOUSE_OUT,
376 ecore_event_evas_mouse_out,
377 NULL);
378
379 _window_hash = eina_hash_pointer_new(free);
380
381 return _ecore_event_evas_init_count;
382
383 shutdown_ecore:
384 ecore_shutdown();
385
386 return --_ecore_event_evas_init_count;
387}
388
389EAPI int
390ecore_event_evas_shutdown(void)
391{
392 size_t i;
393
394 if (--_ecore_event_evas_init_count != 0)
395 return _ecore_event_evas_init_count;
396
397 eina_hash_free(_window_hash);
398 _window_hash = NULL;
399 for (i = 0; i < sizeof(ecore_event_evas_handlers) / sizeof(Ecore_Event_Handler *); i++)
400 {
401 ecore_event_handler_del(ecore_event_evas_handlers[i]);
402 ecore_event_evas_handlers[i] = NULL;
403 }
404
405 ecore_event_shutdown();
406 ecore_shutdown();
407
408 eina_log_domain_unregister(_ecore_input_evas_log_dom);
409 _ecore_input_evas_log_dom = -1;
410
411 return _ecore_event_evas_init_count;
412}