From: John F. Fay Date: Sun, 4 Sep 2011 03:49:11 +0000 (+0000) Subject: Fixing freeglut's desire to initialize the spaceball every time a window is checked... X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=7b784a0870b622d34bee6e31e9932fcfdd28a1c2;p=freeglut 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: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@928 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/src/freeglut_spaceball.c b/src/freeglut_spaceball.c index 7c9d073..89655f4 100644 --- a/src/freeglut_spaceball.c +++ b/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; } }