From 716aa1f33a5f921ea3b0458bcfcae7bbbcf08d09 Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 24 Jul 2014 02:51:46 -0500 Subject: [PATCH] sdl2: fix mouse motion (remove -mousewarp) --- src/sdl2/i_video.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/sdl2/i_video.c b/src/sdl2/i_video.c index 8731c2d8..43485540 100644 --- a/src/sdl2/i_video.c +++ b/src/sdl2/i_video.c @@ -129,7 +129,6 @@ static Uint16 realheight = BASEVIDHEIGHT; static const Uint32 surfaceFlagsW = 0/*|SDL_RESIZABLE*/; static const Uint32 surfaceFlagsF = 0; static SDL_bool mousegrabok = SDL_TRUE; -static SDL_bool mousewarp = SDL_FALSE; #define HalfWarpMouse(x,y) SDL_WarpMouseInWindow(window, (Uint16)(x/2),(Uint16)(y/2)) static SDL_bool videoblitok = SDL_FALSE; static SDL_bool exposevideo = SDL_FALSE; @@ -760,6 +759,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_FOCUS_GAINED: kbfocus = SDL_TRUE; + mousefocus = SDL_TRUE; break; case SDL_WINDOWEVENT_FOCUS_LOST: kbfocus = SDL_FALSE; @@ -800,7 +800,6 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) if (MOUSE_MENU) { SDLdoUngrabMouse(); - return; } } @@ -832,43 +831,26 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) SDL_GetWindowSize(window, &wwidth, &wheight); - if (MOUSE_MENU) + if ((SDL_GetMouseFocus() != window && SDL_GetKeyboardFocus() != window)) { SDLdoUngrabMouse(); return; } - if (mousewarp && (evt.x == wwidth/2) && (evt.y == wheight/2)) + if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } else { - event.data2 = +evt.xrel; - event.data3 = -evt.yrel; + event.data2 = (evt.xrel) * (wwidth / realwidth) * 2; + event.data3 = -evt.yrel * (wheight / realheight) * 2; } event.type = ev_mouse; D_PostEvent(&event); - if (mousewarp) - { - // Warp the pointer back to the middle of the window - // or we cannot move any further if it's at a border. - if ((evt.x < (wwidth/2 )-(wwidth/4 )) || - (evt.y < (wheight/2)-(wheight/4)) || - (evt.x > (wwidth/2 )+(wwidth/4 )) || - (evt.y > (wheight/2)+(wheight/4) ) ) - { - HalfWarpMouse(wwidth, wheight); - } - } - else - { - SDL_SetWindowGrab(window, mousegrabok); - SDL_SetRelativeMouseMode(SDL_TRUE); - } - + HalfWarpMouse(wwidth, wheight); } static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type) @@ -1902,8 +1884,6 @@ void I_StartupGraphics(void) if (M_CheckParm("-nomousegrab")) mousegrabok = SDL_FALSE; - else if (M_CheckParm("-mousewarp") || SDL_SetRelativeMouseMode(SDL_TRUE) == -1) - mousewarp = SDL_TRUE; #if 0 // defined (_DEBUG) else {