foxygit / doom Log in
commit 23f18efcc56665b89f9ea4b346667336ee79c036
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Jan 6 03:26:00 2007 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Jan 6 03:26:00 2007 +0000

    Hide the mouse cursor using SDL_SetCursor to a blank cursor, not
    SDL_ShowCursor. This fixes mouse lag on Windows. Thanks to entryway.

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 823
---
 src/i_video.c | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/src/i_video.c b/src/i_video.c
index 92dc9b28..88370024 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -130,6 +130,10 @@ static int disk_image_w, disk_image_h;
 static byte *saved_background;
 static boolean window_focused;

+// Empty mouse cursor
+
+static SDL_Cursor *cursors[2];
+
 // Mouse acceleration
 //
 // This emulates some of the behavior of DOS mouse drivers by increasing
@@ -540,15 +544,20 @@ static void UpdateGrab(void)

     grab = MouseShouldBeGrabbed();

-    if (grab && !currently_grabbed)
+    if (screensaver_mode)
+    {
+        // Hide the cursor in screensaver mode
+
+        SDL_SetCursor(cursors[0]);
+    }
+    else if (grab && !currently_grabbed)
     {
-        SDL_ShowCursor(0);
+        SDL_SetCursor(cursors[0]);
         SDL_WM_GrabInput(SDL_GRAB_ON);
     }
-
-    if (!grab && currently_grabbed)
+    else if (!grab && currently_grabbed)
     {
-        SDL_ShowCursor(1);
+        SDL_SetCursor(cursors[1]);
         SDL_WM_GrabInput(SDL_GRAB_OFF);
     }

@@ -1076,19 +1085,19 @@ static void FindScreensaverMultiply(void)
     }
 }

-// Blank cursor so we don't see the mouse.  It is not okay to
-// do SDL_ShowCursor(0) because this will hide the mouse in
-// the configuration dialog.  Only show no mouse when over this
-// window.
-
-static void SetBlankCursor(void)
+static void CreateCursors(void)
 {
-    Uint8 zero = zero;
-    SDL_Cursor *cursor;
+    static Uint8 empty_cursor_data = 0;

-    cursor = SDL_CreateCursor(&zero, &zero, 1, 1, 0, 0);
+    // Save the default cursor so it can be recalled later

-    SDL_SetCursor(cursor);
+    cursors[1] = SDL_GetCursor();
+
+    // Create an empty cursor
+
+    cursors[0] = SDL_CreateCursor(&empty_cursor_data,
+                                  &empty_cursor_data,
+                                  1, 1, 0, 0);
 }

 void I_InitGraphics(void)
@@ -1209,7 +1218,6 @@ void I_InitGraphics(void)
     if (screensaver_mode)
     {
         FindScreensaverMultiply();
-        SetBlankCursor();
     }

     // Start with a clear black screen
@@ -1238,6 +1246,8 @@ void I_InitGraphics(void)
     I_SetWindowCaption();
     I_SetWindowIcon();

+    CreateCursors();
+
     UpdateFocus();
     UpdateGrab();