shithub: choc

Download patch

ref: 23f18efcc56665b89f9ea4b346667336ee79c036
parent: 1d3e9a564853aaf44f8ec58d9ea023932416f6b3
author: Simon Howard <fraggle@gmail.com>
date: Fri Jan 5 22:26:00 EST 2007

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

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -130,6 +130,10 @@
 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 @@
 
     grab = MouseShouldBeGrabbed();
 
-    if (grab && !currently_grabbed)
+    if (screensaver_mode)
     {
-        SDL_ShowCursor(0);
+        // Hide the cursor in screensaver mode
+
+        SDL_SetCursor(cursors[0]);
+    }
+    else if (grab && !currently_grabbed)
+    {
+        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 @@
     }
 }
 
-// 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 @@
     if (screensaver_mode)
     {
         FindScreensaverMultiply();
-        SetBlankCursor();
     }
 
     // Start with a clear black screen
@@ -1237,6 +1245,8 @@
 
     I_SetWindowCaption();
     I_SetWindowIcon();
+
+    CreateCursors();
 
     UpdateFocus();
     UpdateGrab();