From c0ceb74931559a075e6925acdb4a26ea5c6086a7 Mon Sep 17 00:00:00 2001 From: rakslice Date: Tue, 10 Nov 2020 22:05:11 -0800 Subject: [PATCH 1/2] fix mouse warp destination coordinates; don't warp mouse cursor when it is not on the mac screen (cherry picked from commit aa92a09475b2a18f51d21f10f2acd4242205db6c) --- BasiliskII/src/SDL/video_sdl2.cpp | 44 ++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/BasiliskII/src/SDL/video_sdl2.cpp b/BasiliskII/src/SDL/video_sdl2.cpp index f5132ee1..68ef2aa2 100644 --- a/BasiliskII/src/SDL/video_sdl2.cpp +++ b/BasiliskII/src/SDL/video_sdl2.cpp @@ -1937,6 +1937,38 @@ int16 video_mode_change(VidLocals *csSave, uint32 ParamPtr) } #endif +static bool is_cursor_in_mac_screen() { + + int windowX, windowY; + int cursorX, cursorY; + int deltaX, deltaY; + bool out; + + // TODO figure out a check for full screen mode + if (display_type == DISPLAY_SCREEN) + return true; + + if (display_type == DISPLAY_WINDOW) { + + if (sdl_window == NULL || SDL_GetMouseFocus() != sdl_window) + return false; + + SDL_GetWindowPosition(sdl_window, &windowX, &windowY); + SDL_GetGlobalMouseState(&cursorX, &cursorY); + deltaX = cursorX - windowX; + deltaY = cursorY - windowY; + D(bug("cursor relative {%d,%d}\n", deltaX, deltaY)); + const VIDEO_MODE &mode = drv->mode; + const int m = get_mag_rate(); + out = deltaX >= 0 && deltaX < VIDEO_MODE_X * m && + deltaY >= 0 && deltaY < VIDEO_MODE_Y * m; + D(bug("cursor in window? %s\n", out? "yes" : "no")); + return out; + } + + return false; +} + void SDL_monitor_desc::switch_to_current_mode(void) { // Close and reopen display @@ -1992,10 +2024,14 @@ void video_set_cursor(void) if (move) { int visible = SDL_ShowCursor(-1); if (visible) { - int x, y; - SDL_GetMouseState(&x, &y); - printf("WarpMouse to {%d,%d} via video_set_cursor\n", x, y); - SDL_WarpMouseGlobal(x, y); + bool cursor_in_window = is_cursor_in_mac_screen(); + + if (cursor_in_window) { + int x, y; + SDL_GetMouseState(&x, &y); + printf("WarpMouse to {%d,%d} via video_set_cursor\n", x, y); + SDL_WarpMouseInWindow(sdl_window, x, y); + } } } } From 991496a4f4801c77dfb6273d560f76f5282ce0e9 Mon Sep 17 00:00:00 2001 From: rakslice Date: Thu, 12 Nov 2020 16:37:06 -0800 Subject: [PATCH 2/2] Make the video_sdl2 warpmouse output a debug message (cherry picked from commit 69574d53a9511b64092304f0969a31da4789051a) --- BasiliskII/src/SDL/video_sdl2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BasiliskII/src/SDL/video_sdl2.cpp b/BasiliskII/src/SDL/video_sdl2.cpp index 68ef2aa2..ea90b8fe 100644 --- a/BasiliskII/src/SDL/video_sdl2.cpp +++ b/BasiliskII/src/SDL/video_sdl2.cpp @@ -2029,7 +2029,7 @@ void video_set_cursor(void) if (cursor_in_window) { int x, y; SDL_GetMouseState(&x, &y); - printf("WarpMouse to {%d,%d} via video_set_cursor\n", x, y); + D(bug("WarpMouse to {%d,%d} via video_set_cursor\n", x, y)); SDL_WarpMouseInWindow(sdl_window, x, y); } }