summaryrefslogtreecommitdiff
path: root/src/lib/ecore_fb
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-12-02 22:35:45 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-12-02 22:35:45 +0000
commit7d6010b12c47a20e492da808e3192c3f87dab619 (patch)
tree26c6fd189e046a76560c0bc740b85f4d767ae399 /src/lib/ecore_fb
parent53fc441d5475155965d92da89502fe4634a561b2 (diff)
merge: add escape ecore, fix several bugs
SVN revision: 79995
Diffstat (limited to 'src/lib/ecore_fb')
-rw-r--r--src/lib/ecore_fb/Ecore_Fb.h100
-rw-r--r--src/lib/ecore_fb/ecore_fb.c129
-rw-r--r--src/lib/ecore_fb/ecore_fb_kbd.c326
-rw-r--r--src/lib/ecore_fb/ecore_fb_keytable.h129
-rw-r--r--src/lib/ecore_fb/ecore_fb_li.c721
-rw-r--r--src/lib/ecore_fb/ecore_fb_private.h94
-rw-r--r--src/lib/ecore_fb/ecore_fb_ps2.c223
-rw-r--r--src/lib/ecore_fb/ecore_fb_ts.c362
-rw-r--r--src/lib/ecore_fb/ecore_fb_vt.c322
9 files changed, 2406 insertions, 0 deletions
diff --git a/src/lib/ecore_fb/Ecore_Fb.h b/src/lib/ecore_fb/Ecore_Fb.h
new file mode 100644
index 0000000000..069cccdff9
--- /dev/null
+++ b/src/lib/ecore_fb/Ecore_Fb.h
@@ -0,0 +1,100 @@
1#ifndef _ECORE_FB_H
2#define _ECORE_FB_H
3
4#include <Eina.h>
5
6#ifdef EAPI
7# undef EAPI
8#endif
9
10#ifdef __GNUC__
11# if __GNUC__ >= 4
12# define EAPI __attribute__ ((visibility("default")))
13# else
14# define EAPI
15# endif
16#else
17# define EAPI
18#endif
19
20/* FIXME:
21 * maybe a new module?
22 * - code to get battery info
23 * - code to get thermal info
24 * ecore evas fb isn't good enough for weird things, like multiple fb's, same happens here.
25 * backlight support using new kernel interface
26 * absolute axis
27 * joystick
28 * ecore_fb_li_device_close_all ? or a shutdown of the subsystem?
29 *
30 */
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/**
37 * @defgroup Ecore_FB_Group Ecore_FB - Frame buffer convenience functions.
38 *
39 * Functions used to set up and shut down the Ecore_Framebuffer functions.
40 *
41 * @{
42 */
43
44/**
45 * @typedef Ecore_Fb_Input_Device
46 * Input device handler.
47 */
48typedef struct _Ecore_Fb_Input_Device Ecore_Fb_Input_Device;
49
50/**
51 * @enum _Ecore_Fb_Input_Device_Cap
52 * Device capabilities.
53 */
54enum _Ecore_Fb_Input_Device_Cap
55{
56 ECORE_FB_INPUT_DEVICE_CAP_NONE = 0x00000000,
57 ECORE_FB_INPUT_DEVICE_CAP_RELATIVE = 0x00000001,
58 ECORE_FB_INPUT_DEVICE_CAP_ABSOLUTE = 0x00000002,
59 ECORE_FB_INPUT_DEVICE_CAP_KEYS_OR_BUTTONS = 0x00000004
60};
61
62/**
63 * @typedef Ecore_Fb_Input_Device_Cap
64 * Device capabilities.
65 */
66typedef enum _Ecore_Fb_Input_Device_Cap Ecore_Fb_Input_Device_Cap;
67
68/* ecore_fb_vt.c */
69EAPI void ecore_fb_callback_gain_set(void (*func) (void *data), void *data);
70EAPI void ecore_fb_callback_lose_set(void (*func) (void *data), void *data);
71
72/* ecore_fb_li.c */
73EAPI Ecore_Fb_Input_Device *ecore_fb_input_device_open(const char *dev);
74EAPI void ecore_fb_input_device_close(Ecore_Fb_Input_Device *dev);
75EAPI void ecore_fb_input_device_listen(Ecore_Fb_Input_Device *dev, Eina_Bool listen);
76EAPI const char *ecore_fb_input_device_name_get(Ecore_Fb_Input_Device *dev);
77EAPI Ecore_Fb_Input_Device_Cap ecore_fb_input_device_cap_get(Ecore_Fb_Input_Device *dev);
78EAPI void ecore_fb_input_device_axis_size_set(Ecore_Fb_Input_Device *dev, int w, int h);
79EAPI void ecore_fb_input_threshold_click_set(Ecore_Fb_Input_Device *dev, double threshold);
80EAPI double ecore_fb_input_threshold_click_get(Ecore_Fb_Input_Device *dev);
81EAPI void ecore_fb_input_device_window_set(Ecore_Fb_Input_Device *dev, void *window);
82
83/* ecore_fb.c */
84
85EAPI int ecore_fb_init(const char *name);
86EAPI int ecore_fb_shutdown(void);
87EAPI void ecore_fb_size_get(int *w, int *h);
88
89EAPI void ecore_fb_touch_screen_calibrate_set(int xscale, int xtrans, int yscale, int ytrans, int xyswap);
90EAPI void ecore_fb_touch_screen_calibrate_get(int *xscale, int *xtrans, int *yscale, int *ytrans, int *xyswap);
91
92/**
93 * @}
94 */
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif
diff --git a/src/lib/ecore_fb/ecore_fb.c b/src/lib/ecore_fb/ecore_fb.c
new file mode 100644
index 0000000000..ff96ac8a77
--- /dev/null
+++ b/src/lib/ecore_fb/ecore_fb.c
@@ -0,0 +1,129 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Ecore_Fb.h"
6#include "ecore_fb_private.h"
7
8static void _ecore_fb_size_get(int *w, int *h);
9
10static int _ecore_fb_init_count = 0;
11static int _ecore_fb_console_w = 0;
12static int _ecore_fb_console_h = 0;
13
14/**
15 * @addtogroup Ecore_FB_Group Ecore_FB - Frame buffer convenience functions.
16 *
17 * @{
18 */
19
20static sighandler_t oldhand = NULL;
21
22static void
23nosigint(int val EINA_UNUSED)
24{
25}
26
27/**
28 * @brief Initialize the Ecore_Fb library.
29 *
30 * @param name Device target name.
31 * @return 1 or greater on success, 0 on error.
32 *
33 * This function sets up all the Ecore_Fb library. It returns 0 on
34 * failure, otherwise it returns the number of times it has already
35 * been called.
36 *
37 * When Ecore_Fb is not used anymore, call ecore_fb_shutdown() to shut down
38 * the Ecore_Fb library.
39 */
40EAPI int
41ecore_fb_init(const char *name EINA_UNUSED)
42{
43 if (++_ecore_fb_init_count != 1)
44 return _ecore_fb_init_count;
45
46 if (!ecore_fb_vt_init())
47 return --_ecore_fb_init_count;
48
49 if (!oldhand)
50 {
51 oldhand = signal(SIGINT, nosigint);
52 }
53
54 _ecore_fb_size_get(&_ecore_fb_console_w, &_ecore_fb_console_h);
55
56 return _ecore_fb_init_count;
57}
58
59/**
60 * @brief Shut down the Ecore_Fb library.
61 *
62 * @return 0 when the library is completely shut down, 1 or
63 * greater otherwise.
64 *
65 * This function shuts down the Ecore_Fb library. It returns 0 when it has
66 * been called the same number of times than ecore_fb_init().
67 */
68EAPI int
69ecore_fb_shutdown(void)
70{
71 if (--_ecore_fb_init_count != 0)
72 return _ecore_fb_init_count;
73
74 if (oldhand)
75 {
76 signal(SIGINT, oldhand);
77 oldhand = NULL;
78 }
79
80 ecore_fb_vt_shutdown();
81
82 return _ecore_fb_init_count;
83}
84
85
86/**
87 * @brief Retrieve the width and height of the current frame buffer in
88 * pixels.
89 *
90 * @param w Pointer to an integer in which to store the width.
91 * @param h Pointer to an interge in which to store the height.
92 *
93 * This function retrieves the size of the current frame buffer in
94 * pixels. @p w and @p h can be buffers that will be filled with the
95 * corresponding values. If one of them is @c NULL, nothing will be
96 * done for that parameter.
97 */
98EAPI void
99ecore_fb_size_get(int *w, int *h)
100{
101 if (w) *w = _ecore_fb_console_w;
102 if (h) *h = _ecore_fb_console_h;
103}
104
105static void
106_ecore_fb_size_get(int *w, int *h)
107{
108 struct fb_var_screeninfo fb_var;
109 int fb;
110
111 fb = open("/dev/fb0", O_RDWR);
112 if (fb < 0)
113 goto exit;
114
115 if (ioctl(fb, FBIOGET_VSCREENINFO, &fb_var) == -1)
116 goto err_ioctl;
117
118 *w = fb_var.xres;
119 *h = fb_var.yres;
120
121err_ioctl:
122 close(fb);
123exit:
124 return;
125}
126
127/**
128 * @}
129 */
diff --git a/src/lib/ecore_fb/ecore_fb_kbd.c b/src/lib/ecore_fb/ecore_fb_kbd.c
new file mode 100644
index 0000000000..fd111db04d
--- /dev/null
+++ b/src/lib/ecore_fb/ecore_fb_kbd.c
@@ -0,0 +1,326 @@
1static void _ecore_fb_event_free_key_down(void *data, void *ev);
2static void _ecore_fb_event_free_key_up(void *data, void *ev);
3
4static const char *_ecore_fb_kbd_syms[128 * 7] =
5{
6#include "ecore_fb_keytable.h"
7};
8
9static const char *_ecore_fb_btn_syms[128] =
10{
11 "0x00",
12 "Escape",
13 "F1",
14 "F2",
15 "F3",
16 "F4",
17 "Up",
18 "Right",
19 "Left",
20 "Down",
21 "Return",
22 "0x1b",
23 "0x1c",
24 "0x1d",
25 "0x1e",
26 "0x1f",
27 "0x20",
28 "0x21",
29 "0x22",
30 "0x23",
31 "0x24",
32 "0x25",
33 "0x26",
34 "0x27",
35 "0x28",
36 "0x29",
37 "0x2a",
38 "0x2b",
39 "0x2c",
40 "0x2d",
41 "0x2e",
42 "0x2f",
43 "0x30",
44 "0x31",
45 "0x32",
46 "0x33",
47 "0x34",
48 "0x35",
49 "0x36",
50 "0x37",
51 "0x38",
52 "0x39",
53 "0x3a",
54 "0x3b",
55 "0x3c",
56 "0x3d",
57 "0x3e",
58 "0x3f",
59 "0x40",
60 "0x41",
61 "0x42",
62 "0x43",
63 "0x44",
64 "0x45",
65 "0x46",
66 "0x47",
67 "0x48",
68 "0x49",
69 "0x4a",
70 "0x4b",
71 "0x4c",
72 "0x4d",
73 "0x4e",
74 "0x4f",
75 "0x50",
76 "0x51",
77 "0x52",
78 "0x53",
79 "0x54",
80 "0x55",
81 "0x56",
82 "0x57",
83 "0x58",
84 "0x59",
85 "0x5a",
86 "0x5b",
87 "0x5c",
88 "0x5d",
89 "0x5e",
90 "0x5f",
91 "0x60",
92 "0x61",
93 "0x62",
94 "0x63",
95 "0x64",
96 "0x65",
97 "0x66",
98 "0x67",
99 "0x68",
100 "0x69",
101 "0x6a",
102 "0x6b",
103 "0x6c",
104 "0x6d",
105 "0x6e",
106 "0x6f",
107 "0x70",
108 "0x71",
109 "0x72",
110 "0x73",
111 "0x74",
112 "0x75",
113 "0x76",
114 "0x77",
115 "0x78",
116 "0x79",
117 "0x7a",
118 "0x7b",
119 "0x7c",
120 "0x7d",
121 "0x7e",
122 "0x7f"
123};
124static int _ecore_fb_kbd_fd = -1;
125static int _ecore_fb_ctrl = 0;
126static int _ecore_fb_alt = 0;
127static int _ecore_fb_shift = 0;
128static int _ecore_fb_lock = 0;
129
130static Ecore_Fd_Handler *_ecore_fb_kbd_fd_handler_handle = NULL;
131static Eina_Bool _ecore_fb_kbd_fd_handler(void *data, Ecore_Fd_Handler *fd_handler);
132
133static void
134_ecore_fb_event_free_key_down(void *data EINA_UNUSED, void *ev)
135{
136 Ecore_Fb_Event_Key_Down *e;
137 e = ev;
138 free(e->keyname);
139 if (e->keysymbol) free(e->keysymbol);
140 if (e->key_compose) free(e->key_compose);
141 free(e);
142}
143
144static void
145_ecore_fb_event_free_key_up(void *data EINA_UNUSED, void *ev)
146{
147 Ecore_Fb_Event_Key_Up *e;
148
149 e = ev;
150 free(e->keyname);
151 if (e->keysymbol) free(e->keysymbol);
152 if (e->key_compose) free(e->key_compose);
153 free(e);
154}
155
156static Eina_Bool
157_ecore_fb_kbd_fd_handler(void *data EINA_UNUSED, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
158{
159 int v = 0;
160
161 do
162 {
163 unsigned char buf;
164
165 v = read(_ecore_fb_kbd_fd, &buf, 1);
166 if (v < 0) return EINA_TRUE;
167 if (v < 1) return EINA_TRUE;
168 if (!(buf & 0x80))
169 {
170 /* DOWN */
171 int vt_switch = -1;
172 Ecore_Fb_Event_Key_Down *e;
173
174 e = calloc(1, sizeof(Ecore_Fb_Event_Key_Down));
175 if (!e) goto retry;
176 if (_ecore_fb_kbd_fd == _ecore_fb_tty_fd)
177 {
178 int add = 0;
179
180 if (_ecore_fb_shift) add = 1;
181 else if (_ecore_fb_lock) add = 2;
182 e->keyname = strdup(_ecore_fb_kbd_syms[(buf & 0x7f) * 7]);
183 e->keysymbol = strdup(_ecore_fb_kbd_syms[((buf & 0x7f) * 7) + add]);
184 e->key_compose = strdup(_ecore_fb_kbd_syms[((buf & 0x7f) * 7) + 3 + add]);
185 }
186 else
187 e->keyname = strdup(_ecore_fb_btn_syms[buf & 0x7f]);
188 if (!e->keyname)
189 {
190 free(e);
191 goto retry;
192 }
193 e->window = 1;
194 e->event_window = e->window;
195 e->root_window = e->window;
196 e->same_screen = 1;
197 e->timestamp = ecore_loop_time_get() * 1000.0;
198 if (!strcmp(e->keyname, "Control_L"))
199 _ecore_fb_ctrl++;
200 else if (!strcmp(e->keyname, "Control_R"))
201 _ecore_fb_ctrl++;
202 else if (!strcmp(e->keyname, "Alt_L"))
203 _ecore_fb_alt++;
204 else if (!strcmp(e->keyname, "Alt_R"))
205 _ecore_fb_alt++;
206 else if (!strcmp(e->keyname, "Shift_L"))
207 _ecore_fb_shift++;
208 else if (!strcmp(e->keyname, "Shift_R"))
209 _ecore_fb_shift++;
210 else if (!strcmp(e->keyname, "Caps_Lock"))
211 _ecore_fb_lock++;
212 else if (!strcmp(e->keyname, "F1")) vt_switch = 0;
213 else if (!strcmp(e->keyname, "F2")) vt_switch = 1;
214 else if (!strcmp(e->keyname, "F3")) vt_switch = 2;
215 else if (!strcmp(e->keyname, "F4")) vt_switch = 3;
216 else if (!strcmp(e->keyname, "F5")) vt_switch = 4;
217 else if (!strcmp(e->keyname, "F6")) vt_switch = 5;
218 else if (!strcmp(e->keyname, "F7")) vt_switch = 6;
219 else if (!strcmp(e->keyname, "F8")) vt_switch = 7;
220 else if (!strcmp(e->keyname, "F9")) vt_switch = 8;
221 else if (!strcmp(e->keyname, "F10")) vt_switch = 9;
222 else if (!strcmp(e->keyname, "F11")) vt_switch = 10;
223 else if (!strcmp(e->keyname, "F12")) vt_switch = 11;
224 if (_ecore_fb_ctrl > 2) _ecore_fb_ctrl = 2;
225 if (_ecore_fb_alt > 2) _ecore_fb_alt = 2;
226 if ((_ecore_fb_kbd_fd == _ecore_fb_tty_fd) &&
227 (_ecore_fb_ctrl))
228 {
229 const char *ts = _ecore_fb_kbd_syms[(buf & 0x7f) + 3 + 3];
230
231 if (ts)
232 {
233 if (e->key_compose) free(e->key_compose);
234 e->key_compose = strdup(ts);
235 }
236 }
237 if ((vt_switch >= 0) &&
238 (_ecore_fb_ctrl) &&
239 (_ecore_fb_alt))
240 _ecore_fb_vt_switch(vt_switch);
241 ecore_event_add(ECORE_FB_EVENT_KEY_DOWN, e, _ecore_fb_event_free_key_down, NULL);
242 }
243 else
244 {
245 /* UP */
246 Ecore_Fb_Event_Key_Up *e;
247
248 e = calloc(1, sizeof(Ecore_Fb_Event_Key_Up));
249 if (!e) goto retry;
250 if (_ecore_fb_kbd_fd == _ecore_fb_tty_fd)
251 {
252 int add = 0;
253
254 if (_ecore_fb_shift) add = 1;
255 else if (_ecore_fb_lock) add = 2;
256 e->keyname = strdup(_ecore_fb_kbd_syms[(buf & 0x7f) * 7]);
257 e->keysymbol = strdup(_ecore_fb_kbd_syms[((buf & 0x7f) * 7) + add]);
258 e->key_compose = strdup(_ecore_fb_kbd_syms[((buf & 0x7f) * 7) + 3 + add]);
259 }
260 else
261 e->keyname = strdup(_ecore_fb_btn_syms[buf & 0x7f]);
262 if (!e->keyname)
263 {
264 free(e);
265 goto retry;
266 }
267 e->window = 1;
268 e->event_window = e->window;
269 e->root_window = e->window;
270 e->same_screen = 1;
271 e->timestamp = ecore_loop_time_get() * 1000.0;
272 ecore_event_add(ECORE_FB_EVENT_KEY_UP, e, _ecore_fb_event_free_key_up, NULL);
273 if (!strcmp(e->keyname, "Control_L"))
274 _ecore_fb_ctrl--;
275 else if (!strcmp(e->keyname, "Control_R"))
276 _ecore_fb_ctrl--;
277 else if (!strcmp(e->keyname, "Alt_L"))
278 _ecore_fb_alt--;
279 else if (!strcmp(e->keyname, "Alt_R"))
280 _ecore_fb_alt--;
281 else if (!strcmp(e->keyname, "Shift_L"))
282 _ecore_fb_shift--;
283 else if (!strcmp(e->keyname, "Shift_R"))
284 _ecore_fb_shift--;
285 else if (!strcmp(e->keyname, "Caps_Lock"))
286 _ecore_fb_lock--;
287 if (_ecore_fb_ctrl < 0) _ecore_fb_ctrl = 0;
288 if (_ecore_fb_alt < 0) _ecore_fb_alt = 0;
289 if (_ecore_fb_shift < 0) _ecore_fb_shift = 0;
290 if (_ecore_fb_lock < 0) _ecore_fb_lock = 0;
291 }
292retry:
293 ;
294 }
295 while (v > 0);
296 return EINA_TRUE;
297}
298
299int
300ecore_fb_kbd_init(void)
301{
302 int prev_flags;
303
304 prev_flags = fcntl(_ecore_fb_kbd_fd, F_GETFL);
305 fcntl(_ecore_fb_kbd_fd, F_SETFL, prev_flags | O_NONBLOCK);
306 _ecore_fb_kbd_fd_handler_handle = ecore_main_fd_handler_add(_ecore_fb_kbd_fd,
307 ECORE_FD_READ,
308 _ecore_fb_kbd_fd_handler, NULL,
309 NULL, NULL);
310 if(!_ecore_fb_kbd_fd_handler_handle) return 0;
311 return 1;
312}
313
314void
315ecore_fb_kbd_shutdown(void)
316{
317 if (_ecore_fb_kbd_fd_handler_handle)
318 ecore_main_fd_handler_del(_ecore_fb_kbd_fd_handler_handle);
319 if (_ecore_fb_kbd_fd >= 0) close(_ecore_fb_kbd_fd);
320 _ecore_fb_kbd_fd = -1;
321 _ecore_fb_kbd_fd_handler_handle = NULL;
322 _ecore_fb_ctrl = 0;
323 _ecore_fb_lock = 0;
324 _ecore_fb_shift = 0;
325 _ecore_fb_alt = 0;
326}
diff --git a/src/lib/ecore_fb/ecore_fb_keytable.h b/src/lib/ecore_fb/ecore_fb_keytable.h
new file mode 100644
index 0000000000..70bf6b9689
--- /dev/null
+++ b/src/lib/ecore_fb/ecore_fb_keytable.h
@@ -0,0 +1,129 @@
1/* this table was taken from ecore_fb, is the default en layout */
2 "0x00", "0x00", "0x00", /**/"", "", "", NULL,/***/
3 "Escape", "Escape", "Escape", /**/"", "", "", "\x1b",/***/
4 "1", "exclam", "1", /**/"1", "!", "1", NULL,/***/
5 "2", "at", "2", /**/"2", "@", "2", "",/***/
6 "3", "numbersign", "3", /**/"3", "#", "3", "\x1b",/***/
7 "4", "dollar", "4", /**/"4", "$", "4", "\x1c",/***/
8 "5", "percent", "5", /**/"5", "%", "5", "\x1d",/***/
9 "6", "asciicircumm", "6", /**/"6", "^", "6", "\x1e",/***/
10 "7", "ampersand", "7", /**/"7", "&", "7", "\x1f",/***/
11 "8", "asterisk", "8", /**/"8", "*", "8", "\x7f",/***/
12 "9", "parenleft", "9", /**/"9", "(", "9", NULL,/***/
13 "0", "parenright", "0", /**/"0", ")", "0", NULL,/***/
14 "minus", "underscore", "minus", /**/"-", "_", "-", NULL,/***/
15 "equal", "plus", "equal", /**/"=", "+", "=", NULL,/***/
16 "BackSpace", "BackSpace", "BackSpace", /**/"\010","\010","\010", NULL,/***/
17 "Tab", "ISO_Left_Tab", "Tab", /**/"\011","", "\011", NULL,/***/
18 "q", "Q", "Q", /**/"q", "Q", "Q", "\x11",/***/
19 "w", "W", "W", /**/"w", "W", "W", "\x17",/***/
20 "e", "E", "E", /**/"e", "E", "E", "\x05",/***/
21 "r", "R", "R", /**/"r", "R", "R", "\x12",/***/
22 "t", "T", "T", /**/"t", "T", "T", "\x14",/***/
23 "y", "Y", "Y", /**/"y", "Y", "Y", "\x19",/***/
24 "u", "U", "U", /**/"u", "U", "U", "\x15",/***/
25 "i", "I", "I", /**/"i", "I", "I", "\x09",/***/
26 "o", "O", "O", /**/"o", "O", "O", "\x0f",/***/
27 "p", "P", "P", /**/"p", "P", "P", "\x10",/***/
28 "bracketleft", "braceleft", "bracketleft", /**/"[", "{", "[", "\x1b",/***/
29 "bracketright", "braceright", "bracketright", /**/"]", "}", "]", "\x1d",/***/
30 "Return", "Return", "Return", /**/"\015","\015","\015", NULL,/***/
31 "Control_L", "Control_L", "Control_L", /**/"", "", "", NULL,/***/
32 "a", "A", "A", /**/"a", "A", "A", "\x01",/***/
33 "s", "S", "S", /**/"s", "S", "S", "\x13",/***/
34 "d", "D", "D", /**/"d", "D", "D", "\x04",/***/
35 "f", "F", "F", /**/"f", "F", "F", "\x06",/***/
36 "g", "G", "G", /**/"g", "G", "G", "\x07",/***/
37 "h", "h", "H", /**/"h", "H", "H", "\x08",/***/
38 "j", "J", "J", /**/"j", "J", "J", "\x0a",/***/
39 "k", "K", "K", /**/"k", "K", "K", "\x0b",/***/
40 "l", "L", "L", /**/"l", "L", "L", "\x0c",/***/
41 "semicolon", "colon", "semicolon", /**/";", ":", ";", NULL,/***/
42 "apostrophe", "quotedbl", "apostrophe", /**/"'", "\"", "'", NULL,/***/
43 "grave", "asciitilde", "grave", /**/"`", "~", "`", "",/***/
44 "Shift_L", "Shift_L", "Shift_L", /**/"", "", "", NULL,/***/
45 "backslash", "bar", "backslash", /**/"\\", "|", "\\", "\x1c",/***/
46 "z", "Z", "Z", /**/"z", "Z", "Z", "\x1a",/***/
47 "x", "X", "X", /**/"x", "X", "X", "\x18",/***/
48 "c", "C", "C", /**/"c", "C", "C", "\x03",/***/
49 "v", "V", "V", /**/"v", "V", "V", "\x16",/***/
50 "b", "B", "B", /**/"b", "B", "B", "\x02",/***/
51 "n", "N", "N", /**/"n", "N", "N", "\x0e",/***/
52 "m", "M", "M", /**/"m", "M", "M", "\x0d",/***/
53 "comma", "less", "comma", /**/",", "<", ",", NULL,/***/
54 "period", "greater", "period", /**/".", ">", ".", NULL,/***/
55 "slash", "question", "slash", /**/"/", "?", "/", "",/***/
56 "Shift_R", "Shift_R", "Shift_R", /**/"", "", "", NULL,/***/
57 "KP_Multiply", "KP_Multiply", "KP_Multiply", /**/"", "*", "", NULL,/***/
58 "Alt_L", "Alt_L", "Alt_L", /**/"", "", "", NULL,/***/
59 "space", "space", "space", /**/" ", " ", " ", "",/***/
60 "Caps_Lock", "Caps_Lock", "Caps_Lock", /**/"", "", "", NULL,/***/
61 "F1", "F1", "F1", /**/"", "", "", NULL,/***/
62 "F2", "F2", "F2", /**/"", "", "", NULL,/***/
63 "F3", "F3", "F3", /**/"", "", "", NULL,/***/
64 "F4", "F4", "F4", /**/"", "", "", NULL,/***/
65 "F5", "F5", "F5", /**/"", "", "", NULL,/***/
66 "F6", "F6", "F6", /**/"", "", "", NULL,/***/
67 "F7", "F7", "F7", /**/"", "", "", NULL,/***/
68 "F8", "F8", "F8", /**/"", "", "", NULL,/***/
69 "F9", "F9", "F9", /**/"", "", "", NULL,/***/
70 "F10", "F10", "F10", /**/"", "", "", NULL,/***/
71 "Num_Lock", "Num_Lock", "Num_Lock", /**/"", "", "", NULL,/***/
72 "Scroll_Lock", "Scroll_Lock", "Scroll_Lock", /**/"", "", "", NULL,/***/
73 "KP_Home", "KP_7", "KP_Home", /**/"", "7", "", NULL,/***/
74 "KP_Up", "KP_8", "KP_Up", /**/"", "8", "", NULL,/***/
75 "KP_Prior", "KP_9", "KP_Prior", /**/"", "9", "", NULL,/***/
76 "KP_Subtract", "KP_Subtract", "KP_Subtract", /**/"", "", "", NULL,/***/
77 "KP_Left", "KP_4", "KP_Left", /**/"", "4", "", NULL,/***/
78 "KP_Begin", "KP_5", "KP_Begin", /**/"", "5", "", NULL,/***/
79 "KP_Right", "KP_6", "KP_Right", /**/"", "6", "", NULL,/***/
80 "KP_Add", "KP_Add", "KP_Add", /**/"", "", "", NULL,/***/
81 "KP_End", "KP_1", "KP_End", /**/"", "1", "", NULL,/***/
82 "KP_Down", "KP_2", "KP_Down", /**/"", "2", "", NULL,/***/
83 "KP_Next", "KP_3", "KP_Next", /**/"", "3", "", NULL,/***/
84 "KP_Insert", "KP_0", "KP_Insert", /**/"", "0", "", NULL,/***/
85 "KP_Delete", "KP_Decimal", "KP_Delete", /**/"", ".", "", NULL,/***/
86 "0x54", "0x54", "0x54", /**/"", "", "", NULL,/***/
87 "0x55", "0x55", "0x55", /**/"", "", "", NULL,/***/
88 "0x56", "0x56", "0x56", /**/"", "", "", NULL,/***/
89 "F11", "F11", "F11", /**/"", "", "", NULL,/***/
90 "F12", "F12", "F12", /**/"", "", "", NULL,/***/
91 "0x59", "0x59", "0x59", /**/"", "", "", NULL,/***/
92 "0x5a", "0x5a", "0x5a", /**/"", "", "", NULL,/***/
93 "0x5b", "0x5b", "0x5b", /**/"", "", "", NULL,/***/
94 "0x5c", "0x5c", "0x5c", /**/"", "", "", NULL,/***/
95 "0x5d", "0x5d", "0x5d", /**/"", "", "", NULL,/***/
96 "0x5e", "0x5e", "0x5e", /**/"", "", "", NULL,/***/
97 "0x5f", "0x5f", "0x5f", /**/"", "", "", NULL,/***/
98 "KP_Enter", "KP_Enter", "KP_Enter", /**/"\015", "\015", "\015", NULL,/***/
99 "Control_R", "Control_R", "Control_R", /**/"", "", "", NULL,/***/
100 "KP_Divide", "KP_Divide", "KP_Divide", /**/"", "", "", NULL,/***/
101 "Print", "Print", "Print", /**/"", "", "", NULL,/***/
102 "Alt_R", "Alt_R", "Alt_R", /**/"", "", "", NULL,/***/
103 "0x65", "0x65", "0x65", /**/"", "", "", NULL,/***/
104 "Home", "Home", "Home", /**/"", "", "", NULL,/***/
105 "Up", "Up", "Up", /**/"", "", "", NULL,/***/
106 "Prior", "Prior", "Prior", /**/"", "", "", NULL,/***/
107 "Left", "Left", "Left", /**/"", "", "", NULL,/***/
108 "Right", "Right", "Right", /**/"", "", "", NULL,/***/
109 "End", "End", "End", /**/"", "", "", NULL,/***/
110 "Down", "Down", "Down", /**/"", "", "", NULL,/***/
111 "Next", "Next", "Next", /**/"", "", "", NULL,/***/
112 "Insert", "Insert", "Insert", /**/"", "", "", NULL,/***/
113 "Delete", "Delete", "Delete", /**/"\177","\177","\177", NULL,/***/
114 "0x70", "0x70", "0x70", /**/"", "", "", NULL,/***/
115 "0x71", "0x71", "0x71", /**/"", "", "", NULL,/***/
116 "0x72", "0x72", "0x72", /**/"", "", "", NULL,/***/
117 "0x73", "0x73", "0x73", /**/"", "", "", NULL,/***/
118 "0x74", "0x74", "0x74", /**/"", "", "", NULL,/***/
119 "0x75", "0x75", "0x75", /**/"", "", "", NULL,/***/
120 "0x76", "0x76", "0x76", /**/"", "", "", NULL,/***/
121 "Pause", "Pause", "Pause", /**/"", "", "", NULL,/***/
122 "0x78", "0x78", "0x78", /**/"", "", "", NULL,/***/
123 "0x79", "0x79", "0x79", /**/"", "", "", NULL,/***/
124 "0x7a", "0x7a", "0x7a", /**/"", "", "", NULL,/***/
125 "0x7b", "0x7b", "0x7b", /**/"", "", "", NULL,/***/
126 "0x7c", "0x7c", "0x7c", /**/"", "", "", NULL,/***/
127 "Super_L", "Super_L", "Super_L", /**/"", "", "", NULL,/***/
128 "Super_R", "Super_R", "Super_R", /**/"", "", "", NULL,/***/
129 "0x7f", "0x7f", "0x7f", /**/"", "", "", NULL, /***/
diff --git a/src/lib/ecore_fb/ecore_fb_li.c b/src/lib/ecore_fb/ecore_fb_li.c
new file mode 100644
index 0000000000..0ea0549f92
--- /dev/null
+++ b/src/lib/ecore_fb/ecore_fb_li.c
@@ -0,0 +1,721 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdlib.h>
6
7#include "Ecore_Fb.h"
8#include "ecore_fb_private.h"
9
10#define CLICK_THRESHOLD_DEFAULT 0.25
11
12static Eina_List *_ecore_fb_li_devices = NULL;
13
14static const char *_ecore_fb_li_kbd_syms[128 * 7] =
15{
16#include "ecore_fb_keytable.h"
17};
18
19/* Initial Copyright (C) Brad Hards (1999-2002),
20 * this function is used to tell if "bit" is set in "array"
21 * it selects a byte from the array, and does a boolean AND
22 * operation with a byte that only has the relevant bit set.
23 * eg. to check for the 12th bit, we do (array[1] & 1<<4).
24 * Moved to static inline in order to force compiler to otimized
25 * the unsued part away or force a link error if long has an unexpected
26 * size.
27 * - bigeasy
28 */
29extern int long_has_neither_32_nor_64_bits(void);
30static inline int
31test_bit(int bit, unsigned long *array)
32{
33 if (sizeof(long) == 4)
34 return array[bit / 32] & (1 << (bit % 32));
35 else if (sizeof(long) == 8)
36 return array[bit / 64] & (1 << (bit % 64));
37 else long_has_neither_32_nor_64_bits();
38}
39
40static void
41_ecore_fb_li_device_event_key(Ecore_Fb_Input_Device *dev, struct input_event *iev)
42{
43 if (!dev->listen) return;
44
45 /* check for basic keyboard keys */
46 if ((iev->code >= KEY_ESC) && (iev->code <= KEY_COMPOSE))
47 {
48 int offset = 0;
49 const char *keyname = _ecore_fb_li_kbd_syms[iev->code * 7];
50
51 /* check the key table */
52 if (iev->value)
53 {
54 /* its a repeated key, dont increment */
55 if (iev->value != 2)
56 {
57 if (!strcmp(keyname, "Control_L"))
58 dev->keyboard.ctrl++;
59 else if (!strcmp(keyname, "Control_R"))
60 dev->keyboard.ctrl++;
61 else if (!strcmp(keyname, "Alt_L"))
62 dev->keyboard.alt++;
63 else if (!strcmp(keyname, "Alt_R"))
64 dev->keyboard.alt++;
65 else if (!strcmp(keyname, "Shift_L"))
66 dev->keyboard.shift++;
67 else if (!strcmp(keyname, "Shift_R"))
68 dev->keyboard.shift++;
69 else if (!strcmp(keyname, "Caps_Lock"))
70 dev->keyboard.lock = !dev->keyboard.lock;
71 if (dev->keyboard.ctrl > 2) dev->keyboard.ctrl = 2;
72 if (dev->keyboard.alt > 2) dev->keyboard.alt = 2;
73 if (dev->keyboard.shift > 2) dev->keyboard.shift = 2;
74 if (dev->keyboard.lock > 1) dev->keyboard.lock = 1;
75 }
76 }
77 else
78 {
79 if (!strcmp(keyname, "Control_L"))
80 dev->keyboard.ctrl--;
81 else if (!strcmp(keyname, "Control_R"))
82 dev->keyboard.ctrl--;
83 else if (!strcmp(keyname, "Alt_L"))
84 dev->keyboard.alt--;
85 else if (!strcmp(keyname, "Alt_R"))
86 dev->keyboard.alt--;
87 else if (!strcmp(keyname, "Shift_L"))
88 dev->keyboard.shift--;
89 else if (!strcmp(keyname, "Shift_R"))
90 dev->keyboard.shift--;
91 if (dev->keyboard.ctrl < 0) dev->keyboard.ctrl = 0;
92 if (dev->keyboard.alt < 0) dev->keyboard.alt = 0;
93 if (dev->keyboard.shift < 0) dev->keyboard.shift = 0;
94 if (dev->keyboard.lock < 0) dev->keyboard.lock = 0;
95 }
96
97 /* sending ecore_input_evas events */
98 Ecore_Event_Key *e;
99
100 if (dev->keyboard.shift) offset = 1;
101 else if (dev->keyboard.lock) offset = 2;
102
103 const char *key = _ecore_fb_li_kbd_syms[(iev->code * 7) + offset];
104 const char *compose = _ecore_fb_li_kbd_syms[(iev->code * 7) + 3 + offset];
105
106 if (dev->keyboard.ctrl)
107 {
108 const char *ts = _ecore_fb_li_kbd_syms[(iev->code * 7) + 3 + 3];
109
110 if (ts) compose = ts;
111 }
112
113 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) +
114 strlen(keyname) + (compose ? strlen(compose) : 0) + 3);
115 e->keyname = (char *)(e + 1);
116 e->key = e->keyname + strlen(keyname) + 1;
117 e->compose = (compose) ? e->key + strlen(key) + 1 : NULL;
118 e->string = e->compose;
119
120 strcpy((char *)e->keyname, keyname);
121 strcpy((char *)e->key, key);
122 if (compose)
123 strcpy((char *)e->compose, compose);
124
125 e->modifiers = 0;
126 if (dev->keyboard.shift)
127 e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
128 if (dev->keyboard.ctrl) e->modifiers |= ECORE_EVENT_MODIFIER_CTRL;
129 if (dev->keyboard.alt) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
130 if (dev->keyboard.lock) e->modifiers |= ECORE_EVENT_LOCK_CAPS;
131
132 e->timestamp = ecore_loop_time_get() * 1000.0;
133 e->window = (Ecore_Window)dev->window;
134 e->event_window = (Ecore_Window)dev->window;
135 e->root_window = (Ecore_Window)dev->window;
136 e->same_screen = 1;
137
138 if (iev->value)
139 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
140 else
141 ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
142 }
143 /* check for mouse button events */
144 else if ((iev->code >= BTN_MOUSE) && (iev->code < BTN_JOYSTICK))
145 {
146 int button;
147 Ecore_Event_Mouse_Button *e;
148 double current = ecore_loop_time_get();
149
150 button = ((iev->code & 0x00F) + 1);
151 // swap 2 and 3 to make middle and right butotn work right.
152 if (button == 3) button = 2;
153 else if (button == 2) button = 3;
154 if (iev->value)
155 {
156 dev->mouse.did_double = EINA_FALSE;
157 dev->mouse.did_triple = EINA_FALSE;
158
159 if (((current - dev->mouse.prev) <= dev->mouse.threshold) &&
160 (button == dev->mouse.prev_button))
161 {
162 dev->mouse.did_double = EINA_TRUE;
163 if (((current - dev->mouse.last) <= (2 * dev->mouse.threshold)) &&
164 (button == dev->mouse.last_button))
165 {
166 dev->mouse.did_triple = EINA_TRUE;
167 /* reset */
168 dev->mouse.prev = 0;
169 dev->mouse.last = 0;
170 current = 0;
171 }
172 }
173 dev->mouse.last = dev->mouse.prev;
174 dev->mouse.prev = current;
175 dev->mouse.last_button = dev->mouse.prev_button;
176 dev->mouse.prev_button = button;
177 }
178
179 e = calloc(1, sizeof(Ecore_Event_Mouse_Button));
180 if (!e)
181 return;
182
183 e->timestamp = current * 1000.0;
184 e->window = (Ecore_Window)dev->window;
185 e->event_window = (Ecore_Window)dev->window;
186 e->root_window = (Ecore_Window)dev->window;
187 e->same_screen = 1;
188
189 e->modifiers = 0;
190 if (dev->keyboard.shift)
191 e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
192 if (dev->keyboard.ctrl) e->modifiers |= ECORE_EVENT_MODIFIER_CTRL;
193 if (dev->keyboard.alt) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
194 if (dev->keyboard.lock) e->modifiers |= ECORE_EVENT_LOCK_CAPS;
195
196 e->x = dev->mouse.x;
197 e->y = dev->mouse.y;
198 e->root.x = e->x;
199 e->root.y = e->y;
200 e->buttons = button;
201
202 if (dev->mouse.did_double)
203 e->double_click = 1;
204 if (dev->mouse.did_triple)
205 e->triple_click = 1;
206
207 if (iev->value)
208 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, e, NULL, NULL);
209 else
210 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, e, NULL, NULL);
211 }
212}
213
214static void
215_ecore_fb_li_device_event_rel(Ecore_Fb_Input_Device *dev, struct input_event *iev)
216{
217 if (!dev->listen) return;
218 /* dispatch the button events if they are queued */
219 switch (iev->code)
220 {
221 case REL_X:
222 case REL_Y:
223 {
224 Ecore_Event_Mouse_Move *e;
225 if (iev->code == REL_X)
226 {
227 dev->mouse.x += iev->value;
228 if (dev->mouse.x > dev->mouse.w - 1)
229 dev->mouse.x = dev->mouse.w;
230 else if(dev->mouse.x < 0)
231 dev->mouse.x = 0;
232 }
233 else
234 {
235 dev->mouse.y += iev->value;
236 if (dev->mouse.y > dev->mouse.h - 1)
237 dev->mouse.y = dev->mouse.h;
238 else if(dev->mouse.y < 0)
239 dev->mouse.y = 0;
240 }
241
242 e = calloc(1, sizeof(Ecore_Event_Mouse_Move));
243 if (!e)
244 return;
245
246 e->window = (Ecore_Window)dev->window;
247 e->event_window = (Ecore_Window)dev->window;
248 e->root_window = (Ecore_Window)dev->window;
249 e->same_screen = 1;
250
251 e->modifiers = 0;
252 if (dev->keyboard.shift) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
253 if (dev->keyboard.ctrl) e->modifiers |= ECORE_EVENT_MODIFIER_CTRL;
254 if (dev->keyboard.alt) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
255 if (dev->keyboard.lock) e->modifiers |= ECORE_EVENT_LOCK_CAPS;
256
257 e->x = dev->mouse.x;
258 e->y = dev->mouse.y;
259 e->root.x = e->x;
260 e->root.y = e->y;
261
262 e->timestamp = ecore_loop_time_get() * 1000.0;
263
264 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
265
266 break;
267 }
268 case REL_WHEEL:
269 case REL_HWHEEL:
270 {
271 Ecore_Event_Mouse_Wheel *e;
272
273 e = calloc(1, sizeof(Ecore_Event_Mouse_Wheel));
274 if (!e)
275 return;
276
277 e->x = dev->mouse.x;
278 e->y = dev->mouse.y;
279 if (iev->code == REL_HWHEEL) e->direction = 1;
280 e->z = iev->value;
281 e->root.x = dev->mouse.x;
282 e->root.y = dev->mouse.y;
283
284 e->window = (Ecore_Window)dev->window;
285 e->event_window = (Ecore_Window)dev->window;
286 e->root_window = (Ecore_Window)dev->window;
287 e->same_screen = 1;
288
289 e->modifiers = 0;
290 if (dev->keyboard.shift) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
291 if (dev->keyboard.ctrl) e->modifiers |= ECORE_EVENT_MODIFIER_CTRL;
292 if (dev->keyboard.alt) e->modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
293 if (dev->keyboard.lock) e->modifiers |= ECORE_EVENT_LOCK_CAPS;
294
295 e->timestamp = ecore_loop_time_get() * 1000.0;
296
297 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, e, NULL, NULL);
298
299 break;
300 }
301 default:
302 break;
303 }
304}
305
306static void
307_ecore_fb_li_device_event_abs(Ecore_Fb_Input_Device *dev, struct input_event *iev)
308{
309 static int prev_pressure = 0;
310 int pressure;
311
312 if (!dev->listen) return;
313 switch (iev->code)
314 {
315 case ABS_X:
316 if (dev->mouse.w != 0)
317 {
318 int tmp;
319
320 tmp = (int)((double)(iev->value - dev->mouse.min_w) / dev->mouse.rel_w);
321 if (tmp < 0) dev->mouse.x = 0;
322 else if (tmp > dev->mouse.w) dev->mouse.x = dev->mouse.w;
323 else dev->mouse.x = tmp;
324 dev->mouse.event = ECORE_EVENT_MOUSE_MOVE;
325 }
326 break;
327
328 case ABS_Y:
329 if (dev->mouse.h != 0)
330 {
331 int tmp;
332
333 tmp = (int)((double)(iev->value - dev->mouse.min_h) / dev->mouse.rel_h);
334 if (tmp < 0) dev->mouse.y = 0;
335 else if (tmp > dev->mouse.h) dev->mouse.y = dev->mouse.h;
336 else dev->mouse.y = tmp;
337 dev->mouse.event = ECORE_EVENT_MOUSE_MOVE;
338 }
339 break;
340
341 case ABS_PRESSURE:
342 pressure = iev->value;
343 if ((pressure) && (!prev_pressure))
344 {
345 /* DOWN: mouse is down, but was not before */
346 dev->mouse.event = ECORE_EVENT_MOUSE_BUTTON_DOWN;
347 }
348 else if ((!pressure) && (prev_pressure))
349 {
350 /* UP: mouse was down, but is not now */
351 dev->mouse.event = ECORE_EVENT_MOUSE_BUTTON_UP;
352 }
353 prev_pressure = pressure;
354 break;
355 }
356}
357
358static void
359_ecore_fb_li_device_event_syn(Ecore_Fb_Input_Device *dev, struct input_event *iev EINA_UNUSED)
360{
361 if (!dev->listen) return;
362
363 if (dev->mouse.event == ECORE_EVENT_MOUSE_MOVE)
364 {
365 Ecore_Event_Mouse_Move *ev;
366 ev = calloc(1,sizeof(Ecore_Event_Mouse_Move));
367 ev->x = dev->mouse.x;
368 ev->y = dev->mouse.y;
369 ev->root.x = ev->x;
370 ev->root.y = ev->y;
371 ev->timestamp = ecore_loop_time_get() * 1000.0;
372 }
373 else if (dev->mouse.event == ECORE_EVENT_MOUSE_BUTTON_DOWN)
374 {
375 Ecore_Event_Mouse_Button *ev;
376 ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
377 ev->x = dev->mouse.x;
378 ev->y = dev->mouse.y;
379 ev->root.x = ev->x;
380 ev->root.y = ev->y;
381 ev->buttons = 1;
382 ev->timestamp = ecore_loop_time_get() * 1000.0;
383 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
384 }
385 else if (dev->mouse.event == ECORE_EVENT_MOUSE_BUTTON_UP)
386 {
387 Ecore_Event_Mouse_Button *ev;
388 ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
389 ev->x = dev->mouse.x;
390 ev->y = dev->mouse.y;
391 ev->root.x = ev->x;
392 ev->root.y = ev->y;
393 ev->buttons = 1;
394 ev->timestamp = ecore_loop_time_get() * 1000.0;
395 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
396 }
397}
398
399static Eina_Bool
400_ecore_fb_li_device_fd_callback(void *data, Ecore_Fd_Handler *fdh EINA_UNUSED)
401{
402 Ecore_Fb_Input_Device *dev;
403 struct input_event ev[64];
404 int len;
405 int i;
406
407 dev = (Ecore_Fb_Input_Device*)data;
408 /* read up to 64 events at once */
409 len = read(dev->fd, &ev, sizeof(ev));
410 for(i = 0; i < (int)(len / sizeof(ev[0])); i++)
411 {
412 switch(ev[i].type)
413 {
414 case EV_SYN:
415 _ecore_fb_li_device_event_syn(dev, &ev[i]);
416 break;
417 case EV_ABS:
418 _ecore_fb_li_device_event_abs(dev, &ev[i]);
419 break;
420 case EV_REL:
421 _ecore_fb_li_device_event_rel(dev, &ev[i]);
422 break;
423 case EV_KEY:
424 _ecore_fb_li_device_event_key(dev, &ev[i]);
425 break;
426 default:
427 break;
428 }
429 }
430 return EINA_TRUE;
431}
432
433/**
434 * @addtogroup Ecore_FB_Group Ecore_FB - Frame buffer convenience functions.
435 *
436 * @{
437 */
438
439/**
440 * @brief Set the listen mode for an input device .
441 *
442 * @param dev The device to set the mode of.
443 * @param listen @c EINA_FALSE to disable listening mode, @c EINA_TRUE to
444 * enable it.
445 *
446 * This function enables or disables listening on the input device @p dev.
447 * If @p listen is @c EINA_FALSE, listening mode is disabled, if it is
448 * @c EINA_TRUE, it is enabled.
449 */
450EAPI void
451ecore_fb_input_device_listen(Ecore_Fb_Input_Device *dev, Eina_Bool listen)
452{
453 if (!dev) return;
454 if ((listen && dev->listen) || (!listen && !dev->listen)) return;
455 if (listen)
456 {
457 /* if the device already had a handler */
458 if (!dev->handler)
459 dev->handler = ecore_main_fd_handler_add(dev->fd, ECORE_FD_READ, _ecore_fb_li_device_fd_callback, dev, NULL, NULL);
460
461 }
462 dev->listen = listen;
463}
464
465#ifndef EV_CNT
466# define EV_CNT (EV_MAX+1)
467#endif
468
469/**
470 * @brief Associates an input device with the given @ref Ecore_Evas_Group.
471 *
472 * @param dev The input being associated with an @ref Ecore_Evas_Group (not @c NULL).
473 * @param window The window which this input is being associated to.
474 * @c NULL will remove any previous association.
475 *
476 * Events generated by this device will have a pointer to @p window. If this @p
477 * window is registered with ecore_event_window_register() or
478 * ecore_evas_input_event_register(), respective evas events will be delivered
479 * by the ecore_input_evas system. An example can be seen in the following code:
480 *
481 * @code
482 * Ecore_Evas *ee = ecore_evas_new(NULL, 0, 0, 800, 600, NULL);
483 *
484 * ecore_evas_input_event_register(ee);
485 *
486 * device = ecore_fb_input_device_open(device_path);
487 * if (device)
488 * ecore_fb_input_device_window_set(device, ee);
489 *
490 * @endcode
491 *
492 * On the previous code, all input captured on the mentioned device will be
493 * delivered to the @c Ecore_Evas @c ee.
494 *
495 * @since 1.1
496 */
497EAPI void
498ecore_fb_input_device_window_set(Ecore_Fb_Input_Device *dev, void *window)
499{
500 if (!dev) return;
501
502 dev->window = window;
503}
504
505/**
506 * @brief Open an input device.
507 *
508 * @param dev The device to open.
509 * @return The @ref Ecore_Fb_Input_Device object that has been opened.
510 *
511 * This function opens the input device named @p dev and returns the
512 * object for it, or returns @c NULL on failure.
513 */
514EAPI Ecore_Fb_Input_Device *
515ecore_fb_input_device_open(const char *dev)
516{
517 Ecore_Fb_Input_Device *device;
518 unsigned long event_type_bitmask[EV_CNT / 32 + 1];
519 int event_type;
520 int fd;
521
522 if (!dev) return NULL;
523 device = calloc(1, sizeof(Ecore_Fb_Input_Device));
524 if (!device) return NULL;
525
526 if ((fd = open(dev, O_RDONLY, O_NONBLOCK)) < 0)
527 {
528 fprintf(stderr, "[ecore_fb_li:device_open] %s %s", dev, strerror(errno));
529 goto error_open;
530 }
531 /* query capabilities */
532 if (ioctl(fd, EVIOCGBIT(0, EV_MAX), event_type_bitmask) < 0)
533 {
534 fprintf(stderr,"[ecore_fb_li:device_open] query capabilities %s %s", dev, strerror(errno));
535 goto error_caps;
536 }
537 /* query name */
538 device->info.name = calloc(256, sizeof(char));
539 if (ioctl(fd, EVIOCGNAME(sizeof(char) * 256), device->info.name) < 0)
540 {
541 fprintf(stderr, "[ecore_fb_li:device_open] get name %s %s", dev, strerror(errno));
542 strcpy(device->info.name, "Unknown");
543 }
544 device->fd = fd;
545 device->info.dev = strdup(dev);
546 /* common */
547 device->mouse.threshold = CLICK_THRESHOLD_DEFAULT;
548
549 /* set info */
550 for (event_type = 0; event_type < EV_MAX; event_type++)
551 {
552 if (!test_bit(event_type, event_type_bitmask))
553 continue;
554 switch (event_type)
555 {
556 case EV_SYN:
557 break;
558 case EV_KEY:
559 device->info.cap |= ECORE_FB_INPUT_DEVICE_CAP_KEYS_OR_BUTTONS;
560 break;
561 case EV_REL:
562 device->info.cap |= ECORE_FB_INPUT_DEVICE_CAP_RELATIVE;
563 break;
564 case EV_ABS:
565 device->info.cap |= ECORE_FB_INPUT_DEVICE_CAP_ABSOLUTE;
566 break;
567 case EV_MSC:
568 case EV_LED:
569 case EV_SND:
570 case EV_REP:
571 case EV_FF :
572 case EV_FF_STATUS:
573 case EV_PWR:
574 default:
575 break;
576 }
577 }
578
579 _ecore_fb_li_devices = eina_list_append(_ecore_fb_li_devices, device);
580 return device;
581
582error_caps:
583 close(fd);
584error_open:
585 free(device);
586 return NULL;
587}
588
589/**
590 * @brief Close the given device.
591 *
592 * @param dev The device to close
593 *
594 * This function closes the device @p dev. If @p dev is @c NULL, this
595 * function does nothing.
596 */
597EAPI void
598ecore_fb_input_device_close(Ecore_Fb_Input_Device *dev)
599{
600 if (!dev || dev->fd < 0) return;
601 /* close the fd */
602 close(dev->fd);
603 /* remove the element from the list */
604 _ecore_fb_li_devices = eina_list_remove(_ecore_fb_li_devices, dev);
605 free(dev);
606}
607
608
609/**
610 * @brief Set the axis size of the given device.
611 *
612 * @param dev The device to set the axis size to.
613 * @param w The width of the axis.
614 * @param h The height of the axis.
615 *
616 * This function sets set the width @p w and height @p h of the axis
617 * of device @p dev. If @p dev is a relative input device, a width and
618 * height must set for it. If its absolute set the ioctl correctly, if
619 * not, unsupported device.
620 */
621EAPI void
622ecore_fb_input_device_axis_size_set(Ecore_Fb_Input_Device *dev, int w, int h)
623{
624 if (!dev) return;
625 if ((w < 0) || (h < 0)) return;
626 /* FIXME
627 * this code is for a touchscreen device,
628 * make it configurable (ABSOLUTE | RELATIVE)
629 */
630 if (dev->info.cap & ECORE_FB_INPUT_DEVICE_CAP_ABSOLUTE)
631 {
632 /* FIXME looks like some kernels dont include this struct */
633 struct input_absinfo abs_features;
634
635 ioctl(dev->fd, EVIOCGABS(ABS_X), &abs_features);
636 dev->mouse.min_w = abs_features.minimum;
637 dev->mouse.rel_w = (double)(abs_features.maximum - abs_features.minimum)/(double)(w);
638
639 ioctl(dev->fd, EVIOCGABS(ABS_Y), &abs_features);
640 dev->mouse.min_h = abs_features.minimum;
641 dev->mouse.rel_h = (double)(abs_features.maximum - abs_features.minimum)/(double)(h);
642 }
643 else if (!(dev->info.cap & ECORE_FB_INPUT_DEVICE_CAP_RELATIVE))
644 return;
645
646 /* update the local values */
647 if (dev->mouse.x > w - 1) dev->mouse.x = w -1;
648 if (dev->mouse.y > h - 1) dev->mouse.y = h -1;
649 dev->mouse.w = w;
650 dev->mouse.h = h;
651}
652
653/**
654 * @brief Retrieve the name of the given device.
655 *
656 * @param dev The device to get the name from.
657 * @return The name of the device.
658 *
659 * This function returns the name of the device @p dev. If @p dev is
660 * @c NULL, this function returns @c NULL.
661 */
662EAPI const char *
663ecore_fb_input_device_name_get(Ecore_Fb_Input_Device *dev)
664{
665 if (!dev) return NULL;
666 return dev->info.name;
667}
668
669/**
670 * @brief Retrieve the capability of the given device.
671 *
672 * @param dev The device to get the name from.
673 * @return The capability of the device.
674 *
675 * This function returns the capability of the device @p dev. If @p dev is
676 * @c NULL, this function returns ECORE_FB_INPUT_DEVICE_CAP_NONE.
677 */
678EAPI Ecore_Fb_Input_Device_Cap
679ecore_fb_input_device_cap_get(Ecore_Fb_Input_Device *dev)
680{
681 if (!dev) return ECORE_FB_INPUT_DEVICE_CAP_NONE;
682 return dev->info.cap;
683}
684
685/**
686 * @brief Set the threshold of mouse clicks of the given device.
687 *
688 * @param dev The device to set the threshodl mouse click to.
689 * @param threshold The threshold value.
690 *
691 * This function sets the threshold of mouse clicks of the device
692 * @p dev to @p threshold. If @p dev is @c NULL, this function does
693 * nothing.
694 */
695EAPI void
696ecore_fb_input_device_threshold_click_set(Ecore_Fb_Input_Device *dev, double threshold)
697{
698 if (!dev) return;
699 if ((threshold == dev->mouse.threshold) || (threshold == 0)) return;
700 dev->mouse.threshold = threshold;
701}
702
703/**
704 * @brief Get the threshold of mouse clicks of the given device.
705 *
706 * @param dev The device to set the threshodl mouse click from.
707 * @return The threshold value.
708 *
709 * This function returns the threshold of mouse clicks of the device
710 * @p dev. If @p dev is @c NULL, this function returns 0.0.
711 */
712EAPI double
713ecore_fb_input_device_threshold_click_get(Ecore_Fb_Input_Device *dev)
714{
715 if (!dev) return 0;
716 return dev->mouse.threshold;
717}
718
719/**
720 * @}
721 */
diff --git a/src/lib/ecore_fb/ecore_fb_private.h b/src/lib/ecore_fb/ecore_fb_private.h
new file mode 100644
index 0000000000..797f86305f
--- /dev/null
+++ b/src/lib/ecore_fb/ecore_fb_private.h
@@ -0,0 +1,94 @@
1#ifndef _ECORE_FB_PRIVATE_H
2#define _ECORE_FB_PRIVATE_H
3
4#include "Ecore.h"
5#include "ecore_private.h"
6#include "Ecore_Input.h"
7
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <unistd.h>
12#include <termios.h>
13#include <sys/types.h>
14#include <sys/stat.h>
15#include <sys/ioctl.h>
16#include <linux/version.h>
17#include <linux/kd.h>
18#include <linux/vt.h>
19#include <linux/fb.h>
20#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
21 #define kernel_ulong_t unsigned long
22 #define BITS_PER_LONG 32
23 #include <linux/input.h>
24 #undef kernel_ulong_t
25 #undef BITS_PER_LONG
26#else
27 #include <linux/input.h>
28#endif
29
30#include <signal.h>
31#include <fcntl.h>
32#include <errno.h>
33
34#include <Ecore_Fb.h>
35
36/* ecore_fb_li.c */
37struct _Ecore_Fb_Input_Device
38{
39 int fd;
40 Ecore_Fd_Handler *handler;
41 int listen;
42 struct {
43 Ecore_Fb_Input_Device_Cap cap;
44 char *name;
45 char *dev;
46 } info;
47 struct
48 {
49 /* common mouse */
50 int x,y;
51 int w,h;
52
53 double last;
54 double prev;
55 double threshold;
56 Eina_Bool did_double;
57 Eina_Bool did_triple;
58 /* absolute axis */
59 int min_w, min_h;
60 double rel_w, rel_h;
61 int event;
62 int prev_button;
63 int last_button;
64 } mouse;
65 struct
66 {
67 int shift;
68 int ctrl;
69 int alt;
70 int lock;
71 } keyboard;
72 void *window;
73};
74
75/* ecore_fb_ts.c */
76EAPI int ecore_fb_ts_init(void);
77EAPI void ecore_fb_ts_shutdown(void);
78EAPI void ecore_fb_ts_events_window_set(void *window);
79EAPI void *ecore_fb_ts_events_window_get(void);
80EAPI void ecore_fb_ts_event_window_set(void *window);
81
82/* ecore_fb_vt.c */
83int ecore_fb_vt_init(void);
84void ecore_fb_vt_shutdown(void);
85
86/* hacks to stop people NEEDING #include <linux/h3600_ts.h> */
87#ifndef TS_SET_CAL
88#define TS_SET_CAL 0x4014660b
89#endif
90#ifndef TS_GET_CAL
91#define TS_GET_CAL 0x8014660a
92#endif
93
94#endif
diff --git a/src/lib/ecore_fb/ecore_fb_ps2.c b/src/lib/ecore_fb/ecore_fb_ps2.c
new file mode 100644
index 0000000000..53aa302fef
--- /dev/null
+++ b/src/lib/ecore_fb/ecore_fb_ps2.c
@@ -0,0 +1,223 @@
1typedef struct _Ecore_Fb_Ps2_Event Ecore_Fb_Ps2_Event;
2struct _Ecore_Fb_Ps2_Event
3{
4 unsigned char button;
5 unsigned char x;
6 unsigned char y;
7 unsigned char z;
8};
9
10static int _ecore_fb_ps2_event_byte_count = 0;
11static Ecore_Fb_Ps2_Event _ecore_fb_ps2_event;
12static int _ecore_fb_ps2_fd = 0;
13static Eina_Bool _ecore_fb_ps2_fd_handler(void *data, Ecore_Fd_Handler *fd_handler);
14
15int
16ecore_fb_ps2_init(void)
17{
18 _ecore_fb_ps2_fd = open("/dev/psaux", O_RDWR);
19 if (_ecore_fb_ps2_fd >= 0)
20 {
21 prev_flags = fcntl(_ecore_fb_ps2_fd, F_GETFL);
22 fcntl(_ecore_fb_ps2_fd, F_SETFL, prev_flags | O_NONBLOCK);
23 _ecore_fb_ts_fd_handler_handle = ecore_main_fd_handler_add(_ecore_fb_ps2_fd,
24 ECORE_FD_READ,
25 _ecore_fb_ps2_fd_handler, NULL, NULL, NULL);
26 if (!_ecore_fb_ts_fd_handler_handle)
27 {
28 close(_ecore_fb_ps2_fd);
29 return 0;
30 }
31 return 1;
32 }
33 return 0;
34}
35
36void
37ecore_fb_ps2_shutdown(void)
38{
39 if (_ecore_fb_ps2_fd > 0) close(_ecore_fb_ps2_fd);
40 _ecore_fb_ps2_fd = 0;
41}
42
43static Eina_Bool
44_ecore_fb_ps2_fd_handler(void *data EINA_UNUSED, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
45{
46 static int prev_x = 0, prev_y = 0, prev_button = 0;
47 static double last_time = 0;
48 static double last_last_time = 0;
49 int v = 0;
50
51 do
52 {
53 int x, y, button, i;
54 int num;
55 char *ptr;
56 double t;
57 static int did_double = 0;
58 static int did_triple = 0;
59
60 ptr = (char *)&(_ecore_fb_ps2_event);
61 ptr += _ecore_fb_ps2_event_byte_count;
62 num = sizeof(Ecore_Fb_Ps2_Event) - _ecore_fb_ps2_event_byte_count;
63 v = read(_ecore_fb_ps2_fd, ptr, num);
64 if (v < 0) return EINA_TRUE;
65 _ecore_fb_ps2_event_byte_count += v;
66 if (v < num) return EINA_TRUE;
67 t = ecore_loop_time_get();
68 _ecore_fb_ps2_event_byte_count = 0;
69 if (_ecore_fb_ps2_event.button & 0x10)
70 x = prev_x + (0xffffff00 | _ecore_fb_ps2_event.x);
71 else
72 x = prev_x + _ecore_fb_ps2_event.x;
73 if (_ecore_fb_ps2_event.button & 0x20)
74 y = prev_y - (0xffffff00 | _ecore_fb_ps2_event.y);
75 else
76 y = prev_y - _ecore_fb_ps2_event.y;
77 button = _ecore_fb_ps2_event.button & 0x7;
78 if (x < 0) x = 0;
79 if (y < 0) y = 0;
80 if (x >= _ecore_fb_console_w) x = _ecore_fb_console_w - 1;
81 if (y >= _ecore_fb_console_h) y = _ecore_fb_console_h - 1;
82 /* add event to queue */
83 /* always add a move event */
84 if (1)
85 {
86 /* MOVE: mouse is down and was */
87 Ecore_Event_Mouse_Move *e;
88
89 e = calloc(1, sizeof(Ecore_Fb_Event_Mouse_Move));
90 if (!e) goto retry;
91 e->x = x;
92 e->y = y;
93 e->root.x = e->x;
94 e->root.y = e->y;
95 e->window = 1;
96 e->event_window = e->window;
97 e->root_window = e->window;
98 e->same_screen = 1;
99 e->timestamp = ecore_loop_time_get() * 1000.0;
100 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
101 }
102 for (i = 1; i <= 3; i++)
103 {
104 int mask;
105
106 mask = 1 << (i - 1);
107 if (((button & mask)) && (!(prev_button & mask)))
108 {
109 /* DOWN: mouse is down, but was not now */
110 Ecore_Event_Mouse_Button *e;
111
112 e = calloc(1, sizeof(Ecore_Event_Mouse_Button));
113 if (!e) goto retry;
114 e->x = x;
115 e->y = y;
116 e->root.x = e->x;
117 e->root.y = e->y;
118 e->button = i;
119 e->window = 1;
120 e->event_window = e->window;
121 e->root_window = e->window;
122 e->same_screen = 1;
123 if ((t - last_time) <= _ecore_fb_double_click_time)
124 {
125 e->double_click = 1;
126 did_double = 1;
127 }
128 else
129 {
130 did_double = 0;
131 did_triple = 0;
132 }
133 if ((t - last_last_time) <= (2 * _ecore_fb_double_click_time))
134 {
135 did_triple = 1;
136 e->triple_click = 1;
137 }
138 else
139 {
140 did_triple = 0;
141 }
142 e->timestamp = ecore_loop_time_get() * 1000.0;
143 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, e, NULL, NULL);
144 }
145 else if ((!(button & mask)) && ((prev_button & mask)))
146 {
147 /* UP: mouse was down, but is not now */
148 Ecore_Event_Mouse_Button *e;
149
150 e = calloc(1, sizeof(Ecore_Event_Mouse_Button));
151 if (!e) goto retry;
152 e->x = x;
153 e->y = y;
154 e->root.x = e->x;
155 e->root.y = e->y;
156 e->button = i;
157 e->window = 1;
158 e->event_window = e->window;
159 e->root_window = e->window;
160 e->same_screen = 1;
161 if (did_double)
162 e->double_click = 1;
163 if (did_triple)
164 e->triple_click = 1;
165 e->timestamp = ecore_loop_time_get() * 1000.0;
166 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, e, NULL, NULL);
167 }
168 }
169 if (did_triple)
170 {
171 last_time = 0;
172 last_last_time = 0;
173 }
174 else
175 {
176 last_last_time = last_time;
177 last_time = t;
178 }
179 retry:
180 prev_x = x;
181 prev_y = y;
182 prev_button = button;
183 }
184 while (v > 0);
185 return EINA_TRUE;
186}
187/**
188 * @defgroup Ecore_FB_Click_Group Framebuffer Double Click Functions
189 *
190 * Functions that deal with the double click time of the framebuffer.
191 */
192
193/**
194 * Sets the timeout for a double and triple clicks to be flagged.
195 *
196 * This sets the time between clicks before the double_click flag is
197 * set in a button down event. If 3 clicks occur within double this
198 * time, the triple_click flag is also set.
199 *
200 * @param t The time in seconds
201 * @ingroup Ecore_FB_Click_Group
202 */
203EAPI void
204ecore_fb_double_click_time_set(double t)
205{
206 if (t < 0.0) t = 0.0;
207 _ecore_fb_double_click_time = t;
208}
209
210/**
211 * Retrieves the double and triple click flag timeout.
212 *
213 * See @ref ecore_x_double_click_time_set for more information.
214 *
215 * @return The timeout for double clicks in seconds.
216 * @ingroup Ecore_FB_Click_Group
217 */
218EAPI double
219ecore_fb_double_click_time_get(void)
220{
221 return _ecore_fb_double_click_time;
222}
223
diff --git a/src/lib/ecore_fb/ecore_fb_ts.c b/src/lib/ecore_fb/ecore_fb_ts.c
new file mode 100644
index 0000000000..ce9c733c3e
--- /dev/null
+++ b/src/lib/ecore_fb/ecore_fb_ts.c
@@ -0,0 +1,362 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#ifdef HAVE_TSLIB
6# include <tslib.h>
7# include <errno.h>
8#endif
9
10#include "Ecore_Fb.h"
11#include "ecore_fb_private.h"
12
13typedef struct _Ecore_Fb_Ts_Event Ecore_Fb_Ts_Event;
14typedef struct _Ecore_Fb_Ts_Calibrate Ecore_Fb_Ts_Calibrate;
15typedef struct _Ecore_Fb_Ts_Backlight Ecore_Fb_Ts_Backlight;
16typedef struct _Ecore_Fb_Ts_Contrast Ecore_Fb_Ts_Contrast;
17typedef struct _Ecore_Fb_Ts_Led Ecore_Fb_Ts_Led;
18typedef struct _Ecore_Fb_Ts_Flite Ecore_Fb_Ts_Flite;
19
20struct _Ecore_Fb_Ts_Event
21{
22 unsigned short pressure;
23 unsigned short x;
24 unsigned short y;
25 unsigned short _unused;
26};
27
28struct _Ecore_Fb_Ts_Calibrate
29{
30 int xscale;
31 int xtrans;
32 int yscale;
33 int ytrans;
34 int xyswap;
35};
36
37struct _Ecore_Fb_Ts_Backlight
38{
39 int on;
40 unsigned char brightness;
41};
42
43struct _Ecore_Fb_Ts_Contrast
44{
45 unsigned char contrast;
46};
47
48struct _Ecore_Fb_Ts_Led
49{
50 unsigned char on;
51 unsigned char blink_time;
52 unsigned char on_time;
53 unsigned char off_time;
54};
55
56struct _Ecore_Fb_Ts_Flite
57{
58 unsigned char mode;
59 unsigned char pwr;
60 unsigned char brightness;
61};
62
63static Eina_Bool _ecore_fb_ts_fd_handler(void *data, Ecore_Fd_Handler *fd_handler);
64static int _ecore_fb_ts_fd = -1;
65static int _ecore_fb_ts_event_byte_count = 0;
66static int _ecore_fb_ts_apply_cal = 0;
67static Ecore_Fb_Ts_Event _ecore_fb_ts_event;
68static Ecore_Fb_Ts_Calibrate _ecore_fb_ts_cal = {1,1,0,0,0};
69static Ecore_Fd_Handler *_ecore_fb_ts_fd_handler_handle = NULL;
70
71#ifdef HAVE_TSLIB
72struct tsdev *_ecore_fb_tslib_tsdev = NULL;
73struct ts_sample _ecore_fb_tslib_event;
74#endif
75
76static double _ecore_fb_double_click_time = 0.25;
77static void *_ecore_fb_ts_event_window = NULL;
78
79EAPI int
80ecore_fb_ts_init(void)
81{
82#ifdef HAVE_TSLIB
83 char *tslib_tsdevice = NULL;
84 if ( (tslib_tsdevice = getenv("TSLIB_TSDEVICE")) )
85 {
86 printf( "ECORE_FB: TSLIB_TSDEVICE = '%s'\n", tslib_tsdevice );
87 _ecore_fb_tslib_tsdev = ts_open( tslib_tsdevice, 1 ); /* 1 = nonblocking, 0 = blocking */
88
89 if ( !_ecore_fb_tslib_tsdev )
90 {
91 printf( "ECORE_FB: Can't ts_open (%s)\n", strerror( errno ) );
92 return 0;
93 }
94
95 if ( ts_config( _ecore_fb_tslib_tsdev ) )
96 {
97 printf( "ECORE_FB: Can't ts_config (%s)\n", strerror( errno ) );
98 return 0;
99 }
100 _ecore_fb_ts_fd = ts_fd( _ecore_fb_tslib_tsdev );
101 if ( _ecore_fb_ts_fd < 0 )
102 {
103 printf( "ECORE_FB: Can't open touchscreen (%s)\n", strerror( errno ) );
104 return 0;
105 }
106 }
107#else
108 _ecore_fb_ts_fd = open("/dev/touchscreen/0", O_RDONLY);
109#endif
110 if (_ecore_fb_ts_fd >= 0)
111 {
112 _ecore_fb_ts_fd_handler_handle = ecore_main_fd_handler_add(_ecore_fb_ts_fd,
113 ECORE_FD_READ,
114 _ecore_fb_ts_fd_handler, NULL,
115 NULL, NULL);
116 if (!_ecore_fb_ts_fd_handler_handle)
117 {
118 close(_ecore_fb_ts_fd);
119 return 0;
120 }
121 // FIXME _ecore_fb_kbd_fd = open("/dev/touchscreen/key", O_RDONLY);
122 return 1;
123 }
124 return 0;
125}
126
127EAPI void
128ecore_fb_ts_shutdown(void)
129{
130 if (_ecore_fb_ts_fd_handler_handle)
131 ecore_main_fd_handler_del(_ecore_fb_ts_fd_handler_handle);
132 if (_ecore_fb_ts_fd >= 0) close(_ecore_fb_ts_fd);
133 _ecore_fb_ts_fd = -1;
134 _ecore_fb_ts_fd_handler_handle = NULL;
135 _ecore_fb_ts_event_window = NULL;
136}
137
138EAPI void
139ecore_fb_ts_event_window_set(void *window)
140{
141 _ecore_fb_ts_event_window = window;
142}
143
144EAPI void *
145ecore_fb_ts_event_window_get(void)
146{
147 return _ecore_fb_ts_event_window;
148}
149
150/**
151 * @defgroup Ecore_FB_Calibrate_Group Framebuffer Calibration Functions
152 *
153 * Functions that calibrate the screen.
154 */
155
156
157/**
158 * Calibrates the touschreen using the given parameters.
159 * @param xscale X scaling, where 256 = 1.0
160 * @param xtrans X translation.
161 * @param yscale Y scaling.
162 * @param ytrans Y translation.
163 * @param xyswap Swap X & Y flag.
164 * @ingroup Ecore_FB_Calibrate_Group
165 */
166EAPI void
167ecore_fb_touch_screen_calibrate_set(int xscale, int xtrans, int yscale, int ytrans, int xyswap)
168{
169 Ecore_Fb_Ts_Calibrate cal;
170
171 if (_ecore_fb_ts_fd < 0) return;
172 cal.xscale = xscale;
173 cal.xtrans = xtrans;
174 cal.yscale = yscale;
175 cal.ytrans = ytrans;
176 cal.xyswap = xyswap;
177 if (ioctl(_ecore_fb_ts_fd, TS_SET_CAL, (void *)&cal))
178 {
179 _ecore_fb_ts_cal = cal;
180 _ecore_fb_ts_apply_cal = 1;
181 }
182}
183
184/**
185 * Retrieves the calibration parameters of the touchscreen.
186 * @param xscale Pointer to an integer in which to store the X scaling.
187 * Note that 256 = 1.0.
188 * @param xtrans Pointer to an integer in which to store the X translation.
189 * @param yscale Pointer to an integer in which to store the Y scaling.
190 * @param ytrans Pointer to an integer in which to store the Y translation.
191 * @param xyswap Pointer to an integer in which to store the Swap X & Y flag.
192 * @ingroup Ecore_FB_Calibrate_Group
193 */
194EAPI void
195ecore_fb_touch_screen_calibrate_get(int *xscale, int *xtrans, int *yscale, int *ytrans, int *xyswap)
196{
197 Ecore_Fb_Ts_Calibrate cal;
198
199 if (_ecore_fb_ts_fd < 0) return;
200 if (!_ecore_fb_ts_apply_cal)
201 {
202 if (ioctl(_ecore_fb_ts_fd, TS_GET_CAL, (void *)&cal))
203 _ecore_fb_ts_cal = cal;
204 }
205 else
206 cal = _ecore_fb_ts_cal;
207 if (xscale) *xscale = cal.xscale;
208 if (xtrans) *xtrans = cal.xtrans;
209 if (yscale) *yscale = cal.yscale;
210 if (ytrans) *ytrans = cal.ytrans;
211 if (xyswap) *xyswap = cal.xyswap;
212}
213
214static Eina_Bool
215_ecore_fb_ts_fd_handler(void *data EINA_UNUSED, Ecore_Fd_Handler *fd_handler EINA_UNUSED)
216{
217 static int prev_x = 0, prev_y = 0, prev_pressure = 0;
218 static double last_time = 0;
219 static double last_last_time = 0;
220 int v = 0;
221
222 do
223 {
224 int x, y, pressure;
225 int num;
226 char *ptr;
227 double t = 0.0;
228 static int did_double = 0;
229 static int did_triple = 0;
230
231#ifdef HAVE_TSLIB
232 if (_ecore_fb_ts_apply_cal)
233 num = ts_read_raw(_ecore_fb_tslib_tsdev, &_ecore_fb_tslib_event, 1);
234 else
235 num = ts_read(_ecore_fb_tslib_tsdev, &_ecore_fb_tslib_event, 1);
236 if (num != 1) return 1; /* no more samples at this time */
237 x = _ecore_fb_tslib_event.x;
238 y = _ecore_fb_tslib_event.y;
239 pressure = _ecore_fb_tslib_event.pressure;
240 v = 1; /* loop, there might be more samples */
241#else
242 ptr = (char *)&(_ecore_fb_ts_event);
243 ptr += _ecore_fb_ts_event_byte_count;
244 num = sizeof(Ecore_Fb_Ts_Event) - _ecore_fb_ts_event_byte_count;
245 v = read(_ecore_fb_ts_fd, ptr, num);
246 if (v < 0) return 1;
247 _ecore_fb_ts_event_byte_count += v;
248 if (v < num) return 1;
249 _ecore_fb_ts_event_byte_count = 0;
250 if (_ecore_fb_ts_apply_cal)
251 {
252 x = ((_ecore_fb_ts_cal.xscale * _ecore_fb_ts_event.x) >> 8) + _ecore_fb_ts_cal.xtrans;
253 y = ((_ecore_fb_ts_cal.yscale * _ecore_fb_ts_event.y) >> 8) + _ecore_fb_ts_cal.ytrans;
254 }
255 else
256 {
257 x = _ecore_fb_ts_event.x;
258 y = _ecore_fb_ts_event.y;
259 }
260 pressure = _ecore_fb_ts_event.pressure;
261#endif
262 t = ecore_loop_time_get();
263 /* add event to queue */
264 /* always add a move event */
265 if ((pressure) || (prev_pressure))
266 {
267 /* MOVE: mouse is down and was */
268 Ecore_Event_Mouse_Move *e;
269
270 e = calloc(1, sizeof(Ecore_Event_Mouse_Move));
271 if (!e) goto retry;
272 e->x = x;
273 e->y = y;
274 e->root.x = e->x;
275 e->root.y = e->y;
276 e->window = 1;
277 e->event_window = e->window;
278 e->root_window = e->window;
279 e->same_screen = 1;
280 e->timestamp = ecore_loop_time_get() * 1000.0;
281 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, NULL, NULL);
282 }
283 if ((pressure) && (!prev_pressure))
284 {
285 /* DOWN: mouse is down, but was not now */
286 Ecore_Event_Mouse_Button *e;
287
288 e = calloc(1, sizeof(Ecore_Event_Mouse_Button));
289 if (!e) goto retry;
290 e->x = x;
291 e->y = y;
292 e->root.x = e->x;
293 e->root.y = e->y;
294 e->buttons = 1;
295 if ((t - last_time) <= _ecore_fb_double_click_time)
296 {
297 e->double_click = 1;
298 did_double = 1;
299 }
300 else
301 {
302 did_double = 0;
303 did_triple = 0;
304 }
305 if ((t - last_last_time) <= (2 * _ecore_fb_double_click_time))
306 {
307 did_triple = 1;
308 e->triple_click = 1;
309 }
310 else
311 {
312 did_triple = 0;
313 }
314 e->window = 1;
315 e->event_window = e->window;
316 e->root_window = e->window;
317 e->same_screen = 1;
318 e->timestamp = ecore_loop_time_get() * 1000.0;
319 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, e, NULL, NULL);
320 }
321 else if ((!pressure) && (prev_pressure))
322 {
323 /* UP: mouse was down, but is not now */
324 Ecore_Event_Mouse_Button *e;
325
326 e = calloc(1, sizeof(Ecore_Event_Mouse_Button));
327 if (!e) goto retry;
328 e->x = prev_x;
329 e->y = prev_y;
330 e->root.x = e->x;
331 e->root.y = e->y;
332 e->buttons = 1;
333 if (did_double)
334 e->double_click = 1;
335 if (did_triple)
336 e->triple_click = 1;
337 e->window = 1;
338 e->event_window = e->window;
339 e->root_window = e->window;
340 e->same_screen = 1;
341 e->timestamp = ecore_loop_time_get() * 1000.0;
342 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, e, NULL, NULL);
343 }
344 if (did_triple)
345 {
346 last_time = 0;
347 last_last_time = 0;
348 }
349 else
350 {
351 last_last_time = last_time;
352 last_time = t;
353 }
354retry:
355 prev_x = x;
356 prev_y = y;
357 prev_pressure = pressure;
358 }
359 while (v > 0);
360 return 1;
361}
362
diff --git a/src/lib/ecore_fb/ecore_fb_vt.c b/src/lib/ecore_fb/ecore_fb_vt.c
new file mode 100644
index 0000000000..c92c087336
--- /dev/null
+++ b/src/lib/ecore_fb/ecore_fb_vt.c
@@ -0,0 +1,322 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Ecore_Fb.h"
6#include "ecore_fb_private.h"
7
8static int _ecore_fb_vt_do_switch = 0;
9
10static int _ecore_fb_vt_tty0_fd = -1;
11static int _ecore_fb_vt_tty_fd = -1;
12static int _ecore_fb_vt_current_vt = 0;
13static int _ecore_fb_vt_prev_vt = 0;
14
15static struct termios _ecore_fb_tty_prev_tio_mode;
16static struct vt_mode _ecore_fb_vt_prev_mode;
17
18static Eina_Bool _ecore_fb_signal_usr_handler(void *data, int type, void *ev);
19static Ecore_Event_Handler *_ecore_fb_user_handler = NULL;
20static int _ecore_fb_tty_prev_mode = 0;
21static int _ecore_fb_tty_prev_kd_mode = 0;
22
23/* callbacks for an attach/release of a vt */
24static void (*_ecore_fb_func_fb_lost) (void *data) = NULL;
25static void *_ecore_fb_func_fb_lost_data = NULL;
26static void (*_ecore_fb_func_fb_gain) (void *data) = NULL;
27static void *_ecore_fb_func_fb_gain_data = NULL;
28
29/* FIXME what is the filter for? */
30static Ecore_Event_Filter *_ecore_fb_filter_handler = NULL;
31
32/* prototypes */
33/* XXX: unused
34static void _ecore_fb_vt_switch(int vt);
35static void *_ecore_fb_event_filter_start(void *data);
36static Eina_Bool _ecore_fb_event_filter_filter(void *data, void *loop_data, int type, void *event);
37static void _ecore_fb_event_filter_end(void *data, void *loop_data);
38*/
39
40static Eina_Bool
41_ecore_fb_signal_usr_handler(void *data EINA_UNUSED, int type EINA_UNUSED, void *ev)
42{
43 Ecore_Event_Signal_User *e;
44
45 e = (Ecore_Event_Signal_User *)ev;
46 if (e->number == 1)
47 {
48 /* release vt */
49 if (_ecore_fb_func_fb_lost) _ecore_fb_func_fb_lost(_ecore_fb_func_fb_lost_data);
50 /* TODO stop listening from the devices? let the callback do it? */
51 ioctl(_ecore_fb_vt_tty_fd, VT_RELDISP, 1);
52 }
53 else if (e->number == 2)
54 {
55 /* attach vt */
56 if (_ecore_fb_func_fb_gain) _ecore_fb_func_fb_gain(_ecore_fb_func_fb_gain_data);
57 /* TODO reattach all devices */
58 }
59 return 1;
60}
61
62/* XXX: unused
63static void
64_ecore_fb_vt_switch(int vt)
65{
66 vt++;
67 if (_ecore_fb_vt_tty_fd != 0)
68 {
69 if (vt != _ecore_fb_vt_current_vt)
70 {
71 tcsetattr(_ecore_fb_vt_tty_fd, TCSAFLUSH, &_ecore_fb_tty_prev_tio_mode);
72 ioctl(_ecore_fb_vt_tty_fd, KDSETMODE, _ecore_fb_tty_prev_kd_mode);
73 ioctl(_ecore_fb_vt_tty_fd, KDSKBMODE, _ecore_fb_tty_prev_mode);
74 }
75 }
76 ioctl(_ecore_fb_vt_tty_fd, VT_ACTIVATE, vt);
77}
78*/
79
80static int
81_ecore_fb_vt_setup(void)
82{
83 char buf[64];
84// XXX: unused
85// struct termios tio;
86 struct vt_mode new_vtmode;
87
88 if (_ecore_fb_vt_current_vt != _ecore_fb_vt_prev_vt)
89 {
90 snprintf(buf, sizeof(buf), "/dev/tty%i", _ecore_fb_vt_current_vt);
91 if ((_ecore_fb_vt_tty_fd = open(buf, O_RDWR)) < 0)
92 {
93 printf("[ecore_fb:vt_setup] can't open tty %d\n", _ecore_fb_vt_current_vt);
94 return 0;
95 }
96 close(_ecore_fb_vt_tty0_fd);
97 _ecore_fb_vt_tty0_fd = -1;
98 /* FIXME detach the process from current tty ? */
99 }
100 else
101 _ecore_fb_vt_tty_fd = _ecore_fb_vt_tty0_fd;
102 /* for backup */
103 tcgetattr(_ecore_fb_vt_tty_fd, &_ecore_fb_tty_prev_tio_mode);
104 ioctl(_ecore_fb_vt_tty_fd, KDGETMODE, &_ecore_fb_tty_prev_kd_mode);
105 ioctl(_ecore_fb_vt_tty_fd, VT_GETMODE, &_ecore_fb_vt_prev_mode);
106
107 if (ioctl(_ecore_fb_vt_tty_fd, KDSETMODE, KD_GRAPHICS) < 0)
108 {
109 perror("[ecore_fb:vt_setup] can't set the mode to KD_GRAPHICS");
110 close(_ecore_fb_vt_tty_fd);
111 _ecore_fb_vt_tty_fd = -1;
112 return 0;
113 }
114 ioctl(_ecore_fb_vt_tty_fd, KDGKBMODE, &_ecore_fb_tty_prev_mode);
115
116 /* support of switching */
117 new_vtmode.mode = VT_PROCESS;
118 new_vtmode.waitv = 0;
119 new_vtmode.relsig = SIGUSR1;
120 new_vtmode.acqsig = SIGUSR2;
121 if (ioctl(_ecore_fb_vt_tty_fd, VT_SETMODE, &new_vtmode) < 0)
122 {
123 perror("[ecore_fb:vt_setup] can't set the tty mode");
124 close(_ecore_fb_vt_tty_fd);
125 _ecore_fb_vt_tty_fd = -1;
126 return 0;
127 }
128 /* register signal handlers when alloc/detach of vt */
129 _ecore_fb_user_handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
130 _ecore_fb_signal_usr_handler,
131 NULL);
132 /* What does this do? */
133 /*
134 _ecore_fb_filter_handler = ecore_event_filter_add(_ecore_fb_event_filter_start, _ecore_fb_event_filter_filter, _ecore_fb_event_filter_end, NULL);
135 */
136
137 usleep(40000);
138 if (ioctl(_ecore_fb_vt_tty_fd, VT_ACTIVATE, _ecore_fb_vt_current_vt) < 0)
139 {
140 perror("[ecore_fb:vt_setup] error on VT_ACTIVATE");
141 close(_ecore_fb_vt_tty_fd);
142 _ecore_fb_vt_tty_fd = -1;
143 return 0;
144 }
145 if(ioctl(_ecore_fb_vt_tty_fd, VT_WAITACTIVE, _ecore_fb_vt_current_vt) < 0)
146 {
147 perror("[ecore_fb:vt_setup] error on VT_WAITACTIVE");
148 close(_ecore_fb_vt_tty_fd);
149 _ecore_fb_vt_tty_fd = -1;
150 return 0;
151 }
152 /* FIXME assign the fb to the tty in case isn't setup */
153 return 1;
154}
155
156int
157ecore_fb_vt_init(void)
158{
159 struct vt_stat vtstat;
160
161 /* as root you can allocate another tty */
162 if (!geteuid())
163 _ecore_fb_vt_do_switch = 1;
164 if ((_ecore_fb_vt_tty0_fd = open("/dev/tty0", O_RDONLY)) < 0)
165 {
166 printf("[ecore_fb:init] can't open /dev/tty0\n");
167 return 0;
168 }
169 /* query current vt state */
170 if ((ioctl(_ecore_fb_vt_tty0_fd, VT_GETSTATE, &vtstat)) < 0)
171 {
172 printf("[ecore_fb:init] can't get current tty state\n");
173 return 0;
174 }
175 _ecore_fb_vt_prev_vt = vtstat.v_active;
176 /* switch to another tty */
177 if (_ecore_fb_vt_do_switch)
178 {
179 int vtno;
180
181 if ((ioctl(_ecore_fb_vt_tty0_fd, VT_OPENQRY, &vtno) < 0))
182 {
183 printf("[ecore_fb:init] can't query for a vt\n");
184 return 0;
185 }
186 _ecore_fb_vt_current_vt = vtno;
187 }
188 /* use current tty */
189 else
190 _ecore_fb_vt_current_vt = _ecore_fb_vt_prev_vt;
191 if (!_ecore_fb_vt_setup())
192 {
193 printf("[ecore_fb:init] can't setup the vt, restoring previous mode...\n");
194 /* TODO finish this */
195 if (_ecore_fb_vt_do_switch)
196 {
197 printf("[ecore_fb:init] switching back to vt %d\n", _ecore_fb_vt_prev_vt);
198 }
199 return 0;
200 }
201 return 1;
202}
203
204void
205ecore_fb_vt_shutdown(void)
206{
207 /* restore the previous mode */
208 if (_ecore_fb_vt_tty_fd != -1)
209 {
210 tcsetattr(_ecore_fb_vt_tty_fd, TCSAFLUSH, &_ecore_fb_tty_prev_tio_mode);
211 ioctl(_ecore_fb_vt_tty_fd, KDSETMODE, _ecore_fb_tty_prev_kd_mode);
212 ioctl(_ecore_fb_vt_tty_fd, KDSKBMODE, _ecore_fb_tty_prev_mode);
213 ioctl(_ecore_fb_vt_tty_fd, VT_SETMODE, &_ecore_fb_vt_prev_mode);
214 /* go back to previous vt */
215 close(_ecore_fb_vt_tty_fd);
216 _ecore_fb_vt_tty_fd = -1;
217 }
218
219 if (_ecore_fb_user_handler) ecore_event_handler_del(_ecore_fb_user_handler);
220 _ecore_fb_user_handler = NULL;
221
222 if (_ecore_fb_filter_handler) ecore_event_filter_del(_ecore_fb_filter_handler);
223 _ecore_fb_filter_handler = NULL;
224}
225
226/**
227 * @addtogroup Ecore_FB_Group Ecore_FB - Frame buffer convenience functions.
228 *
229 * @{
230 */
231
232/**
233 * @brief Set a callback called when a virtual terminal is gained.
234 *
235 * @param func The callback called when vt is gained.
236 * @param data The data to pass to the callback.
237 *
238 * This function sets the callback @p func which will be called when a
239 * virtual terminal is gained (for example you press Ctrl-Alt-F1 to go
240 * to vt1 and your app was using vt1). @p data will be pass to @p func if
241 * the callback is called.
242 */
243EAPI void
244ecore_fb_callback_gain_set(void (*func) (void *data), void *data)
245{
246 _ecore_fb_func_fb_gain = func;
247 _ecore_fb_func_fb_gain_data = data;
248}
249
250/**
251 * @brief Set a callback called when a virtual terminal is lost.
252 *
253 * @param func The callback called when vt is lost.
254 * @param data The data to pass to the callback.
255 *
256 * This function sets the callback @p func which will be called when a
257 * virtual terminal is lost (someone wants the tv from you and you
258 * want to give up that vt). @p data will be pass to @p func if the
259 * callback is called.
260 */
261EAPI void
262ecore_fb_callback_lose_set(void (*func) (void *data), void *data)
263{
264 _ecore_fb_func_fb_lost = func;
265 _ecore_fb_func_fb_lost_data = data;
266
267}
268
269/**
270 * @}
271 */
272
273/*
274 * This filter should take into account that the MOUSE_MOVE event can be
275 * triggered by a mouse, not just a touchscreen device, so you can't discard
276 * them (only those generated by a device that sends events with absolute
277 * coordinates).
278
279typedef struct _Ecore_Fb_Filter_Data Ecore_Fb_Filter_Data;
280
281struct _Ecore_Fb_Filter_Data
282{
283 int last_event_type;
284};
285
286static void *
287_ecore_fb_event_filter_start(void *data EINA_UNUSED)
288{
289 Ecore_Fb_Filter_Data *filter_data;
290
291 filter_data = calloc(1, sizeof(Ecore_Fb_Filter_Data));
292 return filter_data;
293}
294
295static Eina_Bool
296_ecore_fb_event_filter_filter(void *data EINA_UNUSED, void *loop_data,int type, void *event EINA_UNUSED)
297{
298 Ecore_Fb_Filter_Data *filter_data;
299
300 filter_data = loop_data;
301 if (!filter_data) return EINA_TRUE;
302 if (type == ECORE_EVENT_MOUSE_MOVE)
303 {
304 if ((filter_data->last_event_type) == ECORE_EVENT_MOUSE_MOVE)
305 {
306 filter_data->last_event_type = type;
307 return EINA_FALSE;
308 }
309 }
310 filter_data->last_event_type = type;
311 return EINA_TRUE;
312}
313
314static void
315_ecore_fb_event_filter_end(void *data EINA_UNUSED, void *loop_data)
316{
317 Ecore_Fb_Filter_Data *filter_data;
318
319 filter_data = loop_data;
320 if (filter_data) free(filter_data);
321}
322*/