diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2006-02-03 15:19:58 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2006-02-03 15:19:58 +0000 |
commit | fc72c5375813a6bbc0845aca984147a944a7e62a (patch) | |
tree | 347a6a9297f9f4d3131c8268f450d6ba227d0246 /uisimulator/sdl/button-x11.c | |
parent | 347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4 (diff) | |
download | rockbox-fc72c5375813a6bbc0845aca984147a944a7e62a.tar.gz rockbox-fc72c5375813a6bbc0845aca984147a944a7e62a.zip |
Patch #1417462 by Dan Everton - Improved SDL simulator
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8546 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl/button-x11.c')
-rw-r--r-- | uisimulator/sdl/button-x11.c | 317 |
1 files changed, 0 insertions, 317 deletions
diff --git a/uisimulator/sdl/button-x11.c b/uisimulator/sdl/button-x11.c deleted file mode 100644 index b0ab81a86a..0000000000 --- a/uisimulator/sdl/button-x11.c +++ /dev/null | |||
@@ -1,317 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Björn Stenberg | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include <stdlib.h> | ||
20 | #include "config.h" | ||
21 | #include "button.h" | ||
22 | #include "kernel.h" | ||
23 | #include "debug.h" | ||
24 | #include "backlight.h" | ||
25 | #include "misc.h" | ||
26 | #include <SDL.h> | ||
27 | |||
28 | extern int screenhack_handle_events(bool *release); | ||
29 | |||
30 | struct event_queue button_queue; | ||
31 | |||
32 | static int button_state = 0; /* keeps track of pressed keys */ | ||
33 | static long lastbtn; /* Last valid button status */ | ||
34 | |||
35 | /* how often we check to see if a button is pressed */ | ||
36 | #define POLL_FREQUENCY HZ/25 | ||
37 | |||
38 | /* how long until repeat kicks in */ | ||
39 | #define REPEAT_START 8 | ||
40 | |||
41 | /* the speed repeat starts at */ | ||
42 | #define REPEAT_INTERVAL_START 4 | ||
43 | |||
44 | /* speed repeat finishes at */ | ||
45 | #define REPEAT_INTERVAL_FINISH 2 | ||
46 | |||
47 | /* mostly copied from real button.c */ | ||
48 | void button_read (void); | ||
49 | |||
50 | static void button_tick(void) | ||
51 | { | ||
52 | static int tick = 0; | ||
53 | static int count = 0; | ||
54 | static int repeat_speed = REPEAT_INTERVAL_START; | ||
55 | static int repeat_count = 0; | ||
56 | static bool repeat = false; | ||
57 | int diff; | ||
58 | int btn; | ||
59 | |||
60 | /* only poll every X ticks */ | ||
61 | if ( ++tick >= POLL_FREQUENCY ) | ||
62 | { | ||
63 | bool post = false; | ||
64 | button_read(); | ||
65 | btn = button_state; | ||
66 | |||
67 | /* Find out if a key has been released */ | ||
68 | diff = btn ^ lastbtn; | ||
69 | if(diff && (btn & diff) == 0) | ||
70 | { | ||
71 | queue_post(&button_queue, BUTTON_REL | diff, NULL); | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | if ( btn ) | ||
76 | { | ||
77 | /* normal keypress */ | ||
78 | if ( btn != lastbtn ) | ||
79 | { | ||
80 | post = true; | ||
81 | repeat = false; | ||
82 | repeat_speed = REPEAT_INTERVAL_START; | ||
83 | |||
84 | } | ||
85 | else /* repeat? */ | ||
86 | { | ||
87 | if ( repeat ) | ||
88 | { | ||
89 | count--; | ||
90 | if (count == 0) { | ||
91 | post = true; | ||
92 | /* yes we have repeat */ | ||
93 | repeat_speed--; | ||
94 | if (repeat_speed < REPEAT_INTERVAL_FINISH) | ||
95 | repeat_speed = REPEAT_INTERVAL_FINISH; | ||
96 | count = repeat_speed; | ||
97 | |||
98 | repeat_count++; | ||
99 | |||
100 | } | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | if (count++ > REPEAT_START) | ||
105 | { | ||
106 | post = true; | ||
107 | repeat = true; | ||
108 | repeat_count = 0; | ||
109 | /* initial repeat */ | ||
110 | count = REPEAT_INTERVAL_START; | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | if ( post ) | ||
115 | { | ||
116 | if (repeat) | ||
117 | queue_post(&button_queue, BUTTON_REPEAT | btn, NULL); | ||
118 | else | ||
119 | queue_post(&button_queue, btn, NULL); | ||
120 | #ifdef HAVE_REMOTE_LCD | ||
121 | if(btn & BUTTON_REMOTE) | ||
122 | remote_backlight_on(); | ||
123 | else | ||
124 | #endif | ||
125 | backlight_on(); | ||
126 | |||
127 | } | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | repeat = false; | ||
132 | count = 0; | ||
133 | } | ||
134 | } | ||
135 | lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); | ||
136 | tick = 0; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | /* | ||
141 | * Read SDL keys and translate to rockbox buttons | ||
142 | */ | ||
143 | |||
144 | void button_read (void) | ||
145 | { | ||
146 | int k; | ||
147 | bool release = false; /* is this a release event */ | ||
148 | int ev = screenhack_handle_events(&release); | ||
149 | |||
150 | switch (ev) | ||
151 | { | ||
152 | case SDLK_KP4: | ||
153 | case SDLK_LEFT: | ||
154 | case SDLK_4: | ||
155 | k = BUTTON_LEFT; | ||
156 | break; | ||
157 | |||
158 | case SDLK_KP6: | ||
159 | case SDLK_RIGHT: | ||
160 | case SDLK_6: | ||
161 | k = BUTTON_RIGHT; | ||
162 | break; | ||
163 | |||
164 | case SDLK_KP8: | ||
165 | case SDLK_UP: | ||
166 | case SDLK_8: | ||
167 | #ifdef BUTTON_UP | ||
168 | k = BUTTON_UP; | ||
169 | #elif defined BUTTON_SCROLL_BACK | ||
170 | k = BUTTON_SCROLL_BACK; | ||
171 | #elif defined BUTTON_PLAY | ||
172 | k = BUTTON_PLAY; | ||
173 | #endif | ||
174 | break; | ||
175 | |||
176 | case SDLK_KP2: | ||
177 | case SDLK_DOWN: | ||
178 | case SDLK_2: | ||
179 | #ifdef BUTTON_DOWN | ||
180 | k = BUTTON_DOWN; | ||
181 | #elif defined BUTTON_SCROLL_FWD | ||
182 | k = BUTTON_SCROLL_FWD; | ||
183 | #elif defined BUTTON_STOP | ||
184 | k = BUTTON_STOP; | ||
185 | #endif | ||
186 | break; | ||
187 | |||
188 | #ifdef BUTTON_ON | ||
189 | case SDLK_KP_PLUS: | ||
190 | case SDLK_q: | ||
191 | k = BUTTON_ON; | ||
192 | break; | ||
193 | #endif | ||
194 | |||
195 | #ifdef BUTTON_OFF | ||
196 | case SDLK_KP_ENTER: | ||
197 | case SDLK_a: | ||
198 | k = BUTTON_OFF; | ||
199 | break; | ||
200 | #endif | ||
201 | |||
202 | #ifdef BUTTON_POWER | ||
203 | case SDLK_KP_MINUS: | ||
204 | case SDLK_p: | ||
205 | k = BUTTON_POWER; | ||
206 | #endif | ||
207 | |||
208 | #ifdef BUTTON_F1 | ||
209 | case SDLK_KP_DIVIDE: | ||
210 | case SDLK_F1: | ||
211 | k = BUTTON_F1; | ||
212 | break; | ||
213 | |||
214 | case SDLK_KP_MULTIPLY: | ||
215 | case SDLK_F2: | ||
216 | k = BUTTON_F2; | ||
217 | break; | ||
218 | |||
219 | case SDLK_KP_MINUS: | ||
220 | case SDLK_F3: | ||
221 | k = BUTTON_F3; | ||
222 | break; | ||
223 | #elif defined(BUTTON_REC) | ||
224 | case SDLK_KP_DIVIDE: | ||
225 | case SDLK_F1: | ||
226 | k = BUTTON_REC; | ||
227 | break; | ||
228 | #endif | ||
229 | |||
230 | case SDLK_KP5: | ||
231 | case SDLK_5: | ||
232 | case SDLK_SPACE: | ||
233 | #ifdef BUTTON_PLAY | ||
234 | k = BUTTON_PLAY; | ||
235 | #elif defined(BUTTON_SELECT) | ||
236 | k = BUTTON_SELECT; | ||
237 | #endif | ||
238 | break; | ||
239 | |||
240 | #ifdef HAVE_LCD_BITMAP | ||
241 | case SDLK_7: | ||
242 | if(!release) | ||
243 | screen_dump(); | ||
244 | break; | ||
245 | #endif | ||
246 | |||
247 | case SDLK_KP_PERIOD: | ||
248 | case SDLK_INSERT: | ||
249 | #ifdef BUTTON_MENU | ||
250 | k = BUTTON_MENU; | ||
251 | #elif defined(BUTTON_MODE) | ||
252 | k = BUTTON_MODE; | ||
253 | #endif | ||
254 | break; | ||
255 | |||
256 | default: | ||
257 | k = 0; | ||
258 | if(ev) | ||
259 | DEBUGF("received ev %d\n", ev); | ||
260 | break; | ||
261 | } | ||
262 | |||
263 | if (release) | ||
264 | button_state &= ~k; | ||
265 | else | ||
266 | button_state |= k; | ||
267 | } | ||
268 | |||
269 | /* Again copied from real button.c... */ | ||
270 | |||
271 | long button_get(bool block) | ||
272 | { | ||
273 | struct event ev; | ||
274 | |||
275 | if ( block || !queue_empty(&button_queue) ) | ||
276 | { | ||
277 | queue_wait(&button_queue, &ev); | ||
278 | return ev.id; | ||
279 | } | ||
280 | return BUTTON_NONE; | ||
281 | } | ||
282 | |||
283 | long button_get_w_tmo(int ticks) | ||
284 | { | ||
285 | struct event ev; | ||
286 | queue_wait_w_tmo(&button_queue, &ev, ticks); | ||
287 | return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE; | ||
288 | } | ||
289 | |||
290 | void button_init(void) | ||
291 | { | ||
292 | tick_add_task(button_tick); | ||
293 | } | ||
294 | |||
295 | int button_status(void) | ||
296 | { | ||
297 | return lastbtn; | ||
298 | } | ||
299 | |||
300 | void button_clear_queue(void) | ||
301 | { | ||
302 | queue_clear(&button_queue); | ||
303 | } | ||
304 | |||
305 | #ifdef HAS_BUTTON_HOLD | ||
306 | bool button_hold(void) { | ||
307 | /* temp fix for hold button on irivers */ | ||
308 | return false; | ||
309 | } | ||
310 | #endif | ||
311 | |||
312 | #ifdef HAS_REMOTE_BUTTON_HOLD | ||
313 | bool remote_button_hold(void) { | ||
314 | /* temp fix for hold button on irivers */ | ||
315 | return false; | ||
316 | } | ||
317 | #endif | ||