Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

touchscreen: Update action system touch event reporting

Add a cleaner API for reporting touch events and deprecate the old
action_get_touchscreen_press() API. The old API is now emulated by
using the new one internally.

Change-Id: I001378e66f9c81806f134f011420d671954fcde2

authored by

Aidan MacDonald and committed by
Solomon Peachy
9e254aca fa164f89

+99 -66
+80 -49
apps/action.c
··· 101 101 #endif 102 102 103 103 #ifdef HAVE_TOUCHSCREEN 104 - bool ts_short_press; 105 - int ts_data; 104 + int ts_data; 105 + long ts_start_tick; 106 + struct touchevent touchevent; 106 107 #endif 107 108 } action_last_t; 108 109 ··· 123 124 #endif 124 125 125 126 #ifdef HAVE_TOUCHSCREEN 126 - .ts_data = 0, 127 - .ts_short_press = false, 127 + .ts_data = 0, 128 + .ts_start_tick = 0, 128 129 #endif 129 130 130 131 #ifdef HAVE_BACKLIGHT ··· 414 415 } 415 416 416 417 /*********************************************** 417 - * get_action_touchscreen allows touchscreen 418 - * presses to have short_press and repeat events 418 + * handles touch event processing 419 419 */ 420 420 static inline bool get_action_touchscreen(action_last_t *last, action_cur_t *cur) 421 421 { 422 - 423 422 #if !defined(HAVE_TOUCHSCREEN) 424 423 (void) last; 425 424 (void) cur; ··· 427 426 #else 428 427 if (has_flag(cur->button, BUTTON_TOUCHSCREEN)) 429 428 { 430 - last->repeated = false; 431 - last->ts_short_press = false; 432 - if (has_flag(last->button, BUTTON_TOUCHSCREEN)) 429 + intptr_t data = button_get_data(); 430 + long now = current_tick; 431 + 432 + if (has_flag(last->button, BUTTON_TOUCHSCREEN) && 433 + !has_flag(last->button, BUTTON_REL)) 433 434 { 434 - if (has_flag(cur->button, BUTTON_REL) && 435 - !has_flag(last->button, BUTTON_REPEAT)) 436 - { 437 - last->ts_short_press = true; 438 - } 439 - else if (has_flag(cur->button, BUTTON_REPEAT)) 440 - { 435 + /* Only update the coordinates if this is not a release event. 436 + * For release events, we reuse the previous event coordinates. */ 437 + if (!has_flag(cur->button, BUTTON_REL)) 438 + last->ts_data = data; 439 + 440 + /* Historical baggage... may be unnecessary. */ 441 + if (has_flag(cur->button, BUTTON_REPEAT)) 441 442 last->repeated = true; 442 - } 443 + } 444 + else 445 + { 446 + /* Ignore isolated release events. No good can come of this. */ 447 + if (has_flag(cur->button, BUTTON_REL)) 448 + return false; 449 + 450 + last->ts_data = data; 451 + last->ts_start_tick = now; 443 452 } 444 453 445 454 last->button = cur->button; 446 - last->tick = current_tick; 455 + last->tick = now; 447 456 cur->action = ACTION_TOUCHSCREEN; 457 + 458 + /* Update touchevent data */ 459 + if (has_flag(last->button, BUTTON_REL)) 460 + last->touchevent.type = TOUCHEVENT_RELEASE; 461 + else if (has_flag(last->button, BUTTON_REPEAT)) 462 + last->touchevent.type = TOUCHEVENT_CONTACT; 463 + else 464 + last->touchevent.type = TOUCHEVENT_PRESS; 465 + 466 + last->touchevent.x = (last->ts_data >> 16) & 0xffff; 467 + last->touchevent.y = last->ts_data & 0xffff; 468 + last->touchevent.tick = last->tick; 469 + 448 470 return true; 471 + } 472 + else 473 + { 474 + last->touchevent.type = TOUCHEVENT_NONE; 449 475 } 450 476 451 477 return false; ··· 1117 1143 ******************************************************************************* 1118 1144 */ 1119 1145 #ifdef HAVE_TOUCHSCREEN 1146 + int action_get_touch_event(struct touchevent *ev) 1147 + { 1148 + if (ev) 1149 + *ev = action_last.touchevent; 1150 + 1151 + return action_last.touchevent.type; 1152 + } 1153 + 1120 1154 /* return BUTTON_NONE on error 1121 1155 * BUTTON_REPEAT if repeated press 1122 1156 * BUTTON_REPEAT|BUTTON_REL if release after repeated press 1123 1157 * BUTTON_REL if it's a short press = release after press 1124 1158 * BUTTON_TOUCHSCREEN if press 1159 + * DEPRECATED, do not use it anymore. 1125 1160 */ 1126 1161 int action_get_touchscreen_press(short *x, short *y) 1127 1162 { 1163 + /* historical default value */ 1164 + const long long_press_time = 30 * HZ / 100; 1128 1165 1129 - int data; 1130 - int ret = BUTTON_TOUCHSCREEN; 1166 + int ret; 1167 + struct touchevent ev; 1168 + switch (action_get_touch_event(&ev)) 1169 + { 1170 + case TOUCHEVENT_PRESS: 1171 + case TOUCHEVENT_CONTACT: 1172 + if (TIME_AFTER(ev.tick, action_last.ts_start_tick + long_press_time)) 1173 + ret = BUTTON_REPEAT; 1174 + else 1175 + ret = BUTTON_TOUCHSCREEN; 1176 + break; 1131 1177 1132 - if (!has_flag(action_last.button, BUTTON_TOUCHSCREEN)) 1133 - { 1134 - return BUTTON_NONE; 1135 - } 1178 + case TOUCHEVENT_RELEASE: 1179 + if (TIME_AFTER(ev.tick, action_last.ts_start_tick + long_press_time)) 1180 + ret = BUTTON_REPEAT|BUTTON_REL; 1181 + else 1182 + ret = BUTTON_REL; 1183 + break; 1136 1184 1137 - data = button_get_data(); 1138 - if (has_flag(action_last.button, BUTTON_REL)) 1139 - { 1140 - *x = (action_last.ts_data&0xffff0000)>>16; 1141 - *y = (action_last.ts_data&0xffff); 1142 - } 1143 - else 1144 - { 1145 - *x = (data&0xffff0000)>>16; 1146 - *y = (data&0xffff); 1185 + default: 1186 + ret = BUTTON_NONE; 1187 + break; 1147 1188 } 1148 1189 1149 - action_last.ts_data = data; 1150 - 1151 - if (action_last.repeated) 1152 - { 1153 - ret = BUTTON_REPEAT; 1154 - } 1155 - else if (action_last.ts_short_press) 1156 - { 1157 - ret = BUTTON_REL; 1158 - } 1159 - /* This is to return a BUTTON_REL after a BUTTON_REPEAT. */ 1160 - else if (has_flag(action_last.button, BUTTON_REL)) 1161 - { 1162 - ret = BUTTON_REPEAT|BUTTON_REL; 1190 + if (ret != BUTTON_NONE) { 1191 + *x = ev.x; 1192 + *y = ev.y; 1163 1193 } 1164 1194 1165 1195 return ret; 1166 1196 } 1167 1197 1198 + /* DEPRECATED, do not use it anymore. */ 1168 1199 int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp) 1169 1200 { 1170 1201 short x, y;
+4 -17
apps/action.h
··· 415 415 intptr_t get_action_data(void); 416 416 417 417 #ifdef HAVE_TOUCHSCREEN 418 - /* return BUTTON_NONE on error 419 - * BUTTON_REPEAT if repeated press 420 - * BUTTON_REPEAT|BUTTON_REL if release after repeated press 421 - * BUTTON_REL if it's a short press = release after press 422 - * BUTTON_TOUCHSCREEN if press 423 - */ 418 + /* Return a touch event and screen coordinates of the touch. */ 419 + int action_get_touch_event(struct touchevent *ev); 420 + 421 + /* DEPRECATED, do not use these anymore */ 424 422 int action_get_touchscreen_press(short *x, short *y); 425 - 426 - /* 427 - * wrapper action_get_touchscreen_press() 428 - * to filter the touchscreen coordinates through a viewport 429 - * 430 - * returns the action and x1, y1 relative to the viewport if 431 - * the press was within the viewport, 432 - * ACTION_UNKNOWN (and x1, y1 untouched) if the press was outside 433 - * BUTTON_NONE else 434 - * 435 - **/ 436 423 int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp); 437 424 #endif 438 425
+15
firmware/export/touchscreen.h
··· 42 42 from button_get_data */ 43 43 }; 44 44 45 + enum touchevent_type 46 + { 47 + TOUCHEVENT_NONE = 0, 48 + TOUCHEVENT_PRESS, 49 + TOUCHEVENT_CONTACT, 50 + TOUCHEVENT_RELEASE, 51 + }; 52 + 53 + struct touchevent 54 + { 55 + int type; 56 + short x, y; 57 + long tick; 58 + }; 59 + 45 60 extern struct touchscreen_parameter calibration_parameters; 46 61 extern const struct touchscreen_parameter default_calibration_parameters; 47 62 int touchscreen_calibrate(struct touchscreen_calibration *cal);