1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 23:08:14 +00:00

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

fixes #973
This commit is contained in:
matejcik 2022-05-05 23:14:20 +02:00 committed by matejcik
parent feb96c84b0
commit 99c817bad4
5 changed files with 35 additions and 28 deletions

View File

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

View File

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

View File

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

View File

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

View File

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