From 758e9c455888dea5b7cabfa77da267a2ded7e8e8 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 19 Aug 2017 21:39:04 +0100 Subject: [PATCH] Merge all (relative) mouse motion events into one mouse event This fixes SDL2_RelMouse's weaker sensitivity for me on Windows (but apparently not for others??) --- src/sdl/i_video.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 2bcef916..d1ec5d44 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -606,6 +606,8 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) if (event.data1) D_PostEvent(&event); } +static int mousemovex, mousemovey; + static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) { event_t event; @@ -623,10 +625,20 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) if (SDL_GetRelativeMouseMode()) { - event.data2 = evt.xrel; - event.data3 = -evt.yrel; + //event.data2 = evt.xrel; + //event.data3 = -evt.yrel; + if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) + { + mousemovex += evt.xrel; + mousemovey += -evt.yrel; + SDL_SetWindowGrab(window, SDL_TRUE); + } + return; } - else if ((evt.x == realwidth/2) && (evt.y == realheight/2)) + + SDL_memset(&event, 0, sizeof(event_t)); + + if ((evt.x == realwidth/2) && (evt.y == realheight/2)) { return; } @@ -792,7 +804,8 @@ void I_GetEvent(void) SDL_Event evt; // We only want the first motion event, // otherwise we'll end up catching the warp back to center. - int mouseMotionOnce = 0; + //int mouseMotionOnce = 0; + mousemovex = mousemovey = 0; if (!graphics_started) { @@ -811,8 +824,9 @@ void I_GetEvent(void) Impl_HandleKeyboardEvent(evt.key, evt.type); break; case SDL_MOUSEMOTION: - if (!mouseMotionOnce) Impl_HandleMouseMotionEvent(evt.motion); - mouseMotionOnce = 1; + //if (!mouseMotionOnce) + Impl_HandleMouseMotionEvent(evt.motion); + //mouseMotionOnce = 1; break; case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: @@ -835,6 +849,17 @@ void I_GetEvent(void) } } + if (mousemovex || mousemovey) + { + event_t event; + SDL_memset(&event, 0, sizeof(event_t)); + event.type = ev_mouse; + event.data1 = 0; + event.data2 = mousemovex; + event.data3 = mousemovey; + D_PostEvent(&event); + } + // In order to make wheels act like buttons, we have to set their state to Up. // This is because wheel messages don't have an up/down state. gamekeydown[KEY_MOUSEWHEELDOWN] = gamekeydown[KEY_MOUSEWHEELUP] = 0;