From 0306c1834a415900f5915901e1b887c2e5e94482 Mon Sep 17 00:00:00 2001 From: ilag11111 Date: Tue, 8 Apr 2014 19:02:45 -0700 Subject: [PATCH 1/3] Disables input grabbing in Linux; allows alt-tabbing and other actions. --- src/sdl2/i_video.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/sdl2/i_video.c b/src/sdl2/i_video.c index 6420f5342..5a835ce0f 100644 --- a/src/sdl2/i_video.c +++ b/src/sdl2/i_video.c @@ -831,32 +831,41 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) SDLdoUngrabMouse(); return; } + +#ifndef LINUX +#ifndef LINUX64 + event.data2 = +evt.xrel; + event.data3 = -evt.yrel; + event.type = ev_mouse; + D_PostEvent(&event); + SDL_SetWindowGrab(window, mousegrabok); + SDL_SetRelativeMouseMode(SDL_TRUE); +#else // If the event is from warping the pointer back to middle // of the screen then ignore it. - /*if (ignorenext || ((evt.x == wwidth/2) && (evt.y == wheight/2))) + if (((evt.x == wwidth/2) && (evt.y == wheight/2))) { - ignorenext = SDL_FALSE; return; } else - {*/ - event.data2 = +evt.xrel; - event.data3 = -evt.yrel; - //} + { + event.data2 = +evt.xrel; + event.data3 = -evt.yrel; + } event.type = ev_mouse; D_PostEvent(&event); // 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 )) || + 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) ) )*/ + (evt.y > (wheight/2)+(wheight/4) ) ) { - //if (SDL_GRAB_ON == SDL_WM_GrabInput(SDL_GRAB_QUERY) || !mousegrabok) - SDL_SetWindowGrab(window, mousegrabok); - //HalfWarpMouse(wwidth, wheight); - SDL_SetRelativeMouseMode(SDL_TRUE); + HalfWarpMouse(wwidth, wheight); } +#endif +#endif + } static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type) From 025523f3e32eb18811065584d040f310c6858280 Mon Sep 17 00:00:00 2001 From: ilag11111 Date: Tue, 8 Apr 2014 19:19:23 -0700 Subject: [PATCH 2/3] Fix the previous commit to work on Linux32. Add more comments. --- src/sdl2/i_video.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/sdl2/i_video.c b/src/sdl2/i_video.c index 5a835ce0f..29d87e897 100644 --- a/src/sdl2/i_video.c +++ b/src/sdl2/i_video.c @@ -831,9 +831,17 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) SDLdoUngrabMouse(); return; } + + // If LINUX64 is defined, LINUX isn't defined. This code or another + // fix needs to be put in a more proper spot. +#ifdef LINUX64 +#ifndef LINUX +#define LINUX 1 +#endif +#endif #ifndef LINUX -#ifndef LINUX64 + // On most systems, grab the mouse and use relative input. event.data2 = +evt.xrel; event.data3 = -evt.yrel; event.type = ev_mouse; @@ -841,6 +849,10 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) SDL_SetWindowGrab(window, mousegrabok); SDL_SetRelativeMouseMode(SDL_TRUE); #else + // On Linux, SDL_SetWindowGrab is bugged and will also grab keyboard + // input, which breaks alt-tabbing. Instead, we're warping the + // mouse as a workaround. + // If the event is from warping the pointer back to middle // of the screen then ignore it. if (((evt.x == wwidth/2) && (evt.y == wheight/2))) @@ -864,7 +876,6 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) HalfWarpMouse(wwidth, wheight); } #endif -#endif } From c206d55568ca23a586de31c96087bf729f5cd6bf Mon Sep 17 00:00:00 2001 From: ilag11111 Date: Wed, 9 Apr 2014 14:40:54 -0700 Subject: [PATCH 3/3] Adds command line parameter -mousewarp to control the use of warping in place of grabbing. Works around bugs in certain versions of X. --- src/sdl2/i_video.c | 53 +++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/src/sdl2/i_video.c b/src/sdl2/i_video.c index 29d87e897..1f3c374d1 100644 --- a/src/sdl2/i_video.c +++ b/src/sdl2/i_video.c @@ -132,6 +132,7 @@ 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; @@ -832,30 +833,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) return; } - // If LINUX64 is defined, LINUX isn't defined. This code or another - // fix needs to be put in a more proper spot. -#ifdef LINUX64 -#ifndef LINUX -#define LINUX 1 -#endif -#endif - -#ifndef LINUX - // On most systems, grab the mouse and use relative input. - event.data2 = +evt.xrel; - event.data3 = -evt.yrel; - event.type = ev_mouse; - D_PostEvent(&event); - SDL_SetWindowGrab(window, mousegrabok); - SDL_SetRelativeMouseMode(SDL_TRUE); -#else - // On Linux, SDL_SetWindowGrab is bugged and will also grab keyboard - // input, which breaks alt-tabbing. Instead, we're warping the - // mouse as a workaround. - - // If the event is from warping the pointer back to middle - // of the screen then ignore it. - if (((evt.x == wwidth/2) && (evt.y == wheight/2))) + if (mousewarp && (evt.x == wwidth/2) && (evt.y == wheight/2)) { return; } @@ -864,18 +842,24 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) event.data2 = +evt.xrel; event.data3 = -evt.yrel; } + event.type = ev_mouse; D_PostEvent(&event); - // 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); + + 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); } -#endif } @@ -2110,6 +2094,9 @@ void I_StartupGraphics(void) } if (M_CheckParm("-nomousegrab")) mousegrabok = SDL_FALSE; + else if (M_CheckParm("-mousewarp")){ + mousewarp = SDL_TRUE; + } #if 0 // defined (_DEBUG) else {