shithub: choc

Download patch

ref: 41c2cd24e6079e0883c1fde4230864343c7a05e8
parent: 33120be8fa37ddb48ab09c7de955bd54a070e4c1
author: Simon Howard <fraggle@gmail.com>
date: Thu Feb 2 15:34:09 EST 2012

Only use the SDL mouse lag workaround on Windows - not all systems allow
the cursor to be changed. This fixes Chocolate Doom on AmigaOS (thanks
Timo Sievänen).

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2483

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -276,6 +276,37 @@
     screenvisible = (state & SDL_APPACTIVE) != 0;
 }
 
+// Show or hide the mouse cursor. We have to use different techniques
+// depending on the OS.
+
+static void ShowCursor(boolean show)
+{
+    // On Windows, using SDL_ShowCursor() adds lag to the mouse input,
+    // so work around this by setting an invisible cursor instead. On
+    // other systems, it isn't possible to change the cursor, so this
+    // hack has to be Windows-only. (Thanks to entryway for this)
+
+#ifdef _WIN32
+    if (show)
+    {
+        SDL_SetCursor(cursors[1]);
+    }
+    else
+    {
+        SDL_SetCursor(cursors[0]);
+    }
+#else
+    SDL_ShowCursor(show);
+#endif
+
+    // When the cursor is hidden, grab the input.
+
+    if (!screensaver_mode)
+    {
+        SDL_WM_GrabInput(!show);
+    }
+}
+
 static void LoadDiskImage(void)
 {
     patch_t *disk;
@@ -423,12 +454,10 @@
 {
     if (initialized)
     {
-        SDL_SetCursor(cursors[1]);
-        SDL_ShowCursor(1);
-        SDL_WM_GrabInput(SDL_GRAB_OFF);
+        ShowCursor(true);
 
         SDL_QuitSubSystem(SDL_INIT_VIDEO);
-    
+
         initialized = false;
     }
 }
@@ -725,17 +754,15 @@
     {
         // Hide the cursor in screensaver mode
 
-        SDL_SetCursor(cursors[0]);
+        ShowCursor(false);
     }
     else if (grab && !currently_grabbed)
     {
-        SDL_SetCursor(cursors[0]);
-        SDL_WM_GrabInput(SDL_GRAB_ON);
+        ShowCursor(false);
     }
     else if (!grab && currently_grabbed)
     {
-        SDL_SetCursor(cursors[1]);
-        SDL_WM_GrabInput(SDL_GRAB_OFF);
+        ShowCursor(true);
     }
 
     currently_grabbed = grab;