Report errors on screen event error

Make scrcpy fail if an important screen event (like frame update) fails.
This commit is contained in:
Romain Vimont 2023-03-10 22:49:40 +01:00
parent aa1efbc35c
commit 3a72f3fb4d
3 changed files with 17 additions and 12 deletions

View file

@ -175,7 +175,9 @@ event_loop(struct scrcpy *s) {
LOGD("User requested to quit"); LOGD("User requested to quit");
return SCRCPY_EXIT_SUCCESS; return SCRCPY_EXIT_SUCCESS;
default: default:
sc_screen_handle_event(&s->screen, &event); if (!sc_screen_handle_event(&s->screen, &event)) {
return SCRCPY_EXIT_FAILURE;
}
break; break;
} }
} }

View file

@ -790,7 +790,7 @@ sc_screen_is_mouse_capture_key(SDL_Keycode key) {
return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI; return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI;
} }
void bool
sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) { sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
bool relative_mode = sc_screen_is_relative_mode(screen); bool relative_mode = sc_screen_is_relative_mode(screen);
@ -798,14 +798,15 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
case SC_EVENT_NEW_FRAME: { case SC_EVENT_NEW_FRAME: {
bool ok = sc_screen_update_frame(screen); bool ok = sc_screen_update_frame(screen);
if (!ok) { if (!ok) {
LOGW("Frame update failed\n"); LOGE("Frame update failed\n");
return false;
} }
return; return true;
} }
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
if (!screen->has_frame) { if (!screen->has_frame) {
// Do nothing // Do nothing
return; return true;
} }
switch (event->window.event) { switch (event->window.event) {
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
@ -836,7 +837,7 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
} }
break; break;
} }
return; return true;
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (relative_mode) { if (relative_mode) {
SDL_Keycode key = event->key.keysym.sym; SDL_Keycode key = event->key.keysym.sym;
@ -849,7 +850,7 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
screen->mouse_capture_key_pressed = 0; screen->mouse_capture_key_pressed = 0;
} }
// Mouse capture keys are never forwarded to the device // Mouse capture keys are never forwarded to the device
return; return true;
} }
} }
break; break;
@ -865,7 +866,7 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
sc_screen_toggle_mouse_capture(screen); sc_screen_toggle_mouse_capture(screen);
} }
// Mouse capture keys are never forwarded to the device // Mouse capture keys are never forwarded to the device
return; return true;
} }
} }
break; break;
@ -875,7 +876,7 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
if (relative_mode && !sc_screen_get_mouse_capture(screen)) { if (relative_mode && !sc_screen_get_mouse_capture(screen)) {
// Do not forward to input manager, the mouse will be captured // Do not forward to input manager, the mouse will be captured
// on SDL_MOUSEBUTTONUP // on SDL_MOUSEBUTTONUP
return; return true;
} }
break; break;
case SDL_FINGERMOTION: case SDL_FINGERMOTION:
@ -884,18 +885,19 @@ sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event) {
if (relative_mode) { if (relative_mode) {
// Touch events are not compatible with relative mode // Touch events are not compatible with relative mode
// (coordinates are not relative) // (coordinates are not relative)
return; return true;
} }
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (relative_mode && !sc_screen_get_mouse_capture(screen)) { if (relative_mode && !sc_screen_get_mouse_capture(screen)) {
sc_screen_set_mouse_capture(screen, true); sc_screen_set_mouse_capture(screen, true);
return; return true;
} }
break; break;
} }
sc_input_manager_handle_event(&screen->im, event); sc_input_manager_handle_event(&screen->im, event);
return true;
} }
struct sc_point struct sc_point

View file

@ -136,7 +136,8 @@ void
sc_screen_set_rotation(struct sc_screen *screen, unsigned rotation); sc_screen_set_rotation(struct sc_screen *screen, unsigned rotation);
// react to SDL events // react to SDL events
void // If this function returns false, scrcpy must exit with an error.
bool
sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event); sc_screen_handle_event(struct sc_screen *screen, SDL_Event *event);
// convert point from window coordinates to frame coordinates // convert point from window coordinates to frame coordinates