|
|
|
@ -164,7 +164,26 @@ sc_screen_is_relative_mode(struct sc_screen *screen) {
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
static void
|
|
|
|
sc_screen_set_mouse_capture(struct sc_screen *screen, bool capture) {
|
|
|
|
sc_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;
|
|
|
|
(void) screen;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
if (SDL_SetRelativeMouseMode(capture)) {
|
|
|
|
if (SDL_SetRelativeMouseMode(capture)) {
|
|
|
|
LOGE("Could not set relative mouse mode to %s: %s",
|
|
|
|
LOGE("Could not set relative mouse mode to %s: %s",
|
|
|
|
capture ? "true" : "false", SDL_GetError());
|
|
|
|
capture ? "true" : "false", SDL_GetError());
|
|
|
|
|