remove extraneous motion events from queue

This commit is contained in:
Pavol Rusnak 2016-04-29 17:29:46 +02:00
parent 9856f96cf7
commit 11190fccba
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 12 additions and 1 deletions

View File

@ -55,7 +55,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
if (to < 0) {
to = 0;
}
while (to >= 0) {
for(;;) {
uint32_t e = msg_poll_ui_event();
if (e) {
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
@ -71,6 +71,9 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
memcpy(vstr.buf, m, 64);
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
if (to <= 0) {
break;
}
mp_hal_delay_us_fast(TICK_RESOLUTION);
to -= TICK_RESOLUTION;
}

View File

@ -38,6 +38,7 @@ uint32_t trezorui_poll_sdl_event(void)
{
SDL_Event event;
int x, y;
SDL_PumpEvents();
if (SDL_PollEvent(&event) > 0) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
@ -51,6 +52,8 @@ uint32_t trezorui_poll_sdl_event(void)
return (0x00 << 24) | (0x01 << 16) | (x << 8) | y; // touch_start
break;
case SDL_MOUSEMOTION:
// remove other SDL_MOUSEMOTION events from queue
SDL_FlushEvent(SDL_MOUSEMOTION);
if (event.motion.state) {
return (0x00 << 24) | (0x02 << 16) | (x << 8) | y; // touch_move
}
@ -60,6 +63,11 @@ uint32_t trezorui_poll_sdl_event(void)
break;
}
break;
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_ESCAPE) {
exit(3);
}
break;
case SDL_QUIT:
exit(3);
break;