Formatting pass (no code changes).

This commit is contained in:
Camilla Berglund 2010-09-08 15:51:25 +02:00
parent 8bc1a5da16
commit a04e041a6b
7 changed files with 769 additions and 790 deletions

View File

@ -39,11 +39,11 @@
// Enable system keys // Enable system keys
//======================================================================== //========================================================================
void _glfwPlatformEnableSystemKeys( void ) void _glfwPlatformEnableSystemKeys(void)
{ {
if( _glfwWin.keyboardGrabbed ) if (_glfwWin.keyboardGrabbed)
{ {
XUngrabKeyboard( _glfwLibrary.display, CurrentTime ); XUngrabKeyboard(_glfwLibrary.display, CurrentTime);
_glfwWin.keyboardGrabbed = GL_FALSE; _glfwWin.keyboardGrabbed = GL_FALSE;
} }
} }
@ -52,11 +52,11 @@ void _glfwPlatformEnableSystemKeys( void )
// Disable system keys // Disable system keys
//======================================================================== //========================================================================
void _glfwPlatformDisableSystemKeys( void ) void _glfwPlatformDisableSystemKeys(void)
{ {
if( XGrabKeyboard( _glfwLibrary.display, _glfwWin.window, True, if (XGrabKeyboard(_glfwLibrary.display, _glfwWin.window,
GrabModeAsync, GrabModeAsync, CurrentTime ) == True, GrabModeAsync, GrabModeAsync, CurrentTime)
GrabSuccess ) == GrabSuccess)
{ {
_glfwWin.keyboardGrabbed = GL_TRUE; _glfwWin.keyboardGrabbed = GL_TRUE;
} }

View File

@ -41,21 +41,21 @@
// Convert BPP to RGB bits (based on "best guess") // Convert BPP to RGB bits (based on "best guess")
//======================================================================== //========================================================================
static void BPP2RGB( int bpp, int *r, int *g, int *b ) static void BPP2RGB(int bpp, int *r, int *g, int *b)
{ {
int delta; int delta;
// Special case: BPP = 32 (I don't think this is necessary for X11??) // Special case: BPP = 32 (I don't think this is necessary for X11??)
if( bpp == 32 ) if (bpp == 32)
bpp = 24; bpp = 24;
// Convert "bits per pixel" to red, green & blue sizes // Convert "bits per pixel" to red, green & blue sizes
*r = *g = *b = bpp / 3; *r = *g = *b = bpp / 3;
delta = bpp - (*r * 3); delta = bpp - (*r * 3);
if( delta >= 1 ) if (delta >= 1)
*g = *g + 1; *g = *g + 1;
if( delta == 2 ) if (delta == 2)
*r = *r + 1; *r = *r + 1;
} }
@ -64,9 +64,9 @@ static void BPP2RGB( int bpp, int *r, int *g, int *b )
// Finds the video mode closest in size to the specified desired size // Finds the video mode closest in size to the specified desired size
//======================================================================== //========================================================================
int _glfwGetClosestVideoMode( int screen, int *width, int *height, int *rate ) int _glfwGetClosestVideoMode(int screen, int *width, int *height, int *rate)
{ {
#if defined( _GLFW_HAS_XRANDR ) #if defined(_GLFW_HAS_XRANDR)
int i, match, bestmatch; int i, match, bestmatch;
int sizecount, bestsize; int sizecount, bestsize;
int ratecount, bestrate; int ratecount, bestrate;
@ -74,107 +74,107 @@ int _glfwGetClosestVideoMode( int screen, int *width, int *height, int *rate )
XRRScreenConfiguration *sc; XRRScreenConfiguration *sc;
XRRScreenSize *sizelist; XRRScreenSize *sizelist;
if( _glfwLibrary.XRandR.available ) if (_glfwLibrary.XRandR.available)
{ {
sc = XRRGetScreenInfo( _glfwLibrary.display, sc = XRRGetScreenInfo(_glfwLibrary.display,
RootWindow( _glfwLibrary.display, screen ) ); RootWindow(_glfwLibrary.display, screen));
sizelist = XRRConfigSizes( sc, &sizecount ); sizelist = XRRConfigSizes(sc, &sizecount);
// Find the best matching mode // Find the best matching mode
bestsize = -1; bestsize = -1;
bestmatch = INT_MAX; bestmatch = INT_MAX;
for( i = 0; i < sizecount; i++ ) for (i = 0; i < sizecount; i++)
{ {
match = (*width - sizelist[i].width) * match = (*width - sizelist[i].width) *
(*width - sizelist[i].width) + (*width - sizelist[i].width) +
(*height - sizelist[i].height) * (*height - sizelist[i].height) *
(*height - sizelist[i].height); (*height - sizelist[i].height);
if( match < bestmatch ) if (match < bestmatch)
{ {
bestmatch = match; bestmatch = match;
bestsize = i; bestsize = i;
} }
} }
if( bestsize != -1 ) if (bestsize != -1)
{ {
// Report width & height of best matching mode // Report width & height of best matching mode
*width = sizelist[bestsize].width; *width = sizelist[bestsize].width;
*height = sizelist[bestsize].height; *height = sizelist[bestsize].height;
if( *rate > 0 ) if (*rate > 0)
{ {
ratelist = XRRConfigRates( sc, bestsize, &ratecount ); ratelist = XRRConfigRates(sc, bestsize, &ratecount);
bestrate = -1; bestrate = -1;
bestmatch = INT_MAX; bestmatch = INT_MAX;
for( i = 0; i < ratecount; i++ ) for (i = 0; i < ratecount; i++)
{ {
match = abs( ratelist[i] - *rate ); match = abs(ratelist[i] - *rate);
if( match < bestmatch ) if (match < bestmatch)
{ {
bestmatch = match; bestmatch = match;
bestrate = ratelist[i]; bestrate = ratelist[i];
} }
} }
if( bestrate != -1 ) if (bestrate != -1)
*rate = bestrate; *rate = bestrate;
} }
} }
// Free modelist // Free modelist
XRRFreeScreenConfigInfo( sc ); XRRFreeScreenConfigInfo(sc);
if( bestsize != -1 ) if (bestsize != -1)
return bestsize; return bestsize;
} }
#elif defined( _GLFW_HAS_XF86VIDMODE ) #elif defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo **modelist; XF86VidModeModeInfo **modelist;
int modecount, i, bestmode, bestmatch, match; int modecount, i, bestmode, bestmatch, match;
// Use the XF86VidMode extension to control video resolution // Use the XF86VidMode extension to control video resolution
if( _glfwLibrary.XF86VidMode.available ) if (_glfwLibrary.XF86VidMode.available)
{ {
// Get a list of all available display modes // Get a list of all available display modes
XF86VidModeGetAllModeLines( _glfwLibrary.display, screen, XF86VidModeGetAllModeLines(_glfwLibrary.display, screen,
&modecount, &modelist ); &modecount, &modelist);
// Find the best matching mode // Find the best matching mode
bestmode = -1; bestmode = -1;
bestmatch = INT_MAX; bestmatch = INT_MAX;
for( i = 0; i < modecount; i++ ) for (i = 0; i < modecount; i++)
{ {
match = (*width - modelist[i]->hdisplay) * match = (*width - modelist[i]->hdisplay) *
(*width - modelist[i]->hdisplay) + (*width - modelist[i]->hdisplay) +
(*height - modelist[i]->vdisplay) * (*height - modelist[i]->vdisplay) *
(*height - modelist[i]->vdisplay); (*height - modelist[i]->vdisplay);
if( match < bestmatch ) if (match < bestmatch)
{ {
bestmatch = match; bestmatch = match;
bestmode = i; bestmode = i;
} }
} }
if( bestmode != -1 ) if (bestmode != -1)
{ {
// Report width & height of best matching mode // Report width & height of best matching mode
*width = modelist[ bestmode ]->hdisplay; *width = modelist[bestmode]->hdisplay;
*height = modelist[ bestmode ]->vdisplay; *height = modelist[bestmode]->vdisplay;
} }
// Free modelist // Free modelist
XFree( modelist ); XFree(modelist);
if( bestmode != -1 ) if (bestmode != -1)
return bestmode; return bestmode;
} }
#endif #endif
// Default: Simply use the screen resolution // Default: Simply use the screen resolution
*width = DisplayWidth( _glfwLibrary.display, screen ); *width = DisplayWidth(_glfwLibrary.display, screen);
*height = DisplayHeight( _glfwLibrary.display, screen ); *height = DisplayHeight(_glfwLibrary.display, screen);
return 0; return 0;
} }
@ -184,85 +184,85 @@ int _glfwGetClosestVideoMode( int screen, int *width, int *height, int *rate )
// Change the current video mode // Change the current video mode
//======================================================================== //========================================================================
void _glfwSetVideoModeMODE( int screen, int mode, int rate ) void _glfwSetVideoModeMODE(int screen, int mode, int rate)
{ {
#if defined( _GLFW_HAS_XRANDR ) #if defined(_GLFW_HAS_XRANDR)
XRRScreenConfiguration *sc; XRRScreenConfiguration *sc;
Window root; Window root;
if( _glfwLibrary.XRandR.available ) if (_glfwLibrary.XRandR.available)
{ {
root = RootWindow( _glfwLibrary.display, screen ); root = RootWindow(_glfwLibrary.display, screen);
sc = XRRGetScreenInfo( _glfwLibrary.display, root ); sc = XRRGetScreenInfo(_glfwLibrary.display, root);
// Remember old size and flag that we have changed the mode // Remember old size and flag that we have changed the mode
if( !_glfwWin.FS.modeChanged ) if (!_glfwWin.FS.modeChanged)
{ {
_glfwWin.FS.oldSizeID = XRRConfigCurrentConfiguration( sc, &_glfwWin.FS.oldRotation ); _glfwWin.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwWin.FS.oldRotation);
_glfwWin.FS.oldWidth = DisplayWidth( _glfwLibrary.display, screen ); _glfwWin.FS.oldWidth = DisplayWidth(_glfwLibrary.display, screen);
_glfwWin.FS.oldHeight = DisplayHeight( _glfwLibrary.display, screen ); _glfwWin.FS.oldHeight = DisplayHeight(_glfwLibrary.display, screen);
_glfwWin.FS.modeChanged = GL_TRUE; _glfwWin.FS.modeChanged = GL_TRUE;
} }
if( rate > 0 ) if (rate > 0)
{ {
// Set desired configuration // Set desired configuration
XRRSetScreenConfigAndRate( _glfwLibrary.display, XRRSetScreenConfigAndRate(_glfwLibrary.display,
sc, sc,
root, root,
mode, mode,
RR_Rotate_0, RR_Rotate_0,
(short) rate, (short) rate,
CurrentTime ); CurrentTime);
} }
else else
{ {
// Set desired configuration // Set desired configuration
XRRSetScreenConfig( _glfwLibrary.display, XRRSetScreenConfig(_glfwLibrary.display,
sc, sc,
root, root,
mode, mode,
RR_Rotate_0, RR_Rotate_0,
CurrentTime ); CurrentTime);
} }
XRRFreeScreenConfigInfo( sc ); XRRFreeScreenConfigInfo(sc);
} }
#elif defined( _GLFW_HAS_XF86VIDMODE ) #elif defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo **modelist; XF86VidModeModeInfo **modelist;
int modecount; int modecount;
// Use the XF86VidMode extension to control video resolution // Use the XF86VidMode extension to control video resolution
if( _glfwLibrary.XF86VidMode.available ) if (_glfwLibrary.XF86VidMode.available)
{ {
// Get a list of all available display modes // Get a list of all available display modes
XF86VidModeGetAllModeLines( _glfwLibrary.display, screen, XF86VidModeGetAllModeLines(_glfwLibrary.display, screen,
&modecount, &modelist ); &modecount, &modelist);
// Unlock mode switch if necessary // Unlock mode switch if necessary
if( _glfwWin.FS.modeChanged ) if (_glfwWin.FS.modeChanged)
XF86VidModeLockModeSwitch( _glfwLibrary.display, screen, 0 ); XF86VidModeLockModeSwitch(_glfwLibrary.display, screen, 0);
// Change the video mode to the desired mode // Change the video mode to the desired mode
XF86VidModeSwitchToMode( _glfwLibrary.display, screen, XF86VidModeSwitchToMode(_glfwLibrary.display, screen,
modelist[ mode ] ); modelist[mode]);
// Set viewport to upper left corner (where our window will be) // Set viewport to upper left corner (where our window will be)
XF86VidModeSetViewPort( _glfwLibrary.display, screen, 0, 0 ); XF86VidModeSetViewPort(_glfwLibrary.display, screen, 0, 0);
// Lock mode switch // Lock mode switch
XF86VidModeLockModeSwitch( _glfwLibrary.display, screen, 1 ); XF86VidModeLockModeSwitch(_glfwLibrary.display, screen, 1);
// Remember old mode and flag that we have changed the mode // Remember old mode and flag that we have changed the mode
if( !_glfwWin.FS.modeChanged ) if (!_glfwWin.FS.modeChanged)
{ {
_glfwWin.FS.oldMode = *modelist[ 0 ]; _glfwWin.FS.oldMode = *modelist[0];
_glfwWin.FS.modeChanged = GL_TRUE; _glfwWin.FS.modeChanged = GL_TRUE;
} }
// Free mode list // Free mode list
XFree( modelist ); XFree(modelist);
} }
#endif #endif
} }
@ -272,15 +272,15 @@ void _glfwSetVideoModeMODE( int screen, int mode, int rate )
// Change the current video mode // Change the current video mode
//======================================================================== //========================================================================
void _glfwSetVideoMode( int screen, int *width, int *height, int *rate ) void _glfwSetVideoMode(int screen, int *width, int *height, int *rate)
{ {
int bestmode; int bestmode;
// Find a best match mode // Find a best match mode
bestmode = _glfwGetClosestVideoMode( screen, width, height, rate ); bestmode = _glfwGetClosestVideoMode(screen, width, height, rate);
// Change mode // Change mode
_glfwSetVideoModeMODE( screen, bestmode, *rate ); _glfwSetVideoModeMODE(screen, bestmode, *rate);
} }
@ -288,39 +288,39 @@ void _glfwSetVideoMode( int screen, int *width, int *height, int *rate )
// Restore the previously saved (original) video mode // Restore the previously saved (original) video mode
//======================================================================== //========================================================================
void _glfwRestoreVideoMode( void ) void _glfwRestoreVideoMode(void)
{ {
if( _glfwWin.FS.modeChanged ) if (_glfwWin.FS.modeChanged)
{ {
#if defined( _GLFW_HAS_XRANDR ) #if defined(_GLFW_HAS_XRANDR)
if( _glfwLibrary.XRandR.available ) if (_glfwLibrary.XRandR.available)
{ {
XRRScreenConfiguration *sc; XRRScreenConfiguration *sc;
if( _glfwLibrary.XRandR.available ) if (_glfwLibrary.XRandR.available)
{ {
sc = XRRGetScreenInfo( _glfwLibrary.display, _glfwWin.root ); sc = XRRGetScreenInfo(_glfwLibrary.display, _glfwWin.root);
XRRSetScreenConfig( _glfwLibrary.display, XRRSetScreenConfig(_glfwLibrary.display,
sc, sc,
_glfwWin.root, _glfwWin.root,
_glfwWin.FS.oldSizeID, _glfwWin.FS.oldSizeID,
_glfwWin.FS.oldRotation, _glfwWin.FS.oldRotation,
CurrentTime ); CurrentTime);
XRRFreeScreenConfigInfo( sc ); XRRFreeScreenConfigInfo(sc);
} }
} }
#elif defined( _GLFW_HAS_XF86VIDMODE ) #elif defined(_GLFW_HAS_XF86VIDMODE)
if( _glfwLibrary.XF86VidMode.available ) if (_glfwLibrary.XF86VidMode.available)
{ {
// Unlock mode switch // Unlock mode switch
XF86VidModeLockModeSwitch( _glfwLibrary.display, _glfwWin.screen, 0 ); XF86VidModeLockModeSwitch(_glfwLibrary.display, _glfwWin.screen, 0);
// Change the video mode back to the old mode // Change the video mode back to the old mode
XF86VidModeSwitchToMode( _glfwLibrary.display, XF86VidModeSwitchToMode(_glfwLibrary.display,
_glfwWin.screen, _glfwWin.screen,
&_glfwWin.FS.oldMode ); &_glfwWin.FS.oldMode);
} }
#endif #endif
_glfwWin.FS.modeChanged = GL_FALSE; _glfwWin.FS.modeChanged = GL_FALSE;
@ -343,7 +343,7 @@ struct _glfwResolution
// List available video modes // List available video modes
//======================================================================== //========================================================================
int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount ) int _glfwPlatformGetVideoModes(GLFWvidmode *list, int maxcount)
{ {
int count, k, l, r, g, b, rgba, gl; int count, k, l, r, g, b, rgba, gl;
int depth, screen; int depth, screen;
@ -352,52 +352,52 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
int viscount, rgbcount, rescount; int viscount, rgbcount, rescount;
int *rgbarray; int *rgbarray;
struct _glfwResolution *resarray; struct _glfwResolution *resarray;
#if defined( _GLFW_HAS_XRANDR ) #if defined(_GLFW_HAS_XRANDR)
XRRScreenConfiguration *sc; XRRScreenConfiguration *sc;
XRRScreenSize *sizelist; XRRScreenSize *sizelist;
int sizecount; int sizecount;
#elif defined( _GLFW_HAS_XF86VIDMODE ) #elif defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo **modelist; XF86VidModeModeInfo **modelist;
int modecount, width, height; int modecount, width, height;
#endif #endif
// Get display and screen // Get display and screen
dpy = _glfwLibrary.display; dpy = _glfwLibrary.display;
screen = DefaultScreen( dpy ); screen = DefaultScreen(dpy);
// Get list of visuals // Get list of visuals
vislist = XGetVisualInfo( dpy, 0, &dummy, &viscount ); vislist = XGetVisualInfo(dpy, 0, &dummy, &viscount);
if( vislist == NULL ) if (vislist == NULL)
return 0; return 0;
rgbarray = (int*) malloc( sizeof(int) * viscount ); rgbarray = (int*) malloc(sizeof(int) * viscount);
rgbcount = 0; rgbcount = 0;
// Build RGB array // Build RGB array
for( k = 0; k < viscount; k++ ) for (k = 0; k < viscount; k++)
{ {
// Does the visual support OpenGL & true color? // Does the visual support OpenGL & true color?
glXGetConfig( dpy, &vislist[k], GLX_USE_GL, &gl ); glXGetConfig(dpy, &vislist[k], GLX_USE_GL, &gl);
glXGetConfig( dpy, &vislist[k], GLX_RGBA, &rgba ); glXGetConfig(dpy, &vislist[k], GLX_RGBA, &rgba);
if( gl && rgba ) if (gl && rgba)
{ {
// Get color depth for this visual // Get color depth for this visual
depth = vislist[k].depth; depth = vislist[k].depth;
// Convert to RGB // Convert to RGB
BPP2RGB( depth, &r, &g, &b ); BPP2RGB(depth, &r, &g, &b);
depth = (r<<16) | (g<<8) | b; depth = (r << 16) | (g << 8) | b;
// Is this mode unique? // Is this mode unique?
for( l = 0; l < rgbcount; l++ ) for (l = 0; l < rgbcount; l++)
{ {
if( depth == rgbarray[ l ] ) if (depth == rgbarray[l])
break; break;
} }
if( l >= rgbcount ) if (l >= rgbcount)
{ {
rgbarray[ rgbcount ] = depth; rgbarray[rgbcount] = depth;
rgbcount++; rgbcount++;
} }
} }
@ -407,83 +407,83 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
resarray = NULL; resarray = NULL;
// Build resolution array // Build resolution array
#if defined( _GLFW_HAS_XRANDR ) #if defined(_GLFW_HAS_XRANDR)
if( _glfwLibrary.XRandR.available ) if (_glfwLibrary.XRandR.available)
{ {
sc = XRRGetScreenInfo( dpy, RootWindow( dpy, screen ) ); sc = XRRGetScreenInfo(dpy, RootWindow(dpy, screen));
sizelist = XRRConfigSizes( sc, &sizecount ); sizelist = XRRConfigSizes(sc, &sizecount);
resarray = (struct _glfwResolution*) malloc( sizeof(struct _glfwResolution) * sizecount ); resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * sizecount);
for( k = 0; k < sizecount; k++ ) for (k = 0; k < sizecount; k++)
{ {
resarray[ rescount ].width = sizelist[ k ].width; resarray[rescount].width = sizelist[k].width;
resarray[ rescount ].height = sizelist[ k ].height; resarray[rescount].height = sizelist[k].height;
rescount++; rescount++;
} }
XRRFreeScreenConfigInfo( sc ); XRRFreeScreenConfigInfo(sc);
} }
#elif defined( _GLFW_HAS_XF86VIDMODE ) #elif defined(_GLFW_HAS_XF86VIDMODE)
if( _glfwLibrary.XF86VidMode.available ) if (_glfwLibrary.XF86VidMode.available)
{ {
XF86VidModeGetAllModeLines( dpy, screen, &modecount, &modelist ); XF86VidModeGetAllModeLines(dpy, screen, &modecount, &modelist);
resarray = (struct _glfwResolution*) malloc( sizeof(struct _glfwResolution) * modecount ); resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount);
for( k = 0; k < modecount; k++ ) for (k = 0; k < modecount; k++)
{ {
width = modelist[ k ]->hdisplay; width = modelist[k]->hdisplay;
height = modelist[ k ]->vdisplay; height = modelist[k]->vdisplay;
// Is this mode unique? // Is this mode unique?
for( l = 0; l < rescount; l++ ) for (l = 0; l < rescount; l++)
{ {
if( width == resarray[ l ].width && height == resarray[ l ].height ) if (width == resarray[l].width && height == resarray[l].height)
break; break;
} }
if( l >= rescount ) if (l >= rescount)
{ {
resarray[ rescount ].width = width; resarray[rescount].width = width;
resarray[ rescount ].height = height; resarray[rescount].height = height;
rescount++; rescount++;
} }
} }
XFree( modelist ); XFree(modelist);
} }
#endif #endif
if( !resarray ) if (!resarray)
{ {
rescount = 1; rescount = 1;
resarray = (struct _glfwResolution*) malloc( sizeof(struct _glfwResolution) * rescount ); resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount);
resarray[ 0 ].width = DisplayWidth( dpy, screen ); resarray[ 0 ].width = DisplayWidth(dpy, screen);
resarray[ 0 ].height = DisplayHeight( dpy, screen ); resarray[ 0 ].height = DisplayHeight(dpy, screen);
} }
// Build permutations of colors and resolutions // Build permutations of colors and resolutions
count = 0; count = 0;
for( k = 0; k < rgbcount && count < maxcount; k++ ) for (k = 0; k < rgbcount && count < maxcount; k++)
{ {
for( l = 0; l < rescount && count < maxcount; l++ ) for (l = 0; l < rescount && count < maxcount; l++)
{ {
list[count].Width = resarray[ l ].width; list[count].Width = resarray[l].width;
list[count].Height = resarray[ l ].height; list[count].Height = resarray[l].height;
list[count].RedBits = (rgbarray[ k ] >> 16) & 255; list[count].RedBits = (rgbarray[k] >> 16) & 255;
list[count].GreenBits = (rgbarray[ k ] >> 8) & 255; list[count].GreenBits = (rgbarray[k] >> 8) & 255;
list[count].BlueBits = rgbarray[ k ] & 255; list[count].BlueBits = rgbarray[k] & 255;
count++; count++;
} }
} }
// Free visuals list // Free visuals list
XFree( vislist ); XFree(vislist);
free( resarray ); free(resarray);
free( rgbarray ); free(rgbarray);
return count; return count;
} }
@ -493,39 +493,39 @@ int _glfwPlatformGetVideoModes( GLFWvidmode *list, int maxcount )
// Get the desktop video mode // Get the desktop video mode
//======================================================================== //========================================================================
void _glfwPlatformGetDesktopMode( GLFWvidmode *mode ) void _glfwPlatformGetDesktopMode(GLFWvidmode *mode)
{ {
Display *dpy; Display *dpy;
int bpp, screen; int bpp, screen;
#if defined( _GLFW_HAS_XF86VIDMODE ) #if defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo **modelist; XF86VidModeModeInfo **modelist;
int modecount; int modecount;
#endif #endif
// Get display and screen // Get display and screen
dpy = _glfwLibrary.display; dpy = _glfwLibrary.display;
screen = DefaultScreen( dpy ); screen = DefaultScreen(dpy);
// Get display depth // Get display depth
bpp = DefaultDepth( dpy, screen ); bpp = DefaultDepth(dpy, screen);
// Convert BPP to RGB bits // Convert BPP to RGB bits
BPP2RGB( bpp, &mode->RedBits, &mode->GreenBits, &mode->BlueBits ); BPP2RGB(bpp, &mode->RedBits, &mode->GreenBits, &mode->BlueBits);
#if defined( _GLFW_HAS_XRANDR ) #if defined(_GLFW_HAS_XRANDR)
if( _glfwLibrary.XRandR.available ) if (_glfwLibrary.XRandR.available)
{ {
if( _glfwWin.FS.modeChanged ) if (_glfwWin.FS.modeChanged)
{ {
mode->Width = _glfwWin.FS.oldWidth; mode->Width = _glfwWin.FS.oldWidth;
mode->Height = _glfwWin.FS.oldHeight; mode->Height = _glfwWin.FS.oldHeight;
return; return;
} }
} }
#elif defined( _GLFW_HAS_XF86VIDMODE ) #elif defined(_GLFW_HAS_XF86VIDMODE)
if( _glfwLibrary.XF86VidMode.available ) if (_glfwLibrary.XF86VidMode.available)
{ {
if( _glfwWin.FS.modeChanged ) if (_glfwWin.FS.modeChanged)
{ {
// The old (desktop) mode is stored in _glfwWin.FS.oldMode // The old (desktop) mode is stored in _glfwWin.FS.oldMode
mode->Width = _glfwWin.FS.oldMode.hdisplay; mode->Width = _glfwWin.FS.oldMode.hdisplay;
@ -534,15 +534,14 @@ void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
else else
{ {
// Use the XF86VidMode extension to get list of video modes // Use the XF86VidMode extension to get list of video modes
XF86VidModeGetAllModeLines( dpy, screen, &modecount, XF86VidModeGetAllModeLines(dpy, screen, &modecount, &modelist);
&modelist );
// The first mode in the list is the current (desktio) mode // The first mode in the list is the current (desktio) mode
mode->Width = modelist[ 0 ]->hdisplay; mode->Width = modelist[0]->hdisplay;
mode->Height = modelist[ 0 ]->vdisplay; mode->Height = modelist[0]->vdisplay;
// Free list // Free list
XFree( modelist ); XFree(modelist);
} }
return; return;
@ -550,7 +549,7 @@ void _glfwPlatformGetDesktopMode( GLFWvidmode *mode )
#endif #endif
// Get current display width and height // Get current display width and height
mode->Width = DisplayWidth( dpy, screen ); mode->Width = DisplayWidth(dpy, screen);
mode->Height = DisplayHeight( dpy, screen ); mode->Height = DisplayHeight(dpy, screen);
} }

View File

@ -38,13 +38,13 @@ void (*glXGetProcAddressEXT(const GLubyte *procName))();
// We support four different ways for getting addresses for GL/GLX // We support four different ways for getting addresses for GL/GLX
// extension functions: glXGetProcAddress, glXGetProcAddressARB, // extension functions: glXGetProcAddress, glXGetProcAddressARB,
// glXGetProcAddressEXT, and dlsym // glXGetProcAddressEXT, and dlsym
#if defined( _GLFW_HAS_GLXGETPROCADDRESSARB ) #if defined(_GLFW_HAS_GLXGETPROCADDRESSARB)
#define _glfw_glXGetProcAddress(x) glXGetProcAddressARB(x) #define _glfw_glXGetProcAddress(x) glXGetProcAddressARB(x)
#elif defined( _GLFW_HAS_GLXGETPROCADDRESS ) #elif defined(_GLFW_HAS_GLXGETPROCADDRESS)
#define _glfw_glXGetProcAddress(x) glXGetProcAddress(x) #define _glfw_glXGetProcAddress(x) glXGetProcAddress(x)
#elif defined( _GLFW_HAS_GLXGETPROCADDRESSEXT ) #elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT)
#define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x) #define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x)
#elif defined( _GLFW_HAS_DLOPEN ) #elif defined(_GLFW_HAS_DLOPEN)
#define _glfw_glXGetProcAddress(x) dlsym(_glfwLibs.libGL,x) #define _glfw_glXGetProcAddress(x) dlsym(_glfwLibs.libGL,x)
#define _GLFW_DLOPEN_LIBGL #define _GLFW_DLOPEN_LIBGL
#else #else
@ -60,16 +60,16 @@ void (*glXGetProcAddressEXT(const GLubyte *procName))();
// Check if an OpenGL extension is available at runtime // Check if an OpenGL extension is available at runtime
//======================================================================== //========================================================================
int _glfwPlatformExtensionSupported( const char *extension ) int _glfwPlatformExtensionSupported(const char *extension)
{ {
const GLubyte *extensions; const GLubyte *extensions;
// Get list of GLX extensions // Get list of GLX extensions
extensions = (const GLubyte*) glXQueryExtensionsString( _glfwLibrary.display, extensions = (const GLubyte*) glXQueryExtensionsString(_glfwLibrary.display,
_glfwWin.screen ); _glfwWin.screen);
if( extensions != NULL ) if (extensions != NULL)
{ {
if( _glfwStringInExtensionString( extension, extensions ) ) if (_glfwStringInExtensionString(extension, extensions))
return GL_TRUE; return GL_TRUE;
} }
@ -81,8 +81,8 @@ int _glfwPlatformExtensionSupported( const char *extension )
// Get the function pointer to an OpenGL function // Get the function pointer to an OpenGL function
//======================================================================== //========================================================================
void * _glfwPlatformGetProcAddress( const char *procname ) void * _glfwPlatformGetProcAddress(const char *procname)
{ {
return (void *) _glfw_glXGetProcAddress( (const GLubyte *) procname ); return (void *) _glfw_glXGetProcAddress((const GLubyte *) procname);
} }

View File

@ -39,7 +39,7 @@
// Dynamically load libraries // Dynamically load libraries
//======================================================================== //========================================================================
static void initLibraries( void ) static void initLibraries(void)
{ {
#ifdef _GLFW_DLOPEN_LIBGL #ifdef _GLFW_DLOPEN_LIBGL
int i; int i;
@ -53,11 +53,10 @@ static void initLibraries( void )
}; };
_glfwLibrary.Libs.libGL = NULL; _glfwLibrary.Libs.libGL = NULL;
for( i = 0; !libGL_names[ i ] != NULL; i ++ ) for (i = 0; libGL_names[i] != NULL; i++)
{ {
_glfwLibrary.Libs.libGL = dlopen( libGL_names[ i ], _glfwLibrary.Libs.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL);
RTLD_LAZY | RTLD_GLOBAL ); if (_glfwLibrary.Libs.libGL)
if( _glfwLibrary.Libs.libGL )
break; break;
} }
#endif #endif
@ -68,7 +67,7 @@ static void initLibraries( void )
// Terminate GLFW when exiting application // Terminate GLFW when exiting application
//======================================================================== //========================================================================
static void glfw_atexit( void ) static void glfw_atexit(void)
{ {
glfwTerminate(); glfwTerminate();
} }
@ -78,11 +77,11 @@ static void glfw_atexit( void )
// Initialize X11 display // Initialize X11 display
//======================================================================== //========================================================================
static int initDisplay( void ) static int initDisplay(void)
{ {
// Open display // Open display
_glfwLibrary.display = XOpenDisplay( 0 ); _glfwLibrary.display = XOpenDisplay(0);
if( !_glfwLibrary.display ) if (!_glfwLibrary.display)
{ {
fprintf(stderr, "Failed to open X display\n"); fprintf(stderr, "Failed to open X display\n");
return GL_FALSE; return GL_FALSE;
@ -91,9 +90,9 @@ static int initDisplay( void )
// Check for XF86VidMode extension // Check for XF86VidMode extension
#ifdef _GLFW_HAS_XF86VIDMODE #ifdef _GLFW_HAS_XF86VIDMODE
_glfwLibrary.XF86VidMode.available = _glfwLibrary.XF86VidMode.available =
XF86VidModeQueryExtension( _glfwLibrary.display, XF86VidModeQueryExtension(_glfwLibrary.display,
&_glfwLibrary.XF86VidMode.eventBase, &_glfwLibrary.XF86VidMode.eventBase,
&_glfwLibrary.XF86VidMode.errorBase); &_glfwLibrary.XF86VidMode.errorBase);
#else #else
_glfwLibrary.XF86VidMode.available = 0; _glfwLibrary.XF86VidMode.available = 0;
#endif #endif
@ -101,25 +100,25 @@ static int initDisplay( void )
// Check for XRandR extension // Check for XRandR extension
#ifdef _GLFW_HAS_XRANDR #ifdef _GLFW_HAS_XRANDR
_glfwLibrary.XRandR.available = _glfwLibrary.XRandR.available =
XRRQueryExtension( _glfwLibrary.display, XRRQueryExtension(_glfwLibrary.display,
&_glfwLibrary.XRandR.eventBase, &_glfwLibrary.XRandR.eventBase,
&_glfwLibrary.XRandR.errorBase ); &_glfwLibrary.XRandR.errorBase);
#else #else
_glfwLibrary.XRandR.available = 0; _glfwLibrary.XRandR.available = 0;
#endif #endif
// Fullscreen & screen saver settings // Fullscreen & screen saver settings
// Check if GLX is supported on this display // Check if GLX is supported on this display
if( !glXQueryExtension( _glfwLibrary.display, NULL, NULL ) ) if (!glXQueryExtension(_glfwLibrary.display, NULL, NULL))
{ {
fprintf(stderr, "GLX not supported\n"); fprintf(stderr, "GLX not supported\n");
return GL_FALSE; return GL_FALSE;
} }
// Retrieve GLX version // Retrieve GLX version
if( !glXQueryVersion( _glfwLibrary.display, if (!glXQueryVersion(_glfwLibrary.display,
&_glfwLibrary.glxMajor, &_glfwLibrary.glxMajor,
&_glfwLibrary.glxMinor ) ) &_glfwLibrary.glxMinor))
{ {
fprintf(stderr, "Unable to query GLX version\n"); fprintf(stderr, "Unable to query GLX version\n");
return GL_FALSE; return GL_FALSE;
@ -133,12 +132,12 @@ static int initDisplay( void )
// Terminate X11 display // Terminate X11 display
//======================================================================== //========================================================================
static void terminateDisplay( void ) static void terminateDisplay(void)
{ {
// Open display // Open display
if( _glfwLibrary.display ) if (_glfwLibrary.display)
{ {
XCloseDisplay( _glfwLibrary.display ); XCloseDisplay(_glfwLibrary.display);
_glfwLibrary.display = NULL; _glfwLibrary.display = NULL;
} }
} }
@ -152,16 +151,16 @@ static void terminateDisplay( void )
// Initialize various GLFW state // Initialize various GLFW state
//======================================================================== //========================================================================
int _glfwPlatformInit( void ) int _glfwPlatformInit(void)
{ {
if( !initDisplay() ) if (!initDisplay())
return GL_FALSE; return GL_FALSE;
// Try to load libGL.so if necessary // Try to load libGL.so if necessary
initLibraries(); initLibraries();
// Install atexit() routine // Install atexit() routine
atexit( glfw_atexit ); atexit(glfw_atexit);
// Initialize joysticks // Initialize joysticks
_glfwInitJoysticks(); _glfwInitJoysticks();
@ -177,7 +176,7 @@ int _glfwPlatformInit( void )
// Close window and shut down library // Close window and shut down library
//======================================================================== //========================================================================
int _glfwPlatformTerminate( void ) int _glfwPlatformTerminate(void)
{ {
// Close OpenGL window // Close OpenGL window
glfwCloseWindow(); glfwCloseWindow();
@ -190,9 +189,9 @@ int _glfwPlatformTerminate( void )
// Unload libGL.so if necessary // Unload libGL.so if necessary
#ifdef _GLFW_DLOPEN_LIBGL #ifdef _GLFW_DLOPEN_LIBGL
if( _glfwLibrary.Libs.libGL != NULL ) if (_glfwLibrary.Libs.libGL != NULL)
{ {
dlclose( _glfwLibrary.Libs.libGL ); dlclose(_glfwLibrary.Libs.libGL);
_glfwLibrary.Libs.libGL = NULL; _glfwLibrary.Libs.libGL = NULL;
} }
#endif #endif

View File

@ -77,28 +77,28 @@ struct js_event {
// Initialize joystick interface // Initialize joystick interface
//======================================================================== //========================================================================
void _glfwInitJoysticks( void ) void _glfwInitJoysticks(void)
{ {
#ifdef _GLFW_USE_LINUX_JOYSTICKS #ifdef _GLFW_USE_LINUX_JOYSTICKS
int k, n, fd, joy_count; int k, n, fd, joy_count;
char *joy_base_name, joy_dev_name[ 20 ]; char *joy_base_name, joy_dev_name[20];
int driver_version = 0x000800; int driver_version = 0x000800;
char ret_data; char ret_data;
#endif // _GLFW_USE_LINUX_JOYSTICKS #endif // _GLFW_USE_LINUX_JOYSTICKS
int i; int i;
// Start by saying that there are no sticks // Start by saying that there are no sticks
for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i ) for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
_glfwJoy[ i ].Present = GL_FALSE; _glfwJoy[i].Present = GL_FALSE;
#ifdef _GLFW_USE_LINUX_JOYSTICKS #ifdef _GLFW_USE_LINUX_JOYSTICKS
// Try to open joysticks (nonblocking) // Try to open joysticks (nonblocking)
joy_count = 0; joy_count = 0;
for( k = 0; k <= 1 && joy_count <= GLFW_JOYSTICK_LAST; ++ k ) for (k = 0; k <= 1 && joy_count <= GLFW_JOYSTICK_LAST; k++)
{ {
// Pick joystick base name // Pick joystick base name
switch( k ) switch (k)
{ {
case 0: case 0:
joy_base_name = "/dev/input/js"; // USB sticks joy_base_name = "/dev/input/js"; // USB sticks
@ -111,67 +111,65 @@ void _glfwInitJoysticks( void )
} }
// Try to open a few of these sticks // Try to open a few of these sticks
for( i = 0; i <= 50 && joy_count <= GLFW_JOYSTICK_LAST; ++ i ) for (i = 0; i <= 50 && joy_count <= GLFW_JOYSTICK_LAST; i++)
{ {
sprintf( joy_dev_name, "%s%d", joy_base_name, i ); sprintf(joy_dev_name, "%s%d", joy_base_name, i);
fd = open( joy_dev_name, O_NONBLOCK ); fd = open(joy_dev_name, O_NONBLOCK);
if( fd != -1 ) if (fd != -1)
{ {
// Remember fd // Remember fd
_glfwJoy[ joy_count ].fd = fd; _glfwJoy[joy_count].fd = fd;
// Check that the joystick driver version is 1.0+ // Check that the joystick driver version is 1.0+
ioctl( fd, JSIOCGVERSION, &driver_version ); ioctl(fd, JSIOCGVERSION, &driver_version);
if( driver_version < 0x010000 ) if (driver_version < 0x010000)
{ {
// It's an old 0.x interface (we don't support it) // It's an old 0.x interface (we don't support it)
close( fd ); close(fd);
continue; continue;
} }
// Get number of joystick axes // Get number of joystick axes
ioctl( fd, JSIOCGAXES, &ret_data ); ioctl(fd, JSIOCGAXES, &ret_data);
_glfwJoy[ joy_count ].NumAxes = (int) ret_data; _glfwJoy[joy_count].NumAxes = (int) ret_data;
// Get number of joystick buttons // Get number of joystick buttons
ioctl( fd, JSIOCGBUTTONS, &ret_data ); ioctl(fd, JSIOCGBUTTONS, &ret_data);
_glfwJoy[ joy_count ].NumButtons = (int) ret_data; _glfwJoy[joy_count].NumButtons = (int) ret_data;
// Allocate memory for joystick state // Allocate memory for joystick state
_glfwJoy[ joy_count ].Axis = _glfwJoy[joy_count].Axis =
(float *) malloc( sizeof(float) * (float *) malloc(sizeof(float) *
_glfwJoy[ joy_count ].NumAxes ); _glfwJoy[joy_count].NumAxes);
if( _glfwJoy[ joy_count ].Axis == NULL ) if (_glfwJoy[joy_count].Axis == NULL)
{ {
close( fd ); close(fd);
continue; continue;
} }
_glfwJoy[ joy_count ].Button = _glfwJoy[joy_count].Button =
(unsigned char *) malloc( sizeof(char) * (unsigned char *) malloc(sizeof(char) *
_glfwJoy[ joy_count ].NumButtons ); _glfwJoy[joy_count].NumButtons);
if( _glfwJoy[ joy_count ].Button == NULL ) if (_glfwJoy[joy_count].Button == NULL)
{ {
free( _glfwJoy[ joy_count ].Axis ); free(_glfwJoy[joy_count].Axis);
close( fd ); close(fd);
continue; continue;
} }
// Clear joystick state // Clear joystick state
for( n = 0; n < _glfwJoy[ joy_count ].NumAxes; ++ n ) for (n = 0; n < _glfwJoy[joy_count].NumAxes; n++)
_glfwJoy[ joy_count ].Axis[ n ] = 0.0f; _glfwJoy[joy_count].Axis[n] = 0.0f;
for( n = 0; n < _glfwJoy[ joy_count ].NumButtons; ++ n ) for (n = 0; n < _glfwJoy[joy_count].NumButtons; n++)
_glfwJoy[ joy_count ].Button[ n ] = GLFW_RELEASE; _glfwJoy[joy_count].Button[n] = GLFW_RELEASE;
// The joystick is supported and connected // The joystick is supported and connected
_glfwJoy[ joy_count ].Present = GL_TRUE; _glfwJoy[joy_count].Present = GL_TRUE;
joy_count ++; joy_count++;
} }
} }
} }
#endif // _GLFW_USE_LINUX_JOYSTICKS #endif // _GLFW_USE_LINUX_JOYSTICKS
} }
@ -179,7 +177,7 @@ void _glfwInitJoysticks( void )
// Close all opened joystick handles // Close all opened joystick handles
//======================================================================== //========================================================================
void _glfwTerminateJoysticks( void ) void _glfwTerminateJoysticks(void)
{ {
#ifdef _GLFW_USE_LINUX_JOYSTICKS #ifdef _GLFW_USE_LINUX_JOYSTICKS
@ -187,14 +185,15 @@ void _glfwTerminateJoysticks( void )
int i; int i;
// Close any opened joysticks // Close any opened joysticks
for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i ) for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
{ {
if( _glfwJoy[ i ].Present ) if (_glfwJoy[i].Present)
{ {
close( _glfwJoy[ i ].fd ); close(_glfwJoy[i].fd);
free( _glfwJoy[ i ].Axis ); free(_glfwJoy[i].Axis);
free( _glfwJoy[ i ].Button ); free(_glfwJoy[i].Button);
_glfwJoy[ i ].Present = GL_FALSE;
_glfwJoy[i].Present = GL_FALSE;
} }
} }
@ -207,43 +206,38 @@ void _glfwTerminateJoysticks( void )
// Empty joystick event queue // Empty joystick event queue
//======================================================================== //========================================================================
static void pollJoystickEvents( void ) static void pollJoystickEvents(void)
{ {
#ifdef _GLFW_USE_LINUX_JOYSTICKS #ifdef _GLFW_USE_LINUX_JOYSTICKS
struct js_event e; struct js_event e;
int i; int i;
// Get joystick events for all GLFW joysticks // Get joystick events for all GLFW joysticks
for( i = 0; i <= GLFW_JOYSTICK_LAST; ++ i ) for (i = 0; i <= GLFW_JOYSTICK_LAST; i++)
{ {
// Is the stick present? // Is the stick present?
if( _glfwJoy[ i ].Present ) if (_glfwJoy[i].Present)
{ {
// Read all queued events (non-blocking) // Read all queued events (non-blocking)
while( read(_glfwJoy[i].fd, &e, sizeof(struct js_event)) > 0 ) while (read(_glfwJoy[i].fd, &e, sizeof(struct js_event)) > 0)
{ {
// We don't care if it's an init event or not // We don't care if it's an init event or not
e.type &= ~JS_EVENT_INIT; e.type &= ~JS_EVENT_INIT;
// Check event type // Check event type
switch( e.type ) switch (e.type)
{ {
case JS_EVENT_AXIS: case JS_EVENT_AXIS:
_glfwJoy[ i ].Axis[ e.number ] = (float) e.value / _glfwJoy[i].Axis[e.number] = (float) e.value / 32767.0f;
32767.0f;
// We need to change the sign for the Y axes, so that // We need to change the sign for the Y axes, so that
// positive = up/forward, according to the GLFW spec. // positive = up/forward, according to the GLFW spec.
if( e.number & 1 ) if (e.number & 1)
{ _glfwJoy[i].Axis[e.number] = -_glfwJoy[i].Axis[e.number];
_glfwJoy[ i ].Axis[ e.number ] =
-_glfwJoy[ i ].Axis[ e.number ];
}
break; break;
case JS_EVENT_BUTTON: case JS_EVENT_BUTTON:
_glfwJoy[ i ].Button[ e.number ] = _glfwJoy[i].Button[e.number] =
e.value ? GLFW_PRESS : GLFW_RELEASE; e.value ? GLFW_PRESS : GLFW_RELEASE;
break; break;
@ -253,9 +247,7 @@ static void pollJoystickEvents( void )
} }
} }
} }
#endif // _GLFW_USE_LINUX_JOYSTICKS #endif // _GLFW_USE_LINUX_JOYSTICKS
} }
@ -267,21 +259,21 @@ static void pollJoystickEvents( void )
// Determine joystick capabilities // Determine joystick capabilities
//======================================================================== //========================================================================
int _glfwPlatformGetJoystickParam( int joy, int param ) int _glfwPlatformGetJoystickParam(int joy, int param)
{ {
if( !_glfwJoy[ joy ].Present ) if (!_glfwJoy[joy].Present)
return 0; return 0;
switch( param ) switch (param)
{ {
case GLFW_PRESENT: case GLFW_PRESENT:
return GL_TRUE; return GL_TRUE;
case GLFW_AXES: case GLFW_AXES:
return _glfwJoy[ joy ].NumAxes; return _glfwJoy[joy].NumAxes;
case GLFW_BUTTONS: case GLFW_BUTTONS:
return _glfwJoy[ joy ].NumButtons; return _glfwJoy[joy].NumButtons;
default: default:
break; break;
@ -295,23 +287,23 @@ int _glfwPlatformGetJoystickParam( int joy, int param )
// Get joystick axis positions // Get joystick axis positions
//======================================================================== //========================================================================
int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes ) int _glfwPlatformGetJoystickPos(int joy, float *pos, int numaxes)
{ {
int i; int i;
if( !_glfwJoy[ joy ].Present ) if (!_glfwJoy[joy].Present)
return 0; return 0;
// Update joystick state // Update joystick state
pollJoystickEvents(); pollJoystickEvents();
// Does the joystick support less axes than requested? // Does the joystick support less axes than requested?
if( _glfwJoy[ joy ].NumAxes < numaxes ) if (_glfwJoy[joy].NumAxes < numaxes)
numaxes = _glfwJoy[ joy ].NumAxes; numaxes = _glfwJoy[joy].NumAxes;
// Copy axis positions from internal state // Copy axis positions from internal state
for( i = 0; i < numaxes; ++ i ) for (i = 0; i < numaxes; i++)
pos[ i ] = _glfwJoy[ joy ].Axis[ i ]; pos[i] = _glfwJoy[joy].Axis[i];
return numaxes; return numaxes;
} }
@ -321,24 +313,24 @@ int _glfwPlatformGetJoystickPos( int joy, float *pos, int numaxes )
// Get joystick button states // Get joystick button states
//======================================================================== //========================================================================
int _glfwPlatformGetJoystickButtons( int joy, unsigned char *buttons, int _glfwPlatformGetJoystickButtons(int joy, unsigned char *buttons,
int numbuttons ) int numbuttons)
{ {
int i; int i;
if( !_glfwJoy[ joy ].Present ) if (!_glfwJoy[joy].Present)
return 0; return 0;
// Update joystick state // Update joystick state
pollJoystickEvents(); pollJoystickEvents();
// Does the joystick support less buttons than requested? // Does the joystick support less buttons than requested?
if( _glfwJoy[ joy ].NumButtons < numbuttons ) if (_glfwJoy[joy].NumButtons < numbuttons)
numbuttons = _glfwJoy[ joy ].NumButtons; numbuttons = _glfwJoy[joy].NumButtons;
// Copy button states from internal state // Copy button states from internal state
for( i = 0; i < numbuttons; ++ i ) for (i = 0; i < numbuttons; i++)
buttons[ i ] = _glfwJoy[ joy ].Button[ i ]; buttons[i] = _glfwJoy[joy].Button[i];
return numbuttons; return numbuttons;
} }

View File

@ -35,15 +35,15 @@
// Initialise timer // Initialise timer
//======================================================================== //========================================================================
void _glfwInitTimer( void ) void _glfwInitTimer(void)
{ {
struct timeval tv; struct timeval tv;
// "Resolution" is 1 us // "Resolution" is 1 us
_glfwLibrary.Timer.resolution = 1e-6; _glfwLibrary.Timer.resolution = 1e-6;
// Set start-time for timer // Set start-time for timer
gettimeofday( &tv, NULL ); gettimeofday(&tv, NULL);
_glfwLibrary.Timer.t0 = (long long) tv.tv_sec * (long long) 1000000 + _glfwLibrary.Timer.t0 = (long long) tv.tv_sec * (long long) 1000000 +
(long long) tv.tv_usec; (long long) tv.tv_usec;
} }
@ -57,12 +57,12 @@ void _glfwInitTimer( void )
// Return timer value in seconds // Return timer value in seconds
//======================================================================== //========================================================================
double _glfwPlatformGetTime( void ) double _glfwPlatformGetTime(void)
{ {
long long t; long long t;
struct timeval tv; struct timeval tv;
gettimeofday( &tv, NULL ); gettimeofday(&tv, NULL);
t = (long long) tv.tv_sec * (long long) 1000000 + t = (long long) tv.tv_sec * (long long) 1000000 +
(long long) tv.tv_usec; (long long) tv.tv_usec;
@ -74,16 +74,16 @@ double _glfwPlatformGetTime( void )
// Set timer value in seconds // Set timer value in seconds
//======================================================================== //========================================================================
void _glfwPlatformSetTime( double t ) void _glfwPlatformSetTime(double t)
{ {
long long t0; long long t0;
struct timeval tv; struct timeval tv;
gettimeofday( &tv, NULL ); gettimeofday(&tv, NULL);
t0 = (long long) tv.tv_sec * (long long) 1000000 + t0 = (long long) tv.tv_sec * (long long) 1000000 +
(long long) tv.tv_usec; (long long) tv.tv_usec;
// Calulate new starting time // Calulate new starting time
_glfwLibrary.Timer.t0 = t0 - (long long)(t/_glfwLibrary.Timer.resolution); _glfwLibrary.Timer.t0 = t0 - (long long)(t / _glfwLibrary.Timer.resolution);
} }

File diff suppressed because it is too large Load Diff