diff --git a/core/.changelog.d/973.fixed b/core/.changelog.d/973.fixed new file mode 100644 index 000000000..c03f3f63f --- /dev/null +++ b/core/.changelog.d/973.fixed @@ -0,0 +1 @@ +_(Emulator)_ Emulator window will always react to shutdown events, even while waiting for USB packets. diff --git a/core/embed/extmod/modtrezorio/modtrezorio-poll.h b/core/embed/extmod/modtrezorio/modtrezorio-poll.h index ac9f9138f..e67717fa0 100644 --- a/core/embed/extmod/modtrezorio/modtrezorio-poll.h +++ b/core/embed/extmod/modtrezorio/modtrezorio-poll.h @@ -20,6 +20,7 @@ #include #include "button.h" +#include "common.h" #include "display.h" #include "embed/extmod/trezorobj.h" @@ -72,6 +73,10 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref, const mp_uint_t iface = i & 0x00FF; const mp_uint_t mode = i & 0xFF00; +#if defined TREZOR_EMULATOR + emulator_poll_events(); +#endif + if (false) { } #if defined TREZOR_MODEL_T diff --git a/core/embed/unix/common.c b/core/embed/unix/common.c index 6b71b7057..8549b4bab 100644 --- a/core/embed/unix/common.c +++ b/core/embed/unix/common.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -115,6 +116,33 @@ error_shutdown(const char *line1, const char *line2, const char *line3, void hal_delay(uint32_t ms) { usleep(1000 * ms); } +static int SDLCALL emulator_event_filter(void *userdata, SDL_Event *event) { + switch (event->type) { + case SDL_QUIT: + __shutdown(); + return 0; + case SDL_KEYUP: + if (event->key.repeat) { + return 0; + } + switch (event->key.keysym.sym) { + case SDLK_ESCAPE: + __shutdown(); + return 0; + case SDLK_p: + display_save("emu"); + return 0; + } + break; + } + return 1; +} + +void emulator_poll_events(void) { + SDL_PumpEvents(); + SDL_FilterEvents(emulator_event_filter, NULL); +} + uint8_t HW_ENTROPY_DATA[HW_ENTROPY_LEN]; void collect_hw_entropy(void) { memzero(HW_ENTROPY_DATA, HW_ENTROPY_LEN); } diff --git a/core/embed/unix/common.h b/core/embed/unix/common.h index f7040876c..9641f3b29 100644 --- a/core/embed/unix/common.h +++ b/core/embed/unix/common.h @@ -53,6 +53,7 @@ error_shutdown(const char *line1, const char *line2, const char *line3, : __fatal_error(#expr, msg, __FILE__, __LINE__, __func__)) void hal_delay(uint32_t ms); +void emulator_poll_events(void); void collect_hw_entropy(void); #define HW_ENTROPY_LEN (12 + 32) diff --git a/core/embed/unix/touch.c b/core/embed/unix/touch.c index 171e551de..7ccca305a 100644 --- a/core/embed/unix/touch.c +++ b/core/embed/unix/touch.c @@ -24,28 +24,6 @@ extern void __shutdown(void); extern const char *display_save(const char *prefix); -static bool handle_emulator_events(const SDL_Event *event) { - switch (event->type) { - case SDL_KEYUP: - if (event->key.repeat) { - break; - } - switch (event->key.keysym.sym) { - case SDLK_ESCAPE: - __shutdown(); - return true; - case SDLK_p: - display_save("emu"); - return true; - } - break; - case SDL_QUIT: - __shutdown(); - return true; - } - return false; -} - #if defined TREZOR_MODEL_T #include "touch.h" @@ -57,9 +35,6 @@ uint32_t touch_read(void) { SDL_Event event; SDL_PumpEvents(); if (SDL_PollEvent(&event) > 0) { - if (handle_emulator_events(&event)) { - return 0; - } switch (event.type) { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEMOTION: @@ -110,9 +85,6 @@ uint32_t button_read(void) { SDL_Event event; SDL_PumpEvents(); if (SDL_PollEvent(&event) > 0) { - if (handle_emulator_events(&event)) { - return 0; - } switch (event.type) { case SDL_KEYDOWN: if (event.key.repeat) {