diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/ecore/src/lib/ecore_fb/ecore_fb_li.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to '')
-rw-r--r-- | libraries/ecore/src/lib/ecore_fb/ecore_fb_li.c | 706 |
1 files changed, 706 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_fb/ecore_fb_li.c b/libraries/ecore/src/lib/ecore_fb/ecore_fb_li.c new file mode 100644 index 0000000..4a196dd --- /dev/null +++ b/libraries/ecore/src/lib/ecore_fb/ecore_fb_li.c | |||
@@ -0,0 +1,706 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include "Ecore_Fb.h" | ||
6 | #include "ecore_fb_private.h" | ||
7 | |||
8 | #define CLICK_THRESHOLD_DEFAULT 0.25 | ||
9 | |||
10 | static Eina_List *_ecore_fb_li_devices = NULL; | ||
11 | |||
12 | static const char *_ecore_fb_li_kbd_syms[128 * 6] = | ||
13 | { | ||
14 | #include "ecore_fb_keytable.h" | ||
15 | }; | ||
16 | |||
17 | /* Initial Copyright (C) Brad Hards (1999-2002), | ||
18 | * this function is used to tell if "bit" is set in "array" | ||
19 | * it selects a byte from the array, and does a boolean AND | ||
20 | * operation with a byte that only has the relevant bit set. | ||
21 | * eg. to check for the 12th bit, we do (array[1] & 1<<4). | ||
22 | * Moved to static inline in order to force compiler to otimized | ||
23 | * the unsued part away or force a link error if long has an unexpected | ||
24 | * size. | ||
25 | * - bigeasy | ||
26 | */ | ||
27 | extern int long_has_neither_32_nor_64_bits(void); | ||
28 | static inline int | ||
29 | test_bit(int bit, unsigned long *array) | ||
30 | { | ||
31 | if (sizeof(long) == 4) | ||
32 | return array[bit / 32] & (1 << (bit % 32)); | ||
33 | else if (sizeof(long) == 8) | ||
34 | return array[bit / 64] & (1 << (bit % 64)); | ||
35 | else long_has_neither_32_nor_64_bits(); | ||
36 | } | ||
37 | |||
38 | static void | ||
39 | _ecore_fb_li_device_event_key(Ecore_Fb_Input_Device *dev, struct input_event *iev) | ||
40 | { | ||
41 | if (!dev->listen) return; | ||
42 | |||
43 | /* check for basic keyboard keys */ | ||
44 | if ((iev->code >= KEY_ESC) && (iev->code <= KEY_COMPOSE)) | ||
45 | { | ||
46 | int offset = 0; | ||
47 | const char *keyname = _ecore_fb_li_kbd_syms[iev->code * 6]; | ||
48 | /* check the key table */ | ||
49 | if (iev->value) | ||
50 | { | ||
51 | /* its a repeated key, dont increment */ | ||
52 | if (iev->value == 2) | ||
53 | return; | ||
54 | if (!strcmp(keyname, "Control_L")) | ||
55 | dev->keyboard.ctrl++; | ||
56 | else if (!strcmp(keyname, "Control_R")) | ||
57 | dev->keyboard.ctrl++; | ||
58 | else if (!strcmp(keyname, "Alt_L")) | ||
59 | dev->keyboard.alt++; | ||
60 | else if (!strcmp(keyname, "Alt_R")) | ||
61 | dev->keyboard.alt++; | ||
62 | else if (!strcmp(keyname, "Shift_L")) | ||
63 | dev->keyboard.shift++; | ||
64 | else if (!strcmp(keyname, "Shift_R")) | ||
65 | dev->keyboard.shift++; | ||
66 | else if (!strcmp(keyname, "Caps_Lock")) | ||
67 | dev->keyboard.lock = !dev->keyboard.lock; | ||
68 | if (dev->keyboard.ctrl > 2) dev->keyboard.ctrl = 2; | ||
69 | if (dev->keyboard.alt > 2) dev->keyboard.alt = 2; | ||
70 | if (dev->keyboard.shift > 2) dev->keyboard.shift = 2; | ||
71 | if (dev->keyboard.lock > 1) dev->keyboard.lock = 1; | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | if (!strcmp(keyname, "Control_L")) | ||
76 | dev->keyboard.ctrl--; | ||
77 | else if (!strcmp(keyname, "Control_R")) | ||
78 | dev->keyboard.ctrl--; | ||
79 | else if (!strcmp(keyname, "Alt_L")) | ||
80 | dev->keyboard.alt--; | ||
81 | else if (!strcmp(keyname, "Alt_R")) | ||
82 | dev->keyboard.alt--; | ||
83 | else if (!strcmp(keyname, "Shift_L")) | ||
84 | dev->keyboard.shift--; | ||
85 | else if (!strcmp(keyname, "Shift_R")) | ||
86 | dev->keyboard.shift--; | ||
87 | if (dev->keyboard.ctrl < 0) dev->keyboard.ctrl = 0; | ||
88 | if (dev->keyboard.alt < 0) dev->keyboard.alt = 0; | ||
89 | if (dev->keyboard.shift < 0) dev->keyboard.shift = 0; | ||
90 | if (dev->keyboard.lock < 0) dev->keyboard.lock = 0; | ||
91 | } | ||
92 | |||
93 | /* sending ecore_input_evas events */ | ||
94 | Ecore_Event_Key *e; | ||
95 | |||
96 | if (dev->keyboard.shift) offset = 1; | ||
97 | else if (dev->keyboard.lock) offset = 2; | ||
98 | |||
99 | const char *key = _ecore_fb_li_kbd_syms[(iev->code * 6) + offset]; | ||
100 | const char *compose = _ecore_fb_li_kbd_syms[(iev->code * 6) + 3 + offset]; | ||
101 | |||
102 | e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + | ||
103 | strlen(keyname) + (compose ? strlen(compose) : 0) + 3); | ||
104 | e->keyname = (char *)(e + 1); | ||
105 | e->key = e->keyname + strlen(keyname) + 1; | ||
106 | e->compose = (compose) ? e->key + strlen(key) + 1 : NULL; | ||
107 | e->string = e->compose; | ||
108 | |||
109 | strcpy((char *)e->keyname, keyname); | ||
110 | strcpy((char *)e->key, key); | ||
111 | if (compose) | ||
112 | strcpy((char *)e->compose, compose); | ||
113 | |||
114 | e->modifiers = 0; | ||
115 | if (dev->keyboard.shift) | ||
116 | e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT; | ||
117 | if (dev->keyboard.ctrl) e->modifiers |= ECORE_EVENT_MODIFIER_CTRL; | ||
118 | if (dev->keyboard.alt) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT; | ||
119 | if (dev->keyboard.lock) e->modifiers |= ECORE_EVENT_LOCK_CAPS; | ||
120 | |||
121 | e->timestamp = ecore_time_get(); | ||
122 | e->window = (Ecore_Window)dev->window; | ||
123 | e->event_window = (Ecore_Window)dev->window; | ||
124 | e->root_window = (Ecore_Window)dev->window; | ||
125 | e->same_screen = 1; | ||
126 | |||
127 | if (iev->value) | ||
128 | ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL); | ||
129 | else | ||
130 | ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL); | ||
131 | } | ||
132 | /* check for mouse button events */ | ||
133 | else if ((iev->code >= BTN_MOUSE) && (iev->code < BTN_JOYSTICK)) | ||
134 | { | ||
135 | int button; | ||
136 | Ecore_Event_Mouse_Button *e; | ||
137 | double current = ecore_time_get(); | ||
138 | |||
139 | button = ((iev->code & 0x00F) + 1); | ||
140 | if (iev->value) | ||
141 | { | ||
142 | dev->mouse.did_double = EINA_FALSE; | ||
143 | dev->mouse.did_triple = EINA_FALSE; | ||
144 | |||
145 | if (((current - dev->mouse.prev) <= dev->mouse.threshold) && | ||
146 | (button == dev->mouse.prev_button)) | ||
147 | { | ||
148 | dev->mouse.did_double = EINA_TRUE; | ||
149 | if (((current - dev->mouse.last) <= (2 * dev->mouse.threshold)) && | ||
150 | (button == dev->mouse.last_button)) | ||
151 | { | ||
152 | dev->mouse.did_triple = EINA_TRUE; | ||
153 | /* reset */ | ||
154 | dev->mouse.prev = 0; | ||
155 | dev->mouse.last = 0; | ||
156 | current = 0; | ||
157 | } | ||
158 | } | ||
159 | dev->mouse.last = dev->mouse.prev; | ||
160 | dev->mouse.prev = current; | ||
161 | dev->mouse.last_button = dev->mouse.prev_button; | ||
162 | dev->mouse.prev_button = button; | ||
163 | } | ||
164 | |||
165 | e = calloc(1, sizeof(Ecore_Event_Mouse_Button)); | ||
166 | if (!e) | ||
167 | return; | ||
168 | |||
169 | e->timestamp = current; | ||
170 | e->window = (Ecore_Window)dev->window; | ||
171 | e->event_window = (Ecore_Window)dev->window; | ||
172 | e->root_window = (Ecore_Window)dev->window; | ||
173 | e->same_screen = 1; | ||
174 | |||
175 | e->modifiers = 0; | ||
176 | if (dev->keyboard.shift) | ||
177 | e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT; | ||
178 | if (dev->keyboard.ctrl) e->modifiers |= ECORE_EVENT_MODIFIER_CTRL; | ||
179 | if (dev->keyboard.alt) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT; | ||
180 | if (dev->keyboard.lock) e->modifiers |= ECORE_EVENT_LOCK_CAPS; | ||
181 | |||
182 | e->x = dev->mouse.x; | ||
183 | e->y = dev->mouse.y; | ||
184 | e->root.x = e->x; | ||
185 | e->root.y = e->y; | ||
186 | e->buttons = button; | ||
187 | |||
188 | if (dev->mouse.did_double) | ||
189 | e->double_click = 1; | ||
190 | if (dev->mouse.did_triple) | ||
191 | e->triple_click = 1; | ||
192 | |||
193 | if (iev->value) | ||
194 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, e, NULL, NULL); | ||
195 | else | ||
196 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, e, NULL, NULL); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | static void | ||
201 | _ecore_fb_li_device_event_rel(Ecore_Fb_Input_Device *dev, struct input_event *iev) | ||
202 | { | ||
203 | if (!dev->listen) return; | ||
204 | /* dispatch the button events if they are queued */ | ||
205 | switch (iev->code) | ||
206 | { | ||
207 | case REL_X: | ||
208 | case REL_Y: | ||
209 | { | ||
210 | Ecore_Event_Mouse_Move *e; | ||
211 | if(iev->code == REL_X) | ||
212 | { | ||
213 | dev->mouse.x += iev->value; | ||
214 | if(dev->mouse.x > dev->mouse.w - 1) | ||
215 | dev->mouse.x = dev->mouse.w; | ||
216 | else if(dev->mouse.x < 0) | ||
217 | dev->mouse.x = 0; | ||
218 | } | ||
219 | else | ||
220 | { | ||
221 | dev->mouse.y += iev->value; | ||
222 | if(dev->mouse.y > dev->mouse.h - 1) | ||
223 | dev->mouse.y = dev->mouse.h; | ||
224 | else if(dev->mouse.y < 0) | ||
225 | dev->mouse.y = 0; | ||
226 | } | ||
227 | |||
228 | e = calloc(1, sizeof(Ecore_Event_Mouse_Move)); | ||
229 | if (!e) | ||
230 | return; | ||
231 | |||
232 | e->window = (Ecore_Window)dev->window; | ||
233 | e->event_window = (Ecore_Window)dev->window; | ||
234 | e->root_window = (Ecore_Window)dev->window; | ||
235 | e->same_screen = 1; | ||
236 | |||
237 | e->modifiers = 0; | ||
238 | if (dev->keyboard.shift) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT; | ||
239 | if (dev->keyboard.ctrl) e->modifiers |= ECORE_EVENT_MODIFIER_CTRL; | ||
240 | if (dev->keyboard.alt) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT; | ||
241 | if (dev->keyboard.lock) e->modifiers |= ECORE_EVENT_LOCK_CAPS; | ||
242 | |||
243 | e->x = dev->mouse.x; | ||
244 | e->y = dev->mouse.y; | ||
245 | e->root.x = e->x; | ||
246 | e->root.y = e->y; | ||
247 | |||
248 | e->timestamp = ecore_time_get(); | ||
249 | |||
250 | ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL); | ||
251 | |||
252 | break; | ||
253 | } | ||
254 | case REL_WHEEL: | ||
255 | case REL_HWHEEL: | ||
256 | { | ||
257 | Ecore_Event_Mouse_Wheel *e; | ||
258 | |||
259 | e = calloc(1, sizeof(Ecore_Event_Mouse_Wheel)); | ||
260 | if (!e) | ||
261 | return; | ||
262 | |||
263 | e->x = dev->mouse.x; | ||
264 | e->y = dev->mouse.y; | ||
265 | if (iev->code == REL_HWHEEL) e->direction = 1; | ||
266 | e->z = iev->value; | ||
267 | e->root.x = dev->mouse.x; | ||
268 | e->root.y = dev->mouse.y; | ||
269 | |||
270 | e->window = (Ecore_Window)dev->window; | ||
271 | e->event_window = (Ecore_Window)dev->window; | ||
272 | e->root_window = (Ecore_Window)dev->window; | ||
273 | e->same_screen = 1; | ||
274 | |||
275 | e->modifiers = 0; | ||
276 | if (dev->keyboard.shift) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT; | ||
277 | if (dev->keyboard.ctrl) e->modifiers |= ECORE_EVENT_MODIFIER_CTRL; | ||
278 | if (dev->keyboard.alt) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT; | ||
279 | if (dev->keyboard.lock) e->modifiers |= ECORE_EVENT_LOCK_CAPS; | ||
280 | |||
281 | e->timestamp = ecore_time_get(); | ||
282 | |||
283 | ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, e, NULL, NULL); | ||
284 | |||
285 | break; | ||
286 | } | ||
287 | default: | ||
288 | break; | ||
289 | } | ||
290 | } | ||
291 | |||
292 | static void | ||
293 | _ecore_fb_li_device_event_abs(Ecore_Fb_Input_Device *dev, struct input_event *iev) | ||
294 | { | ||
295 | static int prev_pressure = 0; | ||
296 | int pressure; | ||
297 | |||
298 | if (!dev->listen) return; | ||
299 | switch (iev->code) | ||
300 | { | ||
301 | case ABS_X: | ||
302 | if (dev->mouse.w != 0) | ||
303 | { | ||
304 | int tmp; | ||
305 | |||
306 | tmp = (int)((double)(iev->value - dev->mouse.min_w) / dev->mouse.rel_w); | ||
307 | if (tmp < 0) dev->mouse.x = 0; | ||
308 | else if (tmp > dev->mouse.w) dev->mouse.x = dev->mouse.w; | ||
309 | else dev->mouse.x = tmp; | ||
310 | dev->mouse.event = ECORE_EVENT_MOUSE_MOVE; | ||
311 | } | ||
312 | break; | ||
313 | |||
314 | case ABS_Y: | ||
315 | if(dev->mouse.h != 0) | ||
316 | { | ||
317 | int tmp; | ||
318 | |||
319 | tmp = (int)((double)(iev->value - dev->mouse.min_h) / dev->mouse.rel_h); | ||
320 | if (tmp < 0) dev->mouse.y = 0; | ||
321 | else if (tmp > dev->mouse.h) dev->mouse.y = dev->mouse.h; | ||
322 | else dev->mouse.y = tmp; | ||
323 | dev->mouse.event = ECORE_EVENT_MOUSE_MOVE; | ||
324 | } | ||
325 | break; | ||
326 | |||
327 | case ABS_PRESSURE: | ||
328 | pressure = iev->value; | ||
329 | if ((pressure) && (!prev_pressure)) | ||
330 | { | ||
331 | /* DOWN: mouse is down, but was not before */ | ||
332 | dev->mouse.event = ECORE_EVENT_MOUSE_BUTTON_DOWN; | ||
333 | } | ||
334 | else if ((!pressure) && (prev_pressure)) | ||
335 | { | ||
336 | /* UP: mouse was down, but is not now */ | ||
337 | dev->mouse.event = ECORE_EVENT_MOUSE_BUTTON_UP; | ||
338 | } | ||
339 | prev_pressure = pressure; | ||
340 | break; | ||
341 | } | ||
342 | } | ||
343 | |||
344 | static void | ||
345 | _ecore_fb_li_device_event_syn(Ecore_Fb_Input_Device *dev, struct input_event *iev __UNUSED__) | ||
346 | { | ||
347 | if (!dev->listen) return; | ||
348 | |||
349 | if (dev->mouse.event == ECORE_EVENT_MOUSE_MOVE) | ||
350 | { | ||
351 | Ecore_Event_Mouse_Move *ev; | ||
352 | ev = calloc(1,sizeof(Ecore_Event_Mouse_Move)); | ||
353 | ev->x = dev->mouse.x; | ||
354 | ev->y = dev->mouse.y; | ||
355 | ev->root.x = ev->x; | ||
356 | ev->root.y = ev->y; | ||
357 | ev->timestamp = ecore_time_get(); | ||
358 | } | ||
359 | else if (dev->mouse.event == ECORE_EVENT_MOUSE_BUTTON_DOWN) | ||
360 | { | ||
361 | Ecore_Event_Mouse_Button *ev; | ||
362 | ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); | ||
363 | ev->x = dev->mouse.x; | ||
364 | ev->y = dev->mouse.y; | ||
365 | ev->root.x = ev->x; | ||
366 | ev->root.y = ev->y; | ||
367 | ev->buttons = 1; | ||
368 | ev->timestamp = ecore_time_get(); | ||
369 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL); | ||
370 | } | ||
371 | else if (dev->mouse.event == ECORE_EVENT_MOUSE_BUTTON_UP) | ||
372 | { | ||
373 | Ecore_Event_Mouse_Button *ev; | ||
374 | ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); | ||
375 | ev->x = dev->mouse.x; | ||
376 | ev->y = dev->mouse.y; | ||
377 | ev->root.x = ev->x; | ||
378 | ev->root.y = ev->y; | ||
379 | ev->buttons = 1; | ||
380 | ev->timestamp = ecore_time_get(); | ||
381 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL); | ||
382 | } | ||
383 | } | ||
384 | |||
385 | static Eina_Bool | ||
386 | _ecore_fb_li_device_fd_callback(void *data, Ecore_Fd_Handler *fdh __UNUSED__) | ||
387 | { | ||
388 | Ecore_Fb_Input_Device *dev; | ||
389 | struct input_event ev[64]; | ||
390 | int len; | ||
391 | int i; | ||
392 | |||
393 | dev = (Ecore_Fb_Input_Device*)data; | ||
394 | /* read up to 64 events at once */ | ||
395 | len = read(dev->fd, &ev, sizeof(ev)); | ||
396 | for(i = 0; i < (int)(len / sizeof(ev[0])); i++) | ||
397 | { | ||
398 | switch(ev[i].type) | ||
399 | { | ||
400 | case EV_SYN: | ||
401 | _ecore_fb_li_device_event_syn(dev, &ev[i]); | ||
402 | break; | ||
403 | case EV_ABS: | ||
404 | _ecore_fb_li_device_event_abs(dev, &ev[i]); | ||
405 | break; | ||
406 | case EV_REL: | ||
407 | _ecore_fb_li_device_event_rel(dev, &ev[i]); | ||
408 | break; | ||
409 | case EV_KEY: | ||
410 | _ecore_fb_li_device_event_key(dev, &ev[i]); | ||
411 | break; | ||
412 | default: | ||
413 | break; | ||
414 | } | ||
415 | } | ||
416 | return EINA_TRUE; | ||
417 | } | ||
418 | |||
419 | /** | ||
420 | * @addtogroup Ecore_FB_Group Ecore_FB - Frame buffer convenience functions. | ||
421 | * | ||
422 | * @{ | ||
423 | */ | ||
424 | |||
425 | /** | ||
426 | * @brief Set the listen mode for an input device . | ||
427 | * | ||
428 | * @param dev The device to set the mode of. | ||
429 | * @param listen EINA_FALSE to disable listening mode, EINA_TRUE to enable it. | ||
430 | * | ||
431 | * This function enables or disables listening on the input device @p | ||
432 | * dev. If @p listen is #EINA_FALSE, listening mode is disabled, if it | ||
433 | * is #EINA_TRUE, it is enabled. | ||
434 | */ | ||
435 | EAPI void | ||
436 | ecore_fb_input_device_listen(Ecore_Fb_Input_Device *dev, Eina_Bool listen) | ||
437 | { | ||
438 | if (!dev) return; | ||
439 | if ((listen && dev->listen) || (!listen && !dev->listen)) return; | ||
440 | if (listen) | ||
441 | { | ||
442 | /* if the device already had a handler */ | ||
443 | if (!dev->handler) | ||
444 | dev->handler = ecore_main_fd_handler_add(dev->fd, ECORE_FD_READ, _ecore_fb_li_device_fd_callback, dev, NULL, NULL); | ||
445 | |||
446 | } | ||
447 | dev->listen = listen; | ||
448 | } | ||
449 | |||
450 | #ifndef EV_CNT | ||
451 | # define EV_CNT (EV_MAX+1) | ||
452 | #endif | ||
453 | |||
454 | /** | ||
455 | * @brief Associates an input device with the given @ref Ecore_Evas. | ||
456 | * | ||
457 | * @param dev The input being associated with an @ref Ecore_Evas (not @c NULL). | ||
458 | * @param window The window which this input is being associated to. | ||
459 | * @c NULL will remove any previous association. | ||
460 | * | ||
461 | * Events generated by this device will have a pointer to @p window. If this @p | ||
462 | * window is registered with ecore_event_window_register() or | ||
463 | * ecore_evas_input_event_register(), respective evas events will be delivered | ||
464 | * by the ecore_input_evas system. An example can be seen in the following code: | ||
465 | * | ||
466 | * @code | ||
467 | * Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, 800, 600, NULL); | ||
468 | * | ||
469 | * ecore_evas_input_event_register(ee); | ||
470 | * | ||
471 | * device = ecore_fb_input_device_open(device_path); | ||
472 | * if (device) | ||
473 | * ecore_fb_input_device_window_set(device, ee); | ||
474 | * | ||
475 | * @endcode | ||
476 | * | ||
477 | * On the previous code, all input captured on the mentioned device will be | ||
478 | * delivered to the @Ecore_Evas @c ee. | ||
479 | * | ||
480 | * @since 1.1 | ||
481 | */ | ||
482 | EAPI void | ||
483 | ecore_fb_input_device_window_set(Ecore_Fb_Input_Device *dev, void *window) | ||
484 | { | ||
485 | if (!dev) return; | ||
486 | |||
487 | dev->window = window; | ||
488 | } | ||
489 | |||
490 | /** | ||
491 | * @brief Open an input device. | ||
492 | * | ||
493 | * @param dev The device to open. | ||
494 | * @return The @ref Ecore_Fb_Input_Device object that has been opened. | ||
495 | * | ||
496 | * This function opens the input device named @p dev and returns the | ||
497 | * object for it, or returns @c NULL on failure. | ||
498 | */ | ||
499 | EAPI Ecore_Fb_Input_Device * | ||
500 | ecore_fb_input_device_open(const char *dev) | ||
501 | { | ||
502 | Ecore_Fb_Input_Device *device; | ||
503 | unsigned long event_type_bitmask[EV_CNT / 32 + 1]; | ||
504 | int event_type; | ||
505 | int fd; | ||
506 | |||
507 | if (!dev) return NULL; | ||
508 | device = calloc(1, sizeof(Ecore_Fb_Input_Device)); | ||
509 | if (!device) return NULL; | ||
510 | |||
511 | if ((fd = open(dev, O_RDONLY, O_NONBLOCK)) < 0) | ||
512 | { | ||
513 | fprintf(stderr, "[ecore_fb_li:device_open] %s %s", dev, strerror(errno)); | ||
514 | goto error_open; | ||
515 | } | ||
516 | /* query capabilities */ | ||
517 | if (ioctl(fd, EVIOCGBIT(0, EV_MAX), event_type_bitmask) < 0) | ||
518 | { | ||
519 | fprintf(stderr,"[ecore_fb_li:device_open] query capabilities %s %s", dev, strerror(errno)); | ||
520 | goto error_caps; | ||
521 | } | ||
522 | /* query name */ | ||
523 | device->info.name = calloc(256, sizeof(char)); | ||
524 | if (ioctl(fd, EVIOCGNAME(sizeof(char) * 256), device->info.name) < 0) | ||
525 | { | ||
526 | fprintf(stderr, "[ecore_fb_li:device_open] get name %s %s", dev, strerror(errno)); | ||
527 | strcpy(device->info.name, "Unknown"); | ||
528 | } | ||
529 | device->fd = fd; | ||
530 | device->info.dev = strdup(dev); | ||
531 | /* common */ | ||
532 | device->mouse.threshold = CLICK_THRESHOLD_DEFAULT; | ||
533 | |||
534 | /* set info */ | ||
535 | for (event_type = 0; event_type < EV_MAX; event_type++) | ||
536 | { | ||
537 | if(!test_bit(event_type, event_type_bitmask)) | ||
538 | continue; | ||
539 | switch (event_type) | ||
540 | { | ||
541 | case EV_SYN: | ||
542 | break; | ||
543 | case EV_KEY: | ||
544 | device->info.cap |= ECORE_FB_INPUT_DEVICE_CAP_KEYS_OR_BUTTONS; | ||
545 | break; | ||
546 | case EV_REL: | ||
547 | device->info.cap |= ECORE_FB_INPUT_DEVICE_CAP_RELATIVE; | ||
548 | break; | ||
549 | case EV_ABS: | ||
550 | device->info.cap |= ECORE_FB_INPUT_DEVICE_CAP_ABSOLUTE; | ||
551 | break; | ||
552 | case EV_MSC: | ||
553 | case EV_LED: | ||
554 | case EV_SND: | ||
555 | case EV_REP: | ||
556 | case EV_FF : | ||
557 | case EV_FF_STATUS: | ||
558 | case EV_PWR: | ||
559 | default: | ||
560 | break; | ||
561 | } | ||
562 | } | ||
563 | |||
564 | _ecore_fb_li_devices = eina_list_append(_ecore_fb_li_devices, device); | ||
565 | return device; | ||
566 | |||
567 | error_caps: | ||
568 | close(fd); | ||
569 | error_open: | ||
570 | free(device); | ||
571 | return NULL; | ||
572 | } | ||
573 | |||
574 | /** | ||
575 | * @brief Close the given device. | ||
576 | * | ||
577 | * @param dev The device to close | ||
578 | * | ||
579 | * This function closes the device @p dev. If @p dev is @c NULL, this | ||
580 | * function does nothing. | ||
581 | */ | ||
582 | EAPI void | ||
583 | ecore_fb_input_device_close(Ecore_Fb_Input_Device *dev) | ||
584 | { | ||
585 | if (!dev || dev->fd < 0) return; | ||
586 | /* close the fd */ | ||
587 | close(dev->fd); | ||
588 | /* remove the element from the list */ | ||
589 | _ecore_fb_li_devices = eina_list_remove(_ecore_fb_li_devices, dev); | ||
590 | free(dev); | ||
591 | } | ||
592 | |||
593 | |||
594 | /** | ||
595 | * @brief Set the axis size of the given device. | ||
596 | * | ||
597 | * @param dev The device to set the axis size to. | ||
598 | * @param w The width of the axis. | ||
599 | * @param h The height of the axis. | ||
600 | * | ||
601 | * This function sets set the width @p w and height @p h of the axis | ||
602 | * of device @p dev. If @p dev is a relative input device, a width and | ||
603 | * height must set for it. If its absolute set the ioctl correctly, if | ||
604 | * not, unsupported device. | ||
605 | */ | ||
606 | EAPI void | ||
607 | ecore_fb_input_device_axis_size_set(Ecore_Fb_Input_Device *dev, int w, int h) | ||
608 | { | ||
609 | if (!dev) return; | ||
610 | if ((w < 0) || (h < 0)) return; | ||
611 | /* FIXME | ||
612 | * this code is for a touchscreen device, | ||
613 | * make it configurable (ABSOLUTE | RELATIVE) | ||
614 | */ | ||
615 | if (dev->info.cap & ECORE_FB_INPUT_DEVICE_CAP_ABSOLUTE) | ||
616 | { | ||
617 | /* FIXME looks like some kernels dont include this struct */ | ||
618 | struct input_absinfo abs_features; | ||
619 | |||
620 | ioctl(dev->fd, EVIOCGABS(ABS_X), &abs_features); | ||
621 | dev->mouse.min_w = abs_features.minimum; | ||
622 | dev->mouse.rel_w = (double)(abs_features.maximum - abs_features.minimum)/(double)(w); | ||
623 | |||
624 | ioctl(dev->fd, EVIOCGABS(ABS_Y), &abs_features); | ||
625 | dev->mouse.min_h = abs_features.minimum; | ||
626 | dev->mouse.rel_h = (double)(abs_features.maximum - abs_features.minimum)/(double)(h); | ||
627 | } | ||
628 | else if (!(dev->info.cap & ECORE_FB_INPUT_DEVICE_CAP_RELATIVE)) | ||
629 | return; | ||
630 | |||
631 | /* update the local values */ | ||
632 | if (dev->mouse.x > w - 1) dev->mouse.x = w -1; | ||
633 | if (dev->mouse.y > h - 1) dev->mouse.y = h -1; | ||
634 | dev->mouse.w = w; | ||
635 | dev->mouse.h = h; | ||
636 | } | ||
637 | |||
638 | /** | ||
639 | * @brief Retrieve the name of the given device. | ||
640 | * | ||
641 | * @param dev The device to get the name from. | ||
642 | * @return The name of the device. | ||
643 | * | ||
644 | * This function returns the name of the device @p dev. If @p dev is | ||
645 | * @c NULL, this function returns @c NULL. | ||
646 | */ | ||
647 | EAPI const char * | ||
648 | ecore_fb_input_device_name_get(Ecore_Fb_Input_Device *dev) | ||
649 | { | ||
650 | if (!dev) return NULL; | ||
651 | return dev->info.name; | ||
652 | } | ||
653 | |||
654 | /** | ||
655 | * @brief Retrieve the capability of the given device. | ||
656 | * | ||
657 | * @param dev The device to get the name from. | ||
658 | * @return The capability of the device. | ||
659 | * | ||
660 | * This function returns the capability of the device @p dev. If @p dev is | ||
661 | * @c NULL, this function returns #ECORE_FB_INPUT_DEVICE_CAP_NONE. | ||
662 | */ | ||
663 | EAPI Ecore_Fb_Input_Device_Cap | ||
664 | ecore_fb_input_device_cap_get(Ecore_Fb_Input_Device *dev) | ||
665 | { | ||
666 | if (!dev) return ECORE_FB_INPUT_DEVICE_CAP_NONE; | ||
667 | return dev->info.cap; | ||
668 | } | ||
669 | |||
670 | /** | ||
671 | * @brief Set the threshold of mouse clicks of the given device. | ||
672 | * | ||
673 | * @param dev The device to set the threshodl mouse click to. | ||
674 | * @param threshold The threshold value. | ||
675 | * | ||
676 | * This function sets the threshold of mouse clicks of the device | ||
677 | * @p dev to @p threshold. If @p dev is @c NULL, this function does | ||
678 | * nothing. | ||
679 | */ | ||
680 | EAPI void | ||
681 | ecore_fb_input_device_threshold_click_set(Ecore_Fb_Input_Device *dev, double threshold) | ||
682 | { | ||
683 | if (!dev) return; | ||
684 | if ((threshold == dev->mouse.threshold) || (threshold == 0)) return; | ||
685 | dev->mouse.threshold = threshold; | ||
686 | } | ||
687 | |||
688 | /** | ||
689 | * @brief Get the threshold of mouse clicks of the given device. | ||
690 | * | ||
691 | * @param dev The device to set the threshodl mouse click from. | ||
692 | * @return The threshold value. | ||
693 | * | ||
694 | * This function returns the threshold of mouse clicks of the device | ||
695 | * @p dev. If @p dev is @c NULL, this function returns 0.0. | ||
696 | */ | ||
697 | EAPI double | ||
698 | ecore_fb_input_device_threshold_click_get(Ecore_Fb_Input_Device *dev) | ||
699 | { | ||
700 | if (!dev) return 0; | ||
701 | return dev->mouse.threshold; | ||
702 | } | ||
703 | |||
704 | /** | ||
705 | * @} | ||
706 | */ | ||