renamed VID_GrabMouse to VID_SetMouse as it now takes 3 parameters
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 10 May 2008 12:47:28 +0000 (12:47 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 10 May 2008 12:47:28 +0000 (12:47 +0000)
(fullscreengrab, relative, hidecursor), this required reworking all the
implementations and the calls, but gives the correct behavior in all
cases

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8296 d7cf8633-e32d-0410-b094-e92efae38249

cl_screen.c
vid.h
vid_agl.c
vid_glx.c
vid_null.c
vid_sdl.c
vid_wgl.c

index fb52f04..b1f5df2 100644 (file)
@@ -2039,7 +2039,7 @@ void SCR_UpdateLoadingScreen (qboolean clear)
                return;
        // release mouse grab while loading
        if (!vid.fullscreen)
-               VID_GrabMouse(false);
+               VID_SetMouse(false, false, false);
        CHECKGLERROR
        qglViewport(0, 0, vid.width, vid.height);CHECKGLERROR
        //qglDisable(GL_SCISSOR_TEST);CHECKGLERROR
@@ -2113,7 +2113,6 @@ void CL_UpdateScreen(void)
 {
        double rendertime1;
        float conwidth, conheight;
-       qboolean grabmouse;
 
        if (!scr_initialized || !con_initialized)
                return;                         // not initialized yet
@@ -2273,23 +2272,16 @@ void CL_UpdateScreen(void)
        else
                cl_updatescreen_quality = 1;
 
-       if (key_consoleactive)
-               grabmouse = false;
+       if (!vid_activewindow)
+               VID_SetMouse(false, false, false);
+       else if (key_consoleactive)
+               VID_SetMouse(vid.fullscreen, false, false);
        else if (key_dest == key_menu_grabbed)
-               grabmouse = true;
+               VID_SetMouse(true, !in_client_mouse, true);
        else if (key_dest == key_menu)
-               grabmouse = !in_client_mouse;
-       else if (key_dest == key_game)
-               grabmouse = vid_mouse.integer && !cls.demoplayback && !cl.csqc_wantsmousemove;
+               VID_SetMouse(vid.fullscreen, !in_client_mouse, true);
        else
-               grabmouse = false;
-       vid.mouseaim = grabmouse;
-       if (vid.fullscreen)
-               grabmouse = true;
-       if (!vid_activewindow)
-               grabmouse = false;
-
-       VID_GrabMouse(grabmouse);
+               VID_SetMouse(vid.fullscreen || (vid_mouse.integer && !cls.demoplayback && !cl.csqc_wantsmousemove), vid_mouse.integer && !cls.demoplayback && !cl.csqc_wantsmousemove, true);
 
        VID_Finish();
 }
diff --git a/vid.h b/vid.h
index 9f9e86d..215ffac 100644 (file)
--- a/vid.h
+++ b/vid.h
@@ -37,9 +37,6 @@ typedef struct viddef_s
        qboolean userefreshrate;
        int stereobuffer;
        int samples;
-
-       // these are used for state tracking
-       qboolean mouseaim;
 } viddef_t;
 
 // global video state
@@ -149,7 +146,7 @@ void VID_UpdateGamma(qboolean force, int rampsize);
 // (called from various shutdown/deactivation functions)
 void VID_RestoreSystemGamma(void);
 
-void VID_GrabMouse (qboolean grab);
+void VID_SetMouse (qboolean fullscreengrab, qboolean relative, qboolean hidecursor);
 void VID_Finish (void);
 
 void VID_Restart_f(void);
index 1caf266..2648ce2 100644 (file)
--- a/vid_agl.c
+++ b/vid_agl.c
@@ -60,6 +60,7 @@ CGLContextObj (*qCGLGetCurrentContext) (void);
 static qboolean multithreadedgl;
 static qboolean mouse_avail = true;
 static qboolean vid_usingmouse = false;
+static qboolean vid_usinghidecursor = false;
 static qboolean vid_usingnoaccel = false;
 
 static qboolean vid_isfullscreen = false;
@@ -105,19 +106,21 @@ void VID_GetWindowSize (int *x, int *y, int *width, int *height)
        *height = scr_height;
 }
 
-void VID_GrabMouse(qboolean grab)
+void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
 {
-       if (grab)
+       if (!mouse_avail || !window)
+               fullscreengrab = relative = hidecursor = false;
+
+       if (relative)
        {
                if(vid_usingmouse && (vid_usingnoaccel != !!apple_mouse_noaccel.integer))
-                       VID_GrabMouse(false); // ungrab first!
-               if (!vid_usingmouse && mouse_avail && window)
+                       VID_SetMouse(false, false, false); // ungrab first!
+               if (!vid_usingmouse)
                {
                        Rect winBounds;
                        CGPoint winCenter;
 
                        SelectWindow(window);
-                       CGDisplayHideCursor(CGMainDisplayID());
 
                        // Put the mouse cursor at the center of the window
                        GetWindowBounds (window, kWindowContentRgn, &winBounds);
@@ -181,11 +184,19 @@ void VID_GrabMouse(qboolean grab)
                        }
 
                        CGAssociateMouseAndMouseCursorPosition(true);
-                       CGDisplayShowCursor(CGMainDisplayID());
 
                        vid_usingmouse = false;
                }
        }
+
+       if (vid_usinghidecursor != hidecursor)
+       {
+               vid_usinghidecursor = hidecursor;
+               if (hidecursor)
+                       CGDisplayHideCursor(CGMainDisplayID());
+               else
+                       CGDisplayShowCursor(CGMainDisplayID());
+       }
 }
 
 #define GAMMA_TABLE_SIZE 256
@@ -397,7 +408,7 @@ void VID_Shutdown(void)
        if (context == NULL && window == NULL)
                return;
 
-       VID_GrabMouse(false);
+       VID_SetMouse(false, false, false);
        VID_RestoreSystemGamma();
 
        if (context != NULL)
@@ -697,6 +708,7 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
        multithreadedgl = false;
        vid_isfullscreen = fullscreen;
        vid_usingmouse = false;
+       vid_usinghidecursor = false;
        vid_hidden = false;
        vid_activewindow = true;
        sound_active = true;
@@ -968,7 +980,7 @@ void Sys_SendKeyEvents(void)
                                                GetEventParameter(theEvent, kEventParamMouseDelta, typeHIPoint, NULL, sizeof(deltaPos), NULL, &deltaPos);
                                                GetEventParameter(theEvent, kEventParamWindowMouseLocation, typeHIPoint, NULL, sizeof(windowPos), NULL, &windowPos);
 
-                                               if (vid.mouseaim)
+                                               if (vid_usingmouse)
                                                {
                                                        in_mouse_x += deltaPos.x;
                                                        in_mouse_y += deltaPos.y;
index 00e1cb5..8467bd7 100644 (file)
--- a/vid_glx.c
+++ b/vid_glx.c
@@ -88,7 +88,9 @@ Atom wm_delete_window_atom;
 
 
 static qboolean mouse_avail = true;
+static qboolean vid_usingmousegrab = false;
 static qboolean vid_usingmouse = false;
+static qboolean vid_usinghidecursor = false;
 static qboolean vid_usingvsync = false;
 static qboolean vid_usevsync = false;
 static qboolean vid_x11_hardwaregammasupported = false;
@@ -247,23 +249,44 @@ static Cursor CreateNullCursor(Display *display, Window root)
        return cursor;
 }
 
-void VID_GrabMouse(qboolean grab)
+void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
 {
        qboolean usedgamouse;
-       if (!vidx11_display)
+
+       if (!vidx11_display || !win)
                return;
-       usedgamouse = grab && vid.mouseaim && vid_dgamouse.integer;
+
+       if (!mouse_avail)
+               fullscreengrab = relative = hidecursor = false;
+
+       usedgamouse = relative && vid_dgamouse.integer;
 #if !defined(__APPLE__) && !defined(SUNOS)
        if (!vid_x11_dgasupported)
                usedgamouse = false;
+       if (fullscreengrab && vid_usingmouse && (vid_usingdgamouse != usedgamouse))
+               VID_SetMouse(false, false, false); // ungrab first!
 #endif
-       if (grab)
+
+       if (vid_usingmousegrab != fullscreengrab)
        {
-#if !defined(__APPLE__) && !defined(SUNOS)
-               if(vid_usingmouse && (vid_usingdgamouse != usedgamouse))
-                       VID_GrabMouse(false); // ungrab first!
-#endif
-               if (!vid_usingmouse && mouse_avail && win)
+               vid_usingmousegrab = fullscreengrab;
+               cl_ignoremousemoves = 2;
+               if (fullscreengrab)
+               {
+                       XGrabPointer(vidx11_display, win,  True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
+                       if (vid_grabkeyboard.integer || vid_isfullscreen)
+                               XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
+               }
+               else
+               {
+                       XUngrabPointer(vidx11_display, CurrentTime);
+                       XUngrabKeyboard(vidx11_display, CurrentTime);
+               }
+       }
+
+       if (relative)
+       {
+               if (!vid_usingmouse)
                {
                        XWindowAttributes attribs_1;
                        XSetWindowAttributes attribs_2;
@@ -272,11 +295,6 @@ void VID_GrabMouse(qboolean grab)
                        attribs_2.event_mask = attribs_1.your_event_mask | KEY_MASK | MOUSE_MASK;
                        XChangeWindowAttributes(vidx11_display, win, CWEventMask, &attribs_2);
 
-               // inviso cursor
-                       XDefineCursor(vidx11_display, win, CreateNullCursor(vidx11_display, win));
-
-                       XGrabPointer(vidx11_display, win,  True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
-
 #if !defined(__APPLE__) && !defined(SUNOS)
                        vid_usingdgamouse = usedgamouse;
                        if (usedgamouse)
@@ -288,9 +306,6 @@ void VID_GrabMouse(qboolean grab)
 #endif
                                XWarpPointer(vidx11_display, None, win, 0, 0, 0, 0, vid.width / 2, vid.height / 2);
 
-                       if (vid_grabkeyboard.integer || vid_isfullscreen)
-                               XGrabKeyboard(vidx11_display, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
-
                        cl_ignoremousemoves = 2;
                        vid_usingmouse = true;
                }
@@ -304,18 +319,19 @@ void VID_GrabMouse(qboolean grab)
                                XF86DGADirectVideo(vidx11_display, DefaultScreen(vidx11_display), 0);
                        vid_usingdgamouse = false;
 #endif
-
-                       XUngrabPointer(vidx11_display, CurrentTime);
-                       XUngrabKeyboard(vidx11_display, CurrentTime);
-
-                       // inviso cursor
-                       if (win)
-                               XUndefineCursor(vidx11_display, win);
-
                        cl_ignoremousemoves = 2;
                        vid_usingmouse = false;
                }
        }
+
+       if (vid_usinghidecursor != hidecursor)
+       {
+               vid_usinghidecursor = hidecursor;
+               if (hidecursor)
+                       XDefineCursor(vidx11_display, win, CreateNullCursor(vidx11_display, win));
+               else
+                       XUndefineCursor(vidx11_display, win);
+       }
 }
 
 static keynum_t buttonremap[18] =
@@ -370,7 +386,7 @@ static void HandleEvents(void)
 
                case MotionNotify:
                        // mouse moved
-                       if (vid.mouseaim)
+                       if (vid_usingmouse)
                        {
 #if !defined(__APPLE__) && !defined(SUNOS)
                                if (vid_usingdgamouse)
@@ -523,7 +539,7 @@ void VID_Shutdown(void)
        if (!ctx || !vidx11_display)
                return;
 
-       VID_GrabMouse(false);
+       VID_SetMouse(false, false, false);
        VID_RestoreSystemGamma();
 
        // FIXME: glXDestroyContext here?
@@ -866,7 +882,9 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
 // COMMANDLINEOPTION: MacOSX GLX: -novideosync disables GLX_SGI_swap_control
        gl_videosyncavailable = GL_CheckExtension("GLX_SGI_swap_control", swapcontrolfuncs, "-novideosync", false);
 
+       vid_usingmousegrab = false;
        vid_usingmouse = false;
+       vid_usinghidecursor = false;
        vid_usingvsync = false;
        vid_hidden = false;
        vid_activewindow = true;
index 9d01e8a..6a6b892 100644 (file)
@@ -51,7 +51,7 @@ void InitSig(void)
 #endif
 }
 
-void VID_GrabMouse (qboolean grab)
+void VID_SetMouse (qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
 {
 }
 
index 31e2f7a..d6123be 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -49,7 +49,8 @@ cvar_t joy_sensitivitypitch = {0, "joy_sensitivitypitch", "1", "movement multipl
 cvar_t joy_sensitivityyaw = {0, "joy_sensitivityyaw", "-1", "movement multiplier"};
 cvar_t joy_sensitivityroll = {0, "joy_sensitivityroll", "1", "movement multiplier"};
 
-static qboolean vid_usingmouse;
+static qboolean vid_usingmouse = false;
+static qboolean vid_usinghidecursor = false;
 static qboolean vid_isfullscreen;
 static int vid_numjoysticks = 0;
 #define MAX_JOYSTICKS 8
@@ -232,29 +233,18 @@ static int MapKey( unsigned int sdlkey )
     return tbl_sdltoquake[ sdlkey ];
 }
 
-void VID_GrabMouse(qboolean grab)
+void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
 {
-       //SDL_WM_GrabInput( SDL_GRAB_OFF );
-       //Con_Printf("< Turning off input-grabbing. --blub\n");
-       if (grab)
+       if (vid_usingmouse != relative)
        {
-               if (!vid_usingmouse)
-               {
-                       vid_usingmouse = true;
-                       cl_ignoremousemoves = 2;
-                       SDL_WM_GrabInput( SDL_GRAB_ON );
-                       SDL_ShowCursor( SDL_DISABLE );
-               }
+               vid_usingmouse = relative;
+               cl_ignoremousemoves = 2;
+               SDL_WM_GrabInput( relative ? SDL_GRAB_ON : SDL_GRAB_OFF );
        }
-       else
+       if (vid_usinghidecursor != hidecursor)
        {
-               if (vid_usingmouse)
-               {
-                       vid_usingmouse = false;
-                       cl_ignoremousemoves = 2;
-                       SDL_WM_GrabInput( SDL_GRAB_OFF );
-                       SDL_ShowCursor( SDL_ENABLE );
-               }
+               vid_usinghidecursor = hidecursor;
+               SDL_ShowCursor( hidecursor ? SDL_DISABLE : SDL_ENABLE);
        }
 }
 
@@ -276,7 +266,7 @@ void IN_Move( void )
        static int old_x = 0, old_y = 0;
        static int stuck = 0;
        int x, y;
-       if (vid.mouseaim)
+       if (vid_usingmouse)
        {
                if(vid_stick_mouse.integer)
                {
@@ -763,6 +753,7 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
        vid_hidden = false;
        vid_activewindow = false;
        vid_usingmouse = false;
+       vid_usinghidecursor = false;
 
        SDL_WM_GrabInput(SDL_GRAB_OFF);
        return true;
@@ -770,7 +761,7 @@ int VID_InitMode(int fullscreen, int width, int height, int bpp, int refreshrate
 
 void VID_Shutdown (void)
 {
-       VID_GrabMouse(false);
+       VID_SetMouse(false, false, false);
        VID_RestoreSystemGamma();
 
        SDL_QuitSubSystem(SDL_INIT_VIDEO);
index 7b39e22..b5acec4 100644 (file)
--- a/vid_wgl.c
+++ b/vid_wgl.c
@@ -95,6 +95,7 @@ static DEVMODE gdevmode, initialdevmode;
 static qboolean vid_initialized = false;
 static qboolean vid_wassuspended = false;
 static qboolean vid_usingmouse = false;
+static qboolean vid_usinghidecursor = false;
 static qboolean vid_usingvsync = false;
 static qboolean vid_usevsync = false;
 static HICON hIcon;
@@ -427,7 +428,7 @@ void AppActivate(BOOL fActive, BOOL minimize)
 
        if (!fActive)
        {
-               VID_GrabMouse(false);
+               VID_SetMouse(false, false, false);
                if (vid_isfullscreen)
                {
                        ChangeDisplaySettings (NULL, 0);
@@ -501,7 +502,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM lParam)
                case WM_MOVE:
                        window_x = (int) LOWORD(lParam);
                        window_y = (int) HIWORD(lParam);
-                       VID_GrabMouse(false);
+                       VID_SetMouse(false, false, false);
                        break;
 
                case WM_KEYDOWN:
@@ -1220,6 +1221,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat
        //vid_menudrawfn = VID_MenuDraw;
        //vid_menukeyfn = VID_MenuKey;
        vid_usingmouse = false;
+       vid_usinghidecursor = false;
        vid_usingvsync = false;
        vid_hidden = false;
        vid_initialized = true;
@@ -1243,7 +1245,7 @@ void VID_Shutdown (void)
        if(vid_initialized == false)
                return;
 
-       VID_GrabMouse(false);
+       VID_SetMouse(false, false, false);
        VID_RestoreSystemGamma();
 
        vid_initialized = false;
@@ -1265,7 +1267,7 @@ void VID_Shutdown (void)
        vid_isfullscreen = false;
 }
 
-void VID_GrabMouse(qboolean grab)
+void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
 {
        static qboolean restore_spi;
        static int originalmouseparms[3];
@@ -1273,7 +1275,7 @@ void VID_GrabMouse(qboolean grab)
        if (!mouseinitialized)
                return;
 
-       if (grab)
+       if (relative)
        {
                if (!vid_usingmouse)
                {
@@ -1311,7 +1313,6 @@ void VID_GrabMouse(qboolean grab)
                                SetCapture (mainwindow);
                                ClipCursor (&window_rect);
                        }
-                       ShowCursor (false);
                }
        }
        else
@@ -1336,9 +1337,14 @@ void VID_GrabMouse(qboolean grab)
                                ClipCursor (NULL);
                                ReleaseCapture ();
                        }
-                       ShowCursor (true);
                }
        }
+
+       if (vid_usinghidecursor != hidecursor)
+       {
+               vid_usinghidecursor = hidecursor;
+               ShowCursor (!hidecursor);
+       }
 }
 
 
@@ -1475,7 +1481,7 @@ static void IN_MouseMove (void)
        in_windowmouse_x = current_pos.x - window_x;
        in_windowmouse_y = current_pos.y - window_y;
 
-       if (!vid.mouseaim)
+       if (!vid_usingmouse)
                return;
 
 #ifdef SUPPORTDIRECTX