Fixing freeglut's desire to initialize the spaceball every time a window is checked...
authorJohn F. Fay <johnffay@nettally.com>
Sun, 4 Sep 2011 03:49:11 +0000 (03:49 +0000)
committerJohn F. Fay <johnffay@nettally.com>
Sun, 4 Sep 2011 03:49:11 +0000 (03:49 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@928 7f0cb862-5218-0410-a997-914c9d46530a

src/freeglut_spaceball.c

index 7c9d073..89655f4 100644 (file)
@@ -52,12 +52,17 @@ static int spnav_remove_events(int type);
 static SFG_Window *spnav_win;\r
 #endif\r
 \r
-static int sball_initialized;\r
+/* Flag telling whether we have a spaceball:\r
+ *   0 - haven't tried initializing\r
+ *   1 - have successfully initialized\r
+ *  -1 - have tried to initialize but not succeeded\r
+ */\r
+static int sball_initialized = 0;\r
 \r
 \r
 void fgInitialiseSpaceball(void)\r
 {\r
-    if(sball_initialized) {\r
+    if(sball_initialized != 0) {\r
         return;\r
     }\r
 \r
@@ -66,10 +71,15 @@ void fgInitialiseSpaceball(void)
         Window w;\r
 \r
         if(!fgStructure.CurrentWindow)\r
+               {\r
+                       sball_initialized = -1;\r
             return;\r
+               }\r
 \r
         w = fgStructure.CurrentWindow->Window.Handle;\r
-        if(spnav_x11_open(fgDisplay.Display, w) == -1) {\r
+        if(spnav_x11_open(fgDisplay.Display, w) == -1)\r
+               {\r
+                       sball_initialized = -1;\r
             return;\r
         }\r
     }\r
@@ -87,9 +97,9 @@ void fgSpaceballClose(void)
 \r
 int fgHasSpaceball(void)\r
 {\r
-    if(!sball_initialized) {\r
+    if(sball_initialized == 0) {\r
         fgInitialiseSpaceball();\r
-        if(!sball_initialized) {\r
+        if(sball_initialized != 1) {\r
             fgWarning("fgInitialiseSpaceball failed\n");\r
             return 0;\r
         }\r
@@ -107,9 +117,9 @@ int fgHasSpaceball(void)
 \r
 int fgSpaceballNumButtons(void)\r
 {\r
-    if(!sball_initialized) {\r
+    if(sball_initialized == 0) {\r
         fgInitialiseSpaceball();\r
-        if(!sball_initialized) {\r
+        if(sball_initialized != 1) {\r
             fgWarning("fgInitialiseSpaceball failed\n");\r
             return 0;\r
         }\r
@@ -124,9 +134,9 @@ int fgSpaceballNumButtons(void)
 \r
 void fgSpaceballSetWindow(SFG_Window *window)\r
 {\r
-    if(!sball_initialized) {\r
+    if(sball_initialized == 0) {\r
         fgInitialiseSpaceball();\r
-        if(!sball_initialized) {\r
+        if(sball_initialized != 1) {\r
             return;\r
         }\r
     }\r
@@ -150,7 +160,7 @@ int fgIsSpaceballXEvent(const XEvent *xev)
         fgSpaceballSetWindow(fgStructure.CurrentWindow);\r
     }\r
 \r
-    if(!sball_initialized) {\r
+    if(sball_initialized != 1) {\r
         return 0;\r
     }\r
 \r
@@ -161,9 +171,9 @@ void fgSpaceballHandleXEvent(const XEvent *xev)
 {\r
     spnav_event sev;\r
 \r
-    if(!sball_initialized) {\r
+    if(sball_initialized == 0) {\r
         fgInitialiseSpaceball();\r
-        if(!sball_initialized) {\r
+        if(sball_initialized != 1) {\r
             return;\r
         }\r
     }\r