summaryrefslogtreecommitdiff
path: root/src/lib/ecore_sdl
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_sdl
parent53fc441d5475155965d92da89502fe4634a561b2 (diff)
merge: add escape ecore, fix several bugs
SVN revision: 79995
Diffstat (limited to 'src/lib/ecore_sdl')
-rw-r--r--src/lib/ecore_sdl/Ecore_Sdl.h114
-rw-r--r--src/lib/ecore_sdl/Ecore_Sdl_Keys.h266
-rw-r--r--src/lib/ecore_sdl/ecore_sdl.c334
-rw-r--r--src/lib/ecore_sdl/ecore_sdl_private.h36
4 files changed, 750 insertions, 0 deletions
diff --git a/src/lib/ecore_sdl/Ecore_Sdl.h b/src/lib/ecore_sdl/Ecore_Sdl.h
new file mode 100644
index 0000000000..359e974718
--- /dev/null
+++ b/src/lib/ecore_sdl/Ecore_Sdl.h
@@ -0,0 +1,114 @@
1#ifndef _ECORE_SDL_H
2#define _ECORE_SDL_H
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef _WIN32
9# ifdef EFL_ECORE_SDL_BUILD
10# ifdef DLL_EXPORT
11# define EAPI __declspec(dllexport)
12# else
13# define EAPI
14# endif /* ! DLL_EXPORT */
15# else
16# define EAPI __declspec(dllimport)
17# endif /* ! EFL_ECORE_SDL_BUILD */
18#else
19# ifdef __GNUC__
20# if __GNUC__ >= 4
21# define EAPI __attribute__ ((visibility("default")))
22# else
23# define EAPI
24# endif
25# else
26# define EAPI
27# endif
28#endif /* ! _WIN32 */
29
30/**
31 * @file
32 * @brief Ecore SDL system functions.
33 */
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39EAPI extern int ECORE_SDL_EVENT_GOT_FOCUS;
40EAPI extern int ECORE_SDL_EVENT_LOST_FOCUS;
41EAPI extern int ECORE_SDL_EVENT_RESIZE;
42EAPI extern int ECORE_SDL_EVENT_EXPOSE;
43
44typedef struct _Ecore_Sdl_Event_Key_Down Ecore_Sdl_Event_Key_Down;
45struct _Ecore_Sdl_Event_Key_Down /** SDL Key Down event */
46{
47 const char *keyname; /**< The name of the key that was pressed */
48 const char *keycompose; /**< The UTF-8 string conversion if any */
49 unsigned int time;
50};
51
52typedef struct _Ecore_Sdl_Event_Key_Up Ecore_Sdl_Event_Key_Up;
53struct _Ecore_Sdl_Event_Key_Up /** SDL Key Up event */
54{
55 const char *keyname; /**< The name of the key that was released */
56 const char *keycompose; /**< The UTF-8 string conversion if any */
57 unsigned int time;
58};
59
60typedef struct _Ecore_Sdl_Event_Mouse_Button_Down Ecore_Sdl_Event_Mouse_Button_Down;
61struct _Ecore_Sdl_Event_Mouse_Button_Down /** SDL Mouse Down event */
62{
63 int button; /**< Mouse button that was pressed (1 - 32) */
64 int x; /**< Mouse co-ordinates when mouse button was pressed */
65 int y; /**< Mouse co-ordinates when mouse button was pressed */
66 int double_click : 1; /**< Set if click was a double click */
67 int triple_click : 1; /**< Set if click was a triple click */
68 unsigned int time;
69};
70
71typedef struct _Ecore_Sdl_Event_Mouse_Button_Up Ecore_Sdl_Event_Mouse_Button_Up;
72struct _Ecore_Sdl_Event_Mouse_Button_Up /** SDL Mouse Up event */
73{
74 int button; /**< Mouse button that was released (1 - 32) */
75 int x; /**< Mouse co-ordinates when mouse button was raised */
76 int y; /**< Mouse co-ordinates when mouse button was raised */
77 int double_click : 1; /**< Set if click was a double click */
78 int triple_click : 1; /**< Set if click was a triple click */
79 unsigned int time;
80};
81
82typedef struct _Ecore_Sdl_Event_Mouse_Move Ecore_Sdl_Event_Mouse_Move;
83struct _Ecore_Sdl_Event_Mouse_Move /** SDL Mouse Move event */
84{
85 int x; /**< Mouse co-ordinates where the mouse cursor moved to */
86 int y; /**< Mouse co-ordinates where the mouse cursor moved to */
87 unsigned int time;
88};
89
90typedef struct _Ecore_Sdl_Event_Mouse_Wheel Ecore_Sdl_Event_Mouse_Wheel;
91struct _Ecore_Sdl_Event_Mouse_Wheel /** SDL Mouse Wheel event */
92{
93 int x,y;
94 int direction; /* 0 = vertical, 1 = horizontal */
95 int wheel; /* value 1 (left/up), -1 (right/down) */
96 unsigned int time;
97};
98
99typedef struct _Ecore_Sdl_Event_Video_Resize Ecore_Sdl_Event_Video_Resize;
100struct _Ecore_Sdl_Event_Video_Resize
101{
102 int w;
103 int h;
104};
105
106EAPI int ecore_sdl_init(const char *name);
107EAPI int ecore_sdl_shutdown(void);
108EAPI void ecore_sdl_feed_events(void);
109
110#ifdef __cplusplus
111}
112#endif
113
114#endif
diff --git a/src/lib/ecore_sdl/Ecore_Sdl_Keys.h b/src/lib/ecore_sdl/Ecore_Sdl_Keys.h
new file mode 100644
index 0000000000..4d0b60b854
--- /dev/null
+++ b/src/lib/ecore_sdl/Ecore_Sdl_Keys.h
@@ -0,0 +1,266 @@
1#ifndef ECORE_SDL_KEYS_H__
2# define ECORE_SDL_KEYS_H__
3
4struct _ecore_sdl_keys_s
5{
6 int code;
7 const char* name;
8 const char* compose;
9};
10
11static const struct _ecore_sdl_keys_s keystable[] =
12{
13 { SDLK_UNKNOWN, "0x00", "" },
14#ifndef BUILD_ECORE_EVAS_SDL_130
15 { SDLK_FIRST, "First", "First" },
16#endif
17 { SDLK_BACKSPACE, "BackSpace", "\010" },
18 { SDLK_TAB, "Tab", "\011" },
19 { SDLK_CLEAR, "Clear", "Clear" },
20 { SDLK_RETURN, "Return", "\015" },
21 { SDLK_PAUSE, "Pause", "Pause" },
22 { SDLK_ESCAPE, "Escape", "\033" },
23 { SDLK_SPACE, "space", " " },
24 { SDLK_EXCLAIM, "exclam", "!" },
25 { SDLK_QUOTEDBL, "quotedbl", "\"" },
26 { SDLK_HASH, "numbersign", "#" },
27 { SDLK_DOLLAR, "dollar", "$" },
28 { SDLK_AMPERSAND, "ampersand", "&" },
29 { SDLK_QUOTE, "apostrophe", "'" },
30 { SDLK_LEFTPAREN, "parenleft", "(" },
31 { SDLK_RIGHTPAREN, "parenright", ")" },
32 { SDLK_ASTERISK, "asterisk", "*" },
33 { SDLK_PLUS, "plus", "+" },
34 { SDLK_COMMA, "comma", "," },
35 { SDLK_MINUS, "minus", "-" },
36 { SDLK_PERIOD, "period", "." },
37 { SDLK_SLASH, "slash", "/" },
38 { SDLK_0, "0", "0" },
39 { SDLK_1, "1", "1" },
40 { SDLK_2, "2", "2" },
41 { SDLK_3, "3", "3" },
42 { SDLK_4, "4", "4" },
43 { SDLK_5, "5", "5" },
44 { SDLK_6, "6", "6" },
45 { SDLK_7, "7", "7" },
46 { SDLK_8, "8", "8" },
47 { SDLK_9, "9", "9" },
48 { SDLK_COLON, "colon", ":" },
49 { SDLK_SEMICOLON, "semicolon", ";" },
50 { SDLK_LESS, "less", "<" },
51 { SDLK_EQUALS, "equal", "=" },
52 { SDLK_GREATER, "greater", ">" },
53 { SDLK_QUESTION, "question", "?" },
54 { SDLK_AT, "at", "@" },
55
56 /* Skip uppercase letters */
57 { SDLK_LEFTBRACKET, "bracketleft", "[" },
58 { SDLK_BACKSLASH, "backslash", "\\" },
59 { SDLK_RIGHTBRACKET, "bracketright", "]" },
60 { SDLK_CARET, "asciicircumm", "^" },
61 { SDLK_UNDERSCORE, "underscore", "_" },
62 { SDLK_BACKQUOTE, "asciitilde", "`" },
63 { SDLK_a, "a", "a" },
64 { SDLK_b, "b", "b" },
65 { SDLK_c, "c", "c" },
66 { SDLK_d, "d", "d" },
67 { SDLK_e, "e", "e" },
68 { SDLK_f, "f", "f" },
69 { SDLK_g, "g", "g" },
70 { SDLK_h, "h", "h" },
71 { SDLK_i, "i", "i" },
72 { SDLK_j, "j", "j" },
73 { SDLK_k, "k", "k" },
74 { SDLK_l, "l", "l" },
75 { SDLK_m, "m", "m" },
76 { SDLK_n, "n", "n" },
77 { SDLK_o, "o", "o" },
78 { SDLK_p, "p", "p" },
79 { SDLK_q, "q", "q" },
80 { SDLK_r, "r", "r" },
81 { SDLK_s, "s", "s" },
82 { SDLK_t, "t", "t" },
83 { SDLK_u, "u", "u" },
84 { SDLK_v, "v", "v" },
85 { SDLK_w, "w", "w" },
86 { SDLK_x, "x", "x" },
87 { SDLK_y, "y", "y" },
88 { SDLK_z, "z", "z" },
89 { SDLK_DELETE, "Delete", "\177" },
90 /* End of ASCII mapped keysyms */
91
92#ifndef BUILD_ECORE_EVAS_SDL_130
93 /* International keyboard syms */
94 { SDLK_WORLD_0, "w0", "" }, /* 0xA0 */
95 { SDLK_WORLD_1, "w1", "" },
96 { SDLK_WORLD_2, "w2", "" },
97 { SDLK_WORLD_3, "w3", "" },
98 { SDLK_WORLD_4, "w4", "" },
99 { SDLK_WORLD_5, "w5", "" },
100 { SDLK_WORLD_6, "w6", "" },
101 { SDLK_WORLD_7, "w7", "" },
102 { SDLK_WORLD_8, "w8", "" },
103 { SDLK_WORLD_9, "w9", "" },
104 { SDLK_WORLD_10, "w10", "" },
105 { SDLK_WORLD_11, "w11", "" },
106 { SDLK_WORLD_12, "w12", "" },
107 { SDLK_WORLD_13, "w13", "" },
108 { SDLK_WORLD_14, "w14", "" },
109 { SDLK_WORLD_15, "w15", "" },
110 { SDLK_WORLD_16, "w16", "" },
111 { SDLK_WORLD_17, "w17", "" },
112 { SDLK_WORLD_18, "w18", "" },
113 { SDLK_WORLD_19, "w19", "" },
114 { SDLK_WORLD_20, "w20", "" },
115 { SDLK_WORLD_21, "w21", "" },
116 { SDLK_WORLD_22, "w22", "" },
117 { SDLK_WORLD_23, "w23", "" },
118 { SDLK_WORLD_24, "w24", "" },
119 { SDLK_WORLD_25, "w25", "" },
120 { SDLK_WORLD_26, "w26", "" },
121 { SDLK_WORLD_27, "w27", "" },
122 { SDLK_WORLD_28, "w28", "" },
123 { SDLK_WORLD_29, "w29", "" },
124 { SDLK_WORLD_30, "w30", "" },
125 { SDLK_WORLD_31, "w31", "" },
126 { SDLK_WORLD_32, "w32", "" },
127 { SDLK_WORLD_33, "w33", "" },
128 { SDLK_WORLD_34, "w34", "" },
129 { SDLK_WORLD_35, "w35", "" },
130 { SDLK_WORLD_36, "w36", "" },
131 { SDLK_WORLD_37, "w37", "" },
132 { SDLK_WORLD_38, "w38", "" },
133 { SDLK_WORLD_39, "w39", "" },
134 { SDLK_WORLD_40, "w40", "" },
135 { SDLK_WORLD_41, "w41", "" },
136 { SDLK_WORLD_42, "w42", "" },
137 { SDLK_WORLD_43, "w43", "" },
138 { SDLK_WORLD_44, "w44", "" },
139 { SDLK_WORLD_45, "w45", "" },
140 { SDLK_WORLD_46, "w46", "" },
141 { SDLK_WORLD_47, "w47", "" },
142 { SDLK_WORLD_48, "w48", "" },
143 { SDLK_WORLD_49, "w49", "" },
144 { SDLK_WORLD_50, "w50", "" },
145 { SDLK_WORLD_51, "w51", "" },
146 { SDLK_WORLD_52, "w52", "" },
147 { SDLK_WORLD_53, "w53", "" },
148 { SDLK_WORLD_54, "w54", "" },
149 { SDLK_WORLD_55, "w55", "" },
150 { SDLK_WORLD_56, "w56", "" },
151 { SDLK_WORLD_57, "w57", "" },
152 { SDLK_WORLD_58, "w58", "" },
153 { SDLK_WORLD_59, "w59", "" },
154 { SDLK_WORLD_60, "w60", "" },
155 { SDLK_WORLD_61, "w61", "" },
156 { SDLK_WORLD_62, "w62", "" },
157 { SDLK_WORLD_63, "w63", "" },
158 { SDLK_WORLD_64, "w64", "" },
159 { SDLK_WORLD_65, "w65", "" },
160 { SDLK_WORLD_66, "w66", "" },
161 { SDLK_WORLD_67, "w67", "" },
162 { SDLK_WORLD_68, "w68", "" },
163 { SDLK_WORLD_69, "w69", "" },
164 { SDLK_WORLD_70, "w70", "" },
165 { SDLK_WORLD_71, "w71", "" },
166 { SDLK_WORLD_72, "w72", "" },
167 { SDLK_WORLD_73, "w73", "" },
168 { SDLK_WORLD_74, "w74", "" },
169 { SDLK_WORLD_75, "w75", "" },
170 { SDLK_WORLD_76, "w76", "" },
171 { SDLK_WORLD_77, "w77", "" },
172 { SDLK_WORLD_78, "w78", "" },
173 { SDLK_WORLD_79, "w79", "" },
174 { SDLK_WORLD_80, "w80", "" },
175 { SDLK_WORLD_81, "w81", "" },
176 { SDLK_WORLD_82, "w82", "" },
177 { SDLK_WORLD_83, "w83", "" },
178 { SDLK_WORLD_84, "w84", "" },
179 { SDLK_WORLD_85, "w85", "" },
180 { SDLK_WORLD_86, "w86", "" },
181 { SDLK_WORLD_87, "w87", "" },
182 { SDLK_WORLD_88, "w88", "" },
183 { SDLK_WORLD_89, "w89", "" },
184 { SDLK_WORLD_90, "w90", "" },
185 { SDLK_WORLD_91, "w91", "" },
186 { SDLK_WORLD_92, "w92", "" },
187 { SDLK_WORLD_93, "w93", "" },
188 { SDLK_WORLD_94, "w94", "" },
189 { SDLK_WORLD_95, "w95", "" },
190#endif
191 /* Numeric keypad */
192 { SDLK_KP0, "KP0", "0" },
193 { SDLK_KP1, "KP1", "1" },
194 { SDLK_KP2, "KP2", "2" },
195 { SDLK_KP3, "KP3", "3" },
196 { SDLK_KP4, "KP4", "4" },
197 { SDLK_KP5, "KP5", "5" },
198 { SDLK_KP6, "KP6", "6" },
199 { SDLK_KP7, "KP7", "7" },
200 { SDLK_KP8, "KP8", "8" },
201 { SDLK_KP9, "KP9", "9" },
202 { SDLK_KP_PERIOD, "period", "." },
203 { SDLK_KP_DIVIDE, "KP_Divide", "/" },
204 { SDLK_KP_MULTIPLY, "KP_Multiply", "*" },
205 { SDLK_KP_MINUS, "KP_Minus", "-" },
206 { SDLK_KP_PLUS, "KP_Plus", "+" },
207 { SDLK_KP_ENTER, "KP_Enter", "\015" },
208 { SDLK_KP_EQUALS, "KP_Equals", "=" },
209
210 /* Arrows + Home/End pad */
211 { SDLK_UP, "Up", "Up" },
212 { SDLK_DOWN, "Down", "Down" },
213 { SDLK_RIGHT, "Right", "Right" },
214 { SDLK_LEFT, "Left", "Left" },
215 { SDLK_INSERT, "Insert", "Insert" },
216 { SDLK_HOME, "Home", "Home" },
217 { SDLK_END, "End", "End" },
218 { SDLK_PAGEUP, "Page_Up", "Page_Up" },
219 { SDLK_PAGEDOWN, "Page_Down", "Page_Down" },
220
221 /* Function keys */
222 { SDLK_F1, "F1", "F1" },
223 { SDLK_F2, "F2", "F2" },
224 { SDLK_F3, "F3", "F3" },
225 { SDLK_F4, "F4", "F4" },
226 { SDLK_F5, "F5", "F5" },
227 { SDLK_F6, "F6", "F6" },
228 { SDLK_F7, "F7", "F7" },
229 { SDLK_F8, "F8", "F8" },
230 { SDLK_F9, "F9", "F9" },
231 { SDLK_F10, "F10", "F10" },
232 { SDLK_F11, "F11", "F11" },
233 { SDLK_F12, "F12", "F12" },
234 { SDLK_F13, "F13", "F13" },
235 { SDLK_F14, "F14", "F14" },
236 { SDLK_F15, "F15", "F15" },
237
238 /* Key state modifier keys */
239 { SDLK_NUMLOCK, "Num_Lock", "Num_Lock" },
240 { SDLK_CAPSLOCK, "Caps_Lock", "Caps_Lock" },
241 { SDLK_SCROLLOCK, "Scroll_Lock", "Scroll_Lock" },
242 { SDLK_RSHIFT, "Shift_R", "Shift_R" },
243 { SDLK_LSHIFT, "Shift_L", "Shift_L" },
244 { SDLK_RCTRL, "Control_R", "Control_R" },
245 { SDLK_LCTRL, "Control_L", "Control_L" },
246 { SDLK_RALT, "Alt_R", "Alt_R" },
247 { SDLK_LALT, "Alt_L", "Alt_L" },
248 { SDLK_RMETA, "Meta_R", "Meta_R" },
249 { SDLK_LMETA, "Meta_L", "Meta_L" },
250 { SDLK_LSUPER, "Super_L", "Super_L" }, /* Left "Windows" key */
251 { SDLK_RSUPER, "Super_R", "Super_R" }, /* Right "Windows" key */
252 { SDLK_MODE, "Mode", "Mode" }, /* "Alt Gr" key */
253 { SDLK_COMPOSE, "Compose", "Compose" }, /* Multi-key compose key */
254
255 /* Miscellaneous function keys */
256 { SDLK_HELP, "Help", "Help" },
257 { SDLK_PRINT, "Print", "Print" },
258 { SDLK_SYSREQ, "SysReq", "SysReq" },
259 { SDLK_BREAK, "Break", "Break" },
260 { SDLK_MENU, "Menu", "Menu" },
261 { SDLK_POWER, "Power", "Power" }, /* Power Macintosh power key */
262 { SDLK_EURO, "Euro", "\200" }, /* Some european keyboards */
263 { SDLK_UNDO, "Undo", "Undo" } /* Atari keyboard has Undo */
264};
265
266#endif /* ECORE_SDL_KEYS_H__ */
diff --git a/src/lib/ecore_sdl/ecore_sdl.c b/src/lib/ecore_sdl/ecore_sdl.c
new file mode 100644
index 0000000000..f4a8faedb0
--- /dev/null
+++ b/src/lib/ecore_sdl/ecore_sdl.c
@@ -0,0 +1,334 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <SDL/SDL.h>
6
7#include <Eina.h>
8#include <Ecore.h>
9#include <ecore_private.h>
10#include <Ecore_Input.h>
11#include "Ecore_Sdl.h"
12#include "Ecore_Sdl_Keys.h"
13#include "ecore_sdl_private.h"
14
15
16int _ecore_sdl_log_dom = -1;
17
18typedef struct _Ecore_SDL_Pressed Ecore_SDL_Pressed;
19struct _Ecore_SDL_Pressed
20{
21 EINA_RBTREE;
22
23 SDLKey key;
24};
25
26EAPI int ECORE_SDL_EVENT_GOT_FOCUS = 0;
27EAPI int ECORE_SDL_EVENT_LOST_FOCUS = 0;
28EAPI int ECORE_SDL_EVENT_RESIZE = 0;
29EAPI int ECORE_SDL_EVENT_EXPOSE = 0;
30
31static int _ecore_sdl_init_count = 0;
32static Eina_Rbtree *repeat = NULL;
33
34static Eina_Rbtree_Direction
35_ecore_sdl_pressed_key(const Ecore_SDL_Pressed *left,
36 const Ecore_SDL_Pressed *right,
37 EINA_UNUSED void *data)
38{
39 return left->key < right->key ? EINA_RBTREE_LEFT : EINA_RBTREE_RIGHT;
40}
41
42static int
43_ecore_sdl_pressed_node(const Ecore_SDL_Pressed *node,
44 const SDLKey *key,
45 EINA_UNUSED int length,
46 EINA_UNUSED void *data)
47{
48 return node->key - *key;
49}
50
51/**
52 * @defgroup Ecore_Sdl_Library_Group SDL Library Functions
53 *
54 * Functions used to set up and shut down the Ecore_Sdl functions.
55 */
56
57/**
58 * Sets up the Ecore_Sdl library.
59 * @param name device target name
60 * @return @c 0 on failure. Otherwise, the number of times the library has
61 * been initialised without being shut down.
62 * @ingroup Ecore_SDL_Library_Group
63 */
64EAPI int
65ecore_sdl_init(const char *name EINA_UNUSED)
66{
67 if(++_ecore_sdl_init_count != 1)
68 return _ecore_sdl_init_count;
69 _ecore_sdl_log_dom = eina_log_domain_register
70 ("ecore_sdl", ECORE_SDL_DEFAULT_LOG_COLOR);
71 if(_ecore_sdl_log_dom < 0)
72 {
73 EINA_LOG_ERR("Impossible to create a log domain for the Ecore SDL module.");
74 return --_ecore_sdl_init_count;
75 }
76 if (!ecore_event_init())
77 return --_ecore_sdl_init_count;
78
79 ECORE_SDL_EVENT_GOT_FOCUS = ecore_event_type_new();
80 ECORE_SDL_EVENT_LOST_FOCUS = ecore_event_type_new();
81 ECORE_SDL_EVENT_RESIZE = ecore_event_type_new();
82 ECORE_SDL_EVENT_EXPOSE = ecore_event_type_new();
83
84 SDL_EnableKeyRepeat(200, 100);
85
86 return _ecore_sdl_init_count;
87}
88
89/**
90 * Shuts down the Ecore_Sdl library.
91 * @return @c The number of times the system has been initialised without
92 * being shut down.
93 * @ingroup Ecore_SDL_Library_Group
94 */
95EAPI int
96ecore_sdl_shutdown(void)
97{
98 if (--_ecore_sdl_init_count != 0)
99 return _ecore_sdl_init_count;
100
101 ecore_event_shutdown();
102 eina_log_domain_unregister(_ecore_sdl_log_dom);
103 _ecore_sdl_log_dom = -1;
104 return _ecore_sdl_init_count;
105}
106
107static unsigned int
108_ecore_sdl_event_modifiers(int mod)
109{
110 unsigned int modifiers = 0;
111
112 if(mod & KMOD_LSHIFT) modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
113 if(mod & KMOD_RSHIFT) modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
114 if(mod & KMOD_LCTRL) modifiers |= ECORE_EVENT_MODIFIER_CTRL;
115 if(mod & KMOD_RCTRL) modifiers |= ECORE_EVENT_MODIFIER_CTRL;
116 if(mod & KMOD_LALT) modifiers |= ECORE_EVENT_MODIFIER_ALT;
117 if(mod & KMOD_RALT) modifiers |= ECORE_EVENT_MODIFIER_ALT;
118 if(mod & KMOD_NUM) modifiers |= ECORE_EVENT_LOCK_NUM;
119 if(mod & KMOD_CAPS) modifiers |= ECORE_EVENT_LOCK_CAPS;
120
121 return modifiers;
122}
123
124static Ecore_Event_Key*
125_ecore_sdl_event_key(SDL_Event *event, double timestamp)
126{
127 Ecore_Event_Key *ev;
128 unsigned int i;
129
130 ev = malloc(sizeof(Ecore_Event_Key));
131 if (!ev) return NULL;
132
133 ev->timestamp = timestamp;
134 ev->window = 0;
135 ev->event_window = 0;
136 ev->modifiers = _ecore_sdl_event_modifiers(SDL_GetModState());
137 ev->key = NULL;
138 ev->compose = NULL;
139
140 for (i = 0; i < sizeof(keystable) / sizeof(struct _ecore_sdl_keys_s); ++i)
141 if (keystable[i].code == event->key.keysym.sym)
142 {
143 ev->keyname = keystable[i].name;
144 ev->string = keystable[i].compose;
145
146 return ev;
147 }
148
149 free(ev);
150 return NULL;
151}
152
153EAPI void
154ecore_sdl_feed_events(void)
155{
156 SDL_Event event;
157 unsigned int timestamp;
158
159 while(SDL_PollEvent(&event))
160 {
161 timestamp = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
162 switch(event.type)
163 {
164 case SDL_MOUSEMOTION:
165 {
166 Ecore_Event_Mouse_Move *ev;
167
168 ev = malloc(sizeof(Ecore_Event_Mouse_Move));
169 if (!ev) return ;
170
171 ev->timestamp = timestamp;
172 ev->window = 0;
173 ev->event_window = 0;
174 ev->modifiers = 0; /* FIXME: keep modifier around. */
175 ev->x = event.motion.x;
176 ev->y = event.motion.y;
177 ev->root.x = ev->x;
178 ev->root.y = ev->y;
179
180 /* Must set multi touch device to 0 or it will get ignored */
181 ev->multi.device = 0;
182 ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0;
183 ev->multi.pressure = ev->multi.angle = 0;
184 ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0;
185
186 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
187 break;
188 }
189 case SDL_MOUSEBUTTONDOWN:
190 {
191 if (event.button.button == SDL_BUTTON_WHEELUP ||
192 event.button.button == SDL_BUTTON_WHEELDOWN)
193 {
194 Ecore_Event_Mouse_Wheel *ev;
195
196 ev = malloc(sizeof(Ecore_Event_Mouse_Wheel));
197 if (!ev) return ;
198
199 ev->timestamp = timestamp;
200 ev->window = 0;
201 ev->event_window = 0;
202 ev->modifiers = 0; /* FIXME: keep modifier around. */
203 ev->direction = 0;
204 ev->z = event.button.button == SDL_BUTTON_WHEELDOWN ? -1 : 1;
205
206 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
207 }
208 else
209 {
210 Ecore_Event_Mouse_Button *ev;
211
212 ev = malloc(sizeof(Ecore_Event_Mouse_Button));
213 if (!ev) return ;
214
215 ev->timestamp = timestamp;
216 ev->window = 0;
217 ev->event_window = 0;
218 ev->modifiers = 0; /* FIXME: keep modifier around. */
219 ev->buttons = event.button.button;
220 ev->double_click = 0;
221 ev->triple_click = 0;
222
223 /* Must set multi touch device to 0 or it will get ignored */
224 ev->multi.device = 0;
225 ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0;
226 ev->multi.pressure = ev->multi.angle = 0;
227 ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0;
228
229 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
230 }
231 break;
232 }
233 case SDL_MOUSEBUTTONUP:
234 {
235 Ecore_Event_Mouse_Button *ev;
236
237 ev = malloc(sizeof(Ecore_Event_Mouse_Button));
238 if (!ev) return ;
239 ev->timestamp = timestamp;
240 ev->window = 0;
241 ev->event_window = 0;
242 ev->modifiers = 0; /* FIXME: keep modifier around. */
243 ev->buttons = event.button.button;
244 ev->double_click = 0;
245 ev->triple_click = 0;
246
247 /* Must set multi touch device to 0 or it will get ignored */
248 ev->multi.device = 0;
249 ev->multi.radius = ev->multi.radius_x = ev->multi.radius_y = 0;
250 ev->multi.pressure = ev->multi.angle = 0;
251 ev->multi.x = ev->multi.y = ev->multi.root.x = ev->multi.root.y = 0;
252
253 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
254 break;
255 }
256 case SDL_VIDEORESIZE:
257 {
258 Ecore_Sdl_Event_Video_Resize *ev;
259
260 ev = malloc(sizeof (Ecore_Sdl_Event_Video_Resize));
261 ev->w = event.resize.w;
262 ev->h = event.resize.h;
263
264 ecore_event_add(ECORE_SDL_EVENT_RESIZE, ev, NULL, NULL);
265 break;
266 }
267 case SDL_VIDEOEXPOSE:
268 ecore_event_add(ECORE_SDL_EVENT_EXPOSE, NULL, NULL, NULL);
269 break;
270 case SDL_QUIT:
271 ecore_main_loop_quit();
272 break;
273
274 case SDL_KEYDOWN:
275 {
276 Ecore_SDL_Pressed *entry;
277 Ecore_Event_Key *ev;
278
279 entry = (Ecore_SDL_Pressed*) eina_rbtree_inline_lookup(repeat, &event.key.keysym.sym, sizeof (event.key.keysym.sym),
280 EINA_RBTREE_CMP_KEY_CB(_ecore_sdl_pressed_node), NULL);
281 if (entry)
282 {
283 ev = _ecore_sdl_event_key(&event, timestamp);
284 if (ev) ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
285 }
286
287 ev = _ecore_sdl_event_key(&event, timestamp);
288 if (ev) ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, NULL, NULL);
289
290 if (!entry)
291 {
292 entry = malloc(sizeof (Ecore_SDL_Pressed));
293 if (!entry) break;
294
295 entry->key = event.key.keysym.sym;
296
297 repeat = eina_rbtree_inline_insert(repeat, EINA_RBTREE_GET(entry),
298 EINA_RBTREE_CMP_NODE_CB(_ecore_sdl_pressed_key), NULL);
299 }
300 break;
301 }
302 case SDL_KEYUP:
303 {
304 Ecore_Event_Key *ev;
305 Ecore_SDL_Pressed *entry;
306
307 entry = (Ecore_SDL_Pressed*) eina_rbtree_inline_lookup(repeat, &event.key.keysym.sym, sizeof (event.key.keysym.sym),
308 EINA_RBTREE_CMP_KEY_CB(_ecore_sdl_pressed_node), NULL);
309 if (entry)
310 {
311 repeat = eina_rbtree_inline_remove(repeat, EINA_RBTREE_GET(entry),
312 EINA_RBTREE_CMP_NODE_CB(_ecore_sdl_pressed_key), NULL);
313 free(entry);
314 }
315
316 ev = _ecore_sdl_event_key(&event, timestamp);
317 if (ev) ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
318 break;
319 }
320 case SDL_ACTIVEEVENT:
321 /* FIXME: Focus gain. */
322 break;
323 case SDL_SYSWMEVENT:
324 case SDL_USEREVENT:
325 case SDL_JOYAXISMOTION:
326 case SDL_JOYBALLMOTION:
327 case SDL_JOYHATMOTION:
328 case SDL_JOYBUTTONDOWN:
329 case SDL_JOYBUTTONUP:
330 default:
331 break;
332 }
333 }
334}
diff --git a/src/lib/ecore_sdl/ecore_sdl_private.h b/src/lib/ecore_sdl/ecore_sdl_private.h
new file mode 100644
index 0000000000..37e957015d
--- /dev/null
+++ b/src/lib/ecore_sdl/ecore_sdl_private.h
@@ -0,0 +1,36 @@
1#ifndef _ECORE_SDL_PRIVATE_H
2# define _ECORE_SDL_PRIVATE_H
3
4extern int _ecore_sdl_log_dom;
5
6# ifdef ECORE_SDL_DEFAULT_LOG_COLOR
7# undef ECORE_SDL_DEFAULT_LOG_COLOR
8# endif
9# define ECORE_SDL_DEFAULT_LOG_COLOR EINA_COLOR_BLUE
10
11# ifdef ERR
12# undef ERR
13# endif
14# define ERR(...) EINA_LOG_DOM_ERR(_ecore_sdl_log_dom, __VA_ARGS__)
15
16# ifdef DBG
17# undef DBG
18# endif
19# define DBG(...) EINA_LOG_DOM_DBG(_ecore_sdl_log_dom, __VA_ARGS__)
20
21# ifdef INF
22# undef INF
23# endif
24# define INF(...) EINA_LOG_DOM_INFO(_ecore_sdl_log_dom, __VA_ARGS__)
25
26# ifdef WRN
27# undef WRN
28# endif
29# define WRN(...) EINA_LOG_DOM_WARN(_ecore_sdl_log_dom, __VA_ARGS__)
30
31# ifdef CRIT
32# undef CRIT
33# endif
34# define CRIT(...) EINA_LOG_DOM_CRIT(_ecore_sdl_log_dom, __VA_ARGS__)
35
36#endif