diff options
Diffstat (limited to 'uisimulator/sdl/button.c')
-rw-r--r-- | uisimulator/sdl/button.c | 227 |
1 files changed, 31 insertions, 196 deletions
diff --git a/uisimulator/sdl/button.c b/uisimulator/sdl/button.c index 45dfc3fe2c..c52cf12f9c 100644 --- a/uisimulator/sdl/button.c +++ b/uisimulator/sdl/button.c | |||
@@ -28,15 +28,13 @@ | |||
28 | #include "backlight.h" | 28 | #include "backlight.h" |
29 | #include "misc.h" | 29 | #include "misc.h" |
30 | #include "sim_tasks.h" | 30 | #include "sim_tasks.h" |
31 | #include "button-sdl.h" | ||
31 | 32 | ||
32 | #include "debug.h" | 33 | #include "debug.h" |
33 | 34 | ||
34 | static intptr_t button_data; /* data value from last message dequeued */ | ||
35 | |||
36 | #ifdef HAVE_TOUCHSCREEN | 35 | #ifdef HAVE_TOUCHSCREEN |
37 | #include "touchscreen.h" | 36 | #include "touchscreen.h" |
38 | static int mouse_coords = 0; | 37 | static int mouse_coords = 0; |
39 | static int last_touchscreen_touch = 0xffff; | ||
40 | #endif | 38 | #endif |
41 | /* how long until repeat kicks in */ | 39 | /* how long until repeat kicks in */ |
42 | #define REPEAT_START 6 | 40 | #define REPEAT_START 6 |
@@ -91,23 +89,9 @@ bool remote_button_hold(void) { | |||
91 | } | 89 | } |
92 | #endif | 90 | #endif |
93 | 91 | ||
94 | static int lastbtn; | ||
95 | void button_event(int key, bool pressed) | 92 | void button_event(int key, bool pressed) |
96 | { | 93 | { |
97 | int new_btn = 0; | 94 | int new_btn = 0; |
98 | int diff = 0; | ||
99 | int data = 0; | ||
100 | static int count = 0; | ||
101 | static int repeat_speed = REPEAT_INTERVAL_START; | ||
102 | static int repeat_count = 0; | ||
103 | static bool repeat = false; | ||
104 | static bool post = false; | ||
105 | #ifdef HAVE_BACKLIGHT | ||
106 | static bool skip_release = false; | ||
107 | #ifdef HAVE_REMOTE_LCD | ||
108 | static bool skip_remote_release = false; | ||
109 | #endif | ||
110 | #endif | ||
111 | static bool usb_connected = false; | 95 | static bool usb_connected = false; |
112 | if (usb_connected && key != SDLK_u) | 96 | if (usb_connected && key != SDLK_u) |
113 | return; | 97 | return; |
@@ -116,7 +100,6 @@ void button_event(int key, bool pressed) | |||
116 | 100 | ||
117 | #ifdef HAVE_TOUCHSCREEN | 101 | #ifdef HAVE_TOUCHSCREEN |
118 | case BUTTON_TOUCHSCREEN: | 102 | case BUTTON_TOUCHSCREEN: |
119 | data = mouse_coords; | ||
120 | switch (touchscreen_get_mode()) | 103 | switch (touchscreen_get_mode()) |
121 | { | 104 | { |
122 | case TOUCHSCREEN_POINT: | 105 | case TOUCHSCREEN_POINT: |
@@ -129,7 +112,8 @@ void button_event(int key, bool pressed) | |||
129 | {BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT}, | 112 | {BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT}, |
130 | {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT}, | 113 | {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT}, |
131 | }; | 114 | }; |
132 | int px_x = ((data&0xffff0000)>>16), px_y = ((data&0x0000ffff)); | 115 | int px_x = ((mouse_coords&0xffff0000)>>16); |
116 | int px_y = ((mouse_coords&0x0000ffff)); | ||
133 | new_btn = touchscreen_buttons[px_y/(LCD_HEIGHT/3)][px_x/(LCD_WIDTH/3)]; | 117 | new_btn = touchscreen_buttons[px_y/(LCD_HEIGHT/3)][px_x/(LCD_WIDTH/3)]; |
134 | break; | 118 | break; |
135 | } | 119 | } |
@@ -1223,177 +1207,30 @@ void button_event(int key, bool pressed) | |||
1223 | btn |= new_btn; | 1207 | btn |= new_btn; |
1224 | else | 1208 | else |
1225 | btn &= ~new_btn; | 1209 | btn &= ~new_btn; |
1226 | |||
1227 | /* Lots of stuff copied from real button.c. Not good, I think... */ | ||
1228 | |||
1229 | /* Find out if a key has been released */ | ||
1230 | diff = btn ^ lastbtn; | ||
1231 | if(diff && (btn & diff) == 0) | ||
1232 | { | ||
1233 | #ifdef HAVE_BACKLIGHT | ||
1234 | #ifdef HAVE_REMOTE_LCD | ||
1235 | if(diff & BUTTON_REMOTE) | ||
1236 | if(!skip_remote_release) | ||
1237 | queue_post(&button_queue, BUTTON_REL | diff, data); | ||
1238 | else | ||
1239 | skip_remote_release = false; | ||
1240 | else | ||
1241 | #endif | ||
1242 | if(!skip_release) | ||
1243 | queue_post(&button_queue, BUTTON_REL | diff, data); | ||
1244 | else | ||
1245 | skip_release = false; | ||
1246 | #else | ||
1247 | queue_post(&button_queue, BUTTON_REL | diff, data); | ||
1248 | #endif | ||
1249 | } | ||
1250 | |||
1251 | else | ||
1252 | { | ||
1253 | if ( btn ) | ||
1254 | { | ||
1255 | /* normal keypress */ | ||
1256 | if ( btn != lastbtn ) | ||
1257 | { | ||
1258 | post = true; | ||
1259 | repeat = false; | ||
1260 | repeat_speed = REPEAT_INTERVAL_START; | ||
1261 | |||
1262 | } | ||
1263 | else /* repeat? */ | ||
1264 | { | ||
1265 | if ( repeat ) | ||
1266 | { | ||
1267 | if (!post) | ||
1268 | count--; | ||
1269 | if (count == 0) | ||
1270 | { | ||
1271 | post = true; | ||
1272 | /* yes we have repeat */ | ||
1273 | repeat_speed--; | ||
1274 | if (repeat_speed < REPEAT_INTERVAL_FINISH) | ||
1275 | repeat_speed = REPEAT_INTERVAL_FINISH; | ||
1276 | count = repeat_speed; | ||
1277 | |||
1278 | repeat_count++; | ||
1279 | } | ||
1280 | } | ||
1281 | else | ||
1282 | { | ||
1283 | if (count++ > REPEAT_START) | ||
1284 | { | ||
1285 | post = true; | ||
1286 | repeat = true; | ||
1287 | repeat_count = 0; | ||
1288 | /* initial repeat */ | ||
1289 | count = REPEAT_INTERVAL_START; | ||
1290 | } | ||
1291 | } | ||
1292 | } | ||
1293 | if ( post ) | ||
1294 | { | ||
1295 | if(repeat) | ||
1296 | { | ||
1297 | if (queue_empty(&button_queue)) | ||
1298 | { | ||
1299 | queue_post(&button_queue, BUTTON_REPEAT | btn, data); | ||
1300 | #ifdef HAVE_BACKLIGHT | ||
1301 | #ifdef HAVE_REMOTE_LCD | ||
1302 | if(btn & BUTTON_REMOTE) | ||
1303 | { | ||
1304 | if(skip_remote_release) | ||
1305 | skip_remote_release = false; | ||
1306 | } | ||
1307 | else | ||
1308 | #endif | ||
1309 | if(skip_release) | ||
1310 | skip_release = false; | ||
1311 | #endif | ||
1312 | post = false; | ||
1313 | } | ||
1314 | } | ||
1315 | else | ||
1316 | { | ||
1317 | #ifdef HAVE_BACKLIGHT | ||
1318 | #ifdef HAVE_REMOTE_LCD | ||
1319 | if (btn & BUTTON_REMOTE) { | ||
1320 | if (!remote_filter_first_keypress | ||
1321 | || is_remote_backlight_on(false)) | ||
1322 | queue_post(&button_queue, btn, data); | ||
1323 | else | ||
1324 | skip_remote_release = true; | ||
1325 | } | ||
1326 | else | ||
1327 | #endif | ||
1328 | if (!filter_first_keypress | ||
1329 | || is_backlight_on(false)) | ||
1330 | queue_post(&button_queue, btn, data); | ||
1331 | else | ||
1332 | skip_release = true; | ||
1333 | #else /* no backlight, nothing to skip */ | ||
1334 | queue_post(&button_queue, btn, data); | ||
1335 | #endif | ||
1336 | post = false; | ||
1337 | } | ||
1338 | |||
1339 | #ifdef HAVE_REMOTE_LCD | ||
1340 | if(btn & BUTTON_REMOTE) | ||
1341 | remote_backlight_on(); | ||
1342 | else | ||
1343 | #endif | ||
1344 | backlight_on(); | ||
1345 | |||
1346 | } | ||
1347 | } | ||
1348 | else | ||
1349 | { | ||
1350 | repeat = false; | ||
1351 | count = 0; | ||
1352 | } | ||
1353 | } | ||
1354 | lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); | ||
1355 | } | 1210 | } |
1356 | 1211 | #ifdef HAVE_BUTTON_DATA | |
1357 | /* Again copied from real button.c... */ | 1212 | int button_read_device(int* data) |
1358 | |||
1359 | int button_queue_count( void ) | ||
1360 | { | 1213 | { |
1361 | return queue_count(&button_queue); | 1214 | (void)data; |
1362 | } | 1215 | #else |
1363 | 1216 | int button_read_device(void) | |
1364 | long button_get(bool block) | ||
1365 | { | 1217 | { |
1366 | struct queue_event ev; | 1218 | #endif |
1367 | 1219 | static int hold_button_old = false; | |
1368 | if ( block || !queue_empty(&button_queue) ) { | 1220 | int hold_button = button_hold(); |
1369 | queue_wait(&button_queue, &ev); | 1221 | /* light handling */ |
1370 | button_data = ev.data; | 1222 | if (hold_button != hold_button_old) |
1371 | return ev.id; | 1223 | { |
1224 | hold_button_old = hold_button; | ||
1225 | backlight_hold_changed(hold_button); | ||
1372 | } | 1226 | } |
1373 | return BUTTON_NONE; | ||
1374 | } | ||
1375 | 1227 | ||
1376 | long button_get_w_tmo(int ticks) | 1228 | if (hold_button) |
1377 | { | 1229 | return BUTTON_NONE; |
1378 | struct queue_event ev; | ||
1379 | queue_wait_w_tmo(&button_queue, &ev, ticks); | ||
1380 | if (ev.id == SYS_TIMEOUT) | ||
1381 | ev.id = BUTTON_NONE; | ||
1382 | else | ||
1383 | button_data = ev.data; | ||
1384 | 1230 | ||
1385 | return ev.id; | 1231 | return btn; |
1386 | } | 1232 | } |
1387 | 1233 | ||
1388 | intptr_t button_get_data(void) | ||
1389 | { | ||
1390 | #ifdef HAVE_TOUCHSCREEN | ||
1391 | return button_data; | ||
1392 | #else | ||
1393 | /* Needed by the accelerating wheel driver for Sansa e200 */ | ||
1394 | return 1 << 24; | ||
1395 | #endif | ||
1396 | } | ||
1397 | 1234 | ||
1398 | #ifdef HAVE_TOUCHSCREEN | 1235 | #ifdef HAVE_TOUCHSCREEN |
1399 | extern bool debug_wps; | 1236 | extern bool debug_wps; |
@@ -1416,31 +1253,29 @@ void mouse_tick_task(void) | |||
1416 | } | 1253 | } |
1417 | 1254 | ||
1418 | mouse_coords = (x<<16)|y; | 1255 | mouse_coords = (x<<16)|y; |
1419 | last_touchscreen_touch = current_tick; | ||
1420 | button_event(BUTTON_TOUCHSCREEN, true); | 1256 | button_event(BUTTON_TOUCHSCREEN, true); |
1421 | if (debug_wps) | 1257 | if (debug_wps) |
1422 | printf("Mouse at: (%d, %d)\n", x, y); | 1258 | printf("Mouse at: (%d, %d)\n", x, y); |
1423 | } | 1259 | } |
1424 | } | 1260 | } |
1425 | int touchscreen_last_touch(void) | 1261 | |
1426 | { | ||
1427 | return last_touchscreen_touch; | ||
1428 | } | ||
1429 | #endif | 1262 | #endif |
1430 | void button_init(void) | 1263 | |
1264 | intptr_t button_get_data_sdl(void) | ||
1431 | { | 1265 | { |
1432 | #ifdef HAVE_TOUCHSCREEN | 1266 | #ifdef HAVE_TOUCHSCREEN |
1433 | tick_add_task(mouse_tick_task); | 1267 | /* pass the mouse coordinates to the button driver */ |
1268 | return mouse_coords; | ||
1269 | #else | ||
1270 | /* pass scrollwheel acceleration to the button driver */ | ||
1271 | return 1<<24; | ||
1434 | #endif | 1272 | #endif |
1435 | } | 1273 | } |
1436 | 1274 | ||
1437 | int button_status(void) | 1275 | void button_init_sdl(void) |
1438 | { | ||
1439 | return btn; | ||
1440 | } | ||
1441 | |||
1442 | void button_clear_queue(void) | ||
1443 | { | 1276 | { |
1444 | queue_clear(&button_queue); | 1277 | #ifdef HAVE_TOUCHSCREEN |
1278 | tick_add_task(mouse_tick_task); | ||
1279 | #endif | ||
1445 | } | 1280 | } |
1446 | 1281 | ||