Factorize SDL event push

Add a macro and inline function to call SDL_PushEvent() and log on error
(without actually handling the error, because there is nothing we could
do).
This commit is contained in:
Romain Vimont 2021-10-30 22:36:56 +02:00
parent dae091e3ab
commit d2d18466d4

View file

@ -57,15 +57,22 @@ struct scrcpy {
struct input_manager input_manager; struct input_manager input_manager;
}; };
static inline void
push_event(uint32_t type, const char *name) {
SDL_Event event;
event.type = type;
int ret = SDL_PushEvent(&event);
if (ret < 0) {
LOGE("Could not post %s event: %s", name, SDL_GetError());
// What could we do?
}
}
#define PUSH_EVENT(TYPE) push_event(TYPE, # TYPE)
#ifdef _WIN32 #ifdef _WIN32
BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) { BOOL WINAPI windows_ctrl_handler(DWORD ctrl_type) {
if (ctrl_type == CTRL_C_EVENT) { if (ctrl_type == CTRL_C_EVENT) {
SDL_Event event; PUSH_EVENT(SDL_QUIT);
event.type = SDL_QUIT;
int ret = SDL_PushEvent(&event);
if (ret < 0) {
LOGW("Could not post SDL_QUIT event: %s", SDL_GetError());
}
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
@ -251,13 +258,7 @@ stream_on_eos(struct stream *stream, void *userdata) {
(void) stream; (void) stream;
(void) userdata; (void) userdata;
SDL_Event stop_event; PUSH_EVENT(EVENT_STREAM_STOPPED);
stop_event.type = EVENT_STREAM_STOPPED;
int ret = SDL_PushEvent(&stop_event);
if (ret < 0) {
LOGE("Could not post stream stopped event: %s", SDL_GetError());
// XXX What could we do?
}
} }
bool bool