Display and control your Android device
Work around mouse capture SDL bug on macOS
Romain Vimont3ee3f8dc027f
diff --git a/app/src/screen.c b/app/src/screen.cindex 7ca9bfb7..ae28e6e6 100644--- a/app/src/screen.c+++ b/app/src/screen.c@@ -164,7 +164,26 @@ sc_screen_is_relative_mode(struct sc_screen *screen) {static voidsc_screen_set_mouse_capture(struct sc_screen *screen, bool capture) {+#ifdef __APPLE__+ // Workaround for SDL bug on macOS:+ // <https://github.com/libsdl-org/SDL/issues/5340>+ if (capture) {+ int mouse_x, mouse_y;+ SDL_GetGlobalMouseState(&mouse_x, &mouse_y);++ int x, y, w, h;+ SDL_GetWindowPosition(screen->window, &x, &y);+ SDL_GetWindowSize(screen->window, &w, &h);++ bool outside_window = mouse_x < x || mouse_x >= x + w+ || mouse_y < y || mouse_y >= y + h;+ if (outside_window) {+ SDL_WarpMouseInWindow(screen->window, w / 2, h / 2);+ }+ }+#else(void) screen;+#endifif (SDL_SetRelativeMouseMode(capture)) {LOGE("Could not set relative mouse mode to %s: %s",capture ? "true" : "false", SDL_GetError());diff --git a/app/src/usb/screen_otg.c b/app/src/usb/screen_otg.cindex 96d7eaff..561a84ca 100644--- a/app/src/usb/screen_otg.c+++ b/app/src/usb/screen_otg.c@@ -6,7 +6,26 @@static voidsc_screen_otg_set_mouse_capture(struct sc_screen_otg *screen, bool capture) {+#ifdef __APPLE__+ // Workaround for SDL bug on macOS:+ // <https://github.com/libsdl-org/SDL/issues/5340>+ if (capture) {+ int mouse_x, mouse_y;+ SDL_GetGlobalMouseState(&mouse_x, &mouse_y);++ int x, y, w, h;+ SDL_GetWindowPosition(screen->window, &x, &y);+ SDL_GetWindowSize(screen->window, &w, &h);++ bool outside_window = mouse_x < x || mouse_x >= x + w+ || mouse_y < y || mouse_y >= y + h;+ if (outside_window) {+ SDL_WarpMouseInWindow(screen->window, w / 2, h / 2);+ }+ }+#else(void) screen;+#endifif (SDL_SetRelativeMouseMode(capture)) {LOGE("Could not set relative mouse mode to %s: %s",capture ? "true" : "false", SDL_GetError());