mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-11 16:00:57 +00:00
fix(core/emulator): make sure SDL keyboard and quit events are always processed
fixes #973
This commit is contained in:
parent
feb96c84b0
commit
99c817bad4
1
core/.changelog.d/973.fixed
Normal file
1
core/.changelog.d/973.fixed
Normal file
@ -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 <string.h>
|
||||||
|
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
|
#include "common.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "embed/extmod/trezorobj.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 iface = i & 0x00FF;
|
||||||
const mp_uint_t mode = i & 0xFF00;
|
const mp_uint_t mode = i & 0xFF00;
|
||||||
|
|
||||||
|
#if defined TREZOR_EMULATOR
|
||||||
|
emulator_poll_events();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
}
|
}
|
||||||
#if defined TREZOR_MODEL_T
|
#if defined TREZOR_MODEL_T
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.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); }
|
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];
|
uint8_t HW_ENTROPY_DATA[HW_ENTROPY_LEN];
|
||||||
|
|
||||||
void collect_hw_entropy(void) { memzero(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__))
|
: __fatal_error(#expr, msg, __FILE__, __LINE__, __func__))
|
||||||
|
|
||||||
void hal_delay(uint32_t ms);
|
void hal_delay(uint32_t ms);
|
||||||
|
void emulator_poll_events(void);
|
||||||
|
|
||||||
void collect_hw_entropy(void);
|
void collect_hw_entropy(void);
|
||||||
#define HW_ENTROPY_LEN (12 + 32)
|
#define HW_ENTROPY_LEN (12 + 32)
|
||||||
|
@ -24,28 +24,6 @@
|
|||||||
extern void __shutdown(void);
|
extern void __shutdown(void);
|
||||||
extern const char *display_save(const char *prefix);
|
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
|
#if defined TREZOR_MODEL_T
|
||||||
|
|
||||||
#include "touch.h"
|
#include "touch.h"
|
||||||
@ -57,9 +35,6 @@ uint32_t touch_read(void) {
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
if (SDL_PollEvent(&event) > 0) {
|
if (SDL_PollEvent(&event) > 0) {
|
||||||
if (handle_emulator_events(&event)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
@ -110,9 +85,6 @@ uint32_t button_read(void) {
|
|||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
if (SDL_PollEvent(&event) > 0) {
|
if (SDL_PollEvent(&event) > 0) {
|
||||||
if (handle_emulator_events(&event)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
if (event.key.repeat) {
|
if (event.key.repeat) {
|
||||||
|
Loading…
Reference in New Issue
Block a user