From 42235dfaa147a48198d99da9573f1108824b3d43 Mon Sep 17 00:00:00 2001 From: fayjf Date: Sun, 4 Sep 2011 03:49:11 +0000 Subject: [PATCH] Fixing freeglut's desire to initialize the spaceball every time a window is checked. Now it tries once the first time a spaceball function is called and after that if it fails it doesn't try any more. This is per an e-mail from Diederick Niehorster vintage 6/8/11 at 3:17 AM, referring to feature request 3190319. git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@928 7f0cb862-5218-0410-a997-914c9d46530a --- freeglut/freeglut/src/freeglut_spaceball.c | 34 ++++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/freeglut/freeglut/src/freeglut_spaceball.c b/freeglut/freeglut/src/freeglut_spaceball.c index 7c9d073..89655f4 100644 --- a/freeglut/freeglut/src/freeglut_spaceball.c +++ b/freeglut/freeglut/src/freeglut_spaceball.c @@ -52,12 +52,17 @@ static int spnav_remove_events(int type); static SFG_Window *spnav_win; #endif -static int sball_initialized; +/* Flag telling whether we have a spaceball: + * 0 - haven't tried initializing + * 1 - have successfully initialized + * -1 - have tried to initialize but not succeeded + */ +static int sball_initialized = 0; void fgInitialiseSpaceball(void) { - if(sball_initialized) { + if(sball_initialized != 0) { return; } @@ -66,10 +71,15 @@ void fgInitialiseSpaceball(void) Window w; if(!fgStructure.CurrentWindow) + { + sball_initialized = -1; return; + } w = fgStructure.CurrentWindow->Window.Handle; - if(spnav_x11_open(fgDisplay.Display, w) == -1) { + if(spnav_x11_open(fgDisplay.Display, w) == -1) + { + sball_initialized = -1; return; } } @@ -87,9 +97,9 @@ void fgSpaceballClose(void) int fgHasSpaceball(void) { - if(!sball_initialized) { + if(sball_initialized == 0) { fgInitialiseSpaceball(); - if(!sball_initialized) { + if(sball_initialized != 1) { fgWarning("fgInitialiseSpaceball failed\n"); return 0; } @@ -107,9 +117,9 @@ int fgHasSpaceball(void) int fgSpaceballNumButtons(void) { - if(!sball_initialized) { + if(sball_initialized == 0) { fgInitialiseSpaceball(); - if(!sball_initialized) { + if(sball_initialized != 1) { fgWarning("fgInitialiseSpaceball failed\n"); return 0; } @@ -124,9 +134,9 @@ int fgSpaceballNumButtons(void) void fgSpaceballSetWindow(SFG_Window *window) { - if(!sball_initialized) { + if(sball_initialized == 0) { fgInitialiseSpaceball(); - if(!sball_initialized) { + if(sball_initialized != 1) { return; } } @@ -150,7 +160,7 @@ int fgIsSpaceballXEvent(const XEvent *xev) fgSpaceballSetWindow(fgStructure.CurrentWindow); } - if(!sball_initialized) { + if(sball_initialized != 1) { return 0; } @@ -161,9 +171,9 @@ void fgSpaceballHandleXEvent(const XEvent *xev) { spnav_event sev; - if(!sball_initialized) { + if(sball_initialized == 0) { fgInitialiseSpaceball(); - if(!sball_initialized) { + if(sball_initialized != 1) { return; } }