fix(core/emulator): make sure SDL keyboard and quit events are always processed

fixes #973
pull/2259/head
matejcik 2 years ago committed by matejcik
parent feb96c84b0
commit 99c817bad4

@ -0,0 +1 @@
_(Emulator)_ Emulator window will always react to shutdown events, even while waiting for USB packets.

@ -20,6 +20,7 @@
#include <string.h>
#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

@ -17,6 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -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); }

@ -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)

@ -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) {

Loading…
Cancel
Save