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