/* * Returns various device information. */ int FGAPIENTRY glutDeviceGet( GLenum eWhat ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDeviceGet" ); /* XXX WARNING: we are mostly lying in this function. */ switch( eWhat ) { case GLUT_HAS_JOYSTICK: return fgJoystickDetect (); case GLUT_OWNS_JOYSTICK: return fgState.JoysticksInitialised; case GLUT_JOYSTICK_POLL_RATE: return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.JoystickPollRate : 0; /* XXX The following two are only for Joystick 0 but this is an improvement */ case GLUT_JOYSTICK_BUTTONS: return glutJoystickGetNumButtons ( 0 ); case GLUT_JOYSTICK_AXES: return glutJoystickGetNumAxes ( 0 ); case GLUT_HAS_DIAL_AND_BUTTON_BOX: return fgInputDeviceDetect (); case GLUT_NUM_DIALS: if ( fgState.InputDevsInitialised ) return 8; return 0; case GLUT_NUM_BUTTON_BOX_BUTTONS: return 0; case GLUT_HAS_SPACEBALL: return fgHasSpaceball(); case GLUT_HAS_TABLET: return 0; case GLUT_NUM_SPACEBALL_BUTTONS: return fgSpaceballNumButtons(); case GLUT_NUM_TABLET_BUTTONS: return 0; case GLUT_DEVICE_IGNORE_KEY_REPEAT: return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.IgnoreKeyRepeat : 0; case GLUT_DEVICE_KEY_REPEAT: return fgState.KeyRepeat; default: return fgPlatformGlutDeviceGet ( eWhat ); } /* And now -- the failure. */ return -1; }
/* * Returns various device information. */ int FGAPIENTRY glutDeviceGet( GLenum eWhat ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDeviceGet" ); /* XXX WARNING: we are mostly lying in this function. */ switch( eWhat ) { case GLUT_HAS_KEYBOARD: /* * Win32 is assumed a keyboard, and this cannot be queried, * except for WindowsCE. * * X11 has a core keyboard by definition, although it can * be present as a virtual/dummy keyboard. For now, there * is no reliable way to tell if a real keyboard is present. */ #if defined(_WIN32_CE) return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0; # if FREEGLUT_LIB_PRAGMAS # pragma comment (lib,"Kbdui.lib") # endif #else return 1; #endif #if TARGET_HOST_POSIX_X11 /* X11 has a mouse by definition */ case GLUT_HAS_MOUSE: return 1 ; case GLUT_NUM_MOUSE_BUTTONS: /* We should be able to pass NULL when the last argument is zero, * but at least one X server has a bug where this causes a segfault. * * In XFree86/Xorg servers, a mouse wheel is seen as two buttons * rather than an Axis; "freeglut_main.c" expects this when * checking for a wheel event. */ { unsigned char map; int nbuttons = XGetPointerMapping(fgDisplay.Display, &map,0); return nbuttons; } #elif TARGET_HOST_MS_WINDOWS case GLUT_HAS_MOUSE: /* * MS Windows can be booted without a mouse. */ return GetSystemMetrics( SM_MOUSEPRESENT ); case GLUT_NUM_MOUSE_BUTTONS: # if defined(_WIN32_WCE) return 1; # else return GetSystemMetrics( SM_CMOUSEBUTTONS ); # endif #endif case GLUT_HAS_JOYSTICK: return fgJoystickDetect (); case GLUT_OWNS_JOYSTICK: return fgState.JoysticksInitialised; case GLUT_JOYSTICK_POLL_RATE: return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.JoystickPollRate : 0; /* XXX The following two are only for Joystick 0 but this is an improvement */ case GLUT_JOYSTICK_BUTTONS: return glutJoystickGetNumButtons ( 0 ); case GLUT_JOYSTICK_AXES: return glutJoystickGetNumAxes ( 0 ); case GLUT_HAS_DIAL_AND_BUTTON_BOX: return fgInputDeviceDetect (); case GLUT_NUM_DIALS: if ( fgState.InputDevsInitialised ) return 8; return 0; case GLUT_NUM_BUTTON_BOX_BUTTONS: return 0; case GLUT_HAS_SPACEBALL: return fgHasSpaceball(); case GLUT_HAS_TABLET: return 0; case GLUT_NUM_SPACEBALL_BUTTONS: return fgSpaceballNumButtons(); case GLUT_NUM_TABLET_BUTTONS: return 0; case GLUT_DEVICE_IGNORE_KEY_REPEAT: return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.IgnoreKeyRepeat : 0; case GLUT_DEVICE_KEY_REPEAT: return fgState.KeyRepeat; default: fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat ); break; } /* And now -- the failure. */ return -1; }
/* * Returns various device information. */ int FGAPIENTRY glutDeviceGet( GLenum eWhat ) { FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDeviceGet" ); /* XXX WARNING: we are mostly lying in this function. */ switch( eWhat ) { case GLUT_HAS_KEYBOARD: /* * We always have a keyboard present on PC machines... * * XXX I think that some of my PCs will boot without a keyboard. * XXX Also, who says that we are running on a PC? UNIX/X11 * XXX is much more generic, and X11 can go over a network. * XXX Though in actuality, we can probably assume BOTH a * XXX mouse and keyboard for most/all of our users. */ return TRUE ; #if TARGET_HOST_UNIX_X11 case GLUT_HAS_MOUSE: return TRUE ; case GLUT_NUM_MOUSE_BUTTONS: /* * Return the number of mouse buttons available. This is a big guess. * * XXX We can probe /var/run/dmesg.boot which is world-readable. * XXX This would be somewhat system-dependant, but is doable. * XXX E.g., on NetBSD, my USB mouse registers: * XXX ums0 at uhidev0: 3 buttons and Z dir. * XXX We can also probe /var/log/XFree86\..*\.log to get * XXX lines such as: * XXX (**) Option "Buttons" "5" * XXX (**) Option "ZAxisMapping" "4 5" * XXX (**) Mouse0: ZAxisMapping: buttons 4 and 5 * XXX (**) Mouse0: Buttons: 5 * XXX ...which tells us even more, and is a bit less * XXX system-dependant. (Other than MS-WINDOWS, all * XXX target hosts with actual users are probably running * XXX XFree86...) It is at least worth taking a look at * XXX this file. */ return 3 ; #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE case GLUT_HAS_MOUSE: /* * The Windows can be booted without a mouse. * It would be nice to have this reported. */ return GetSystemMetrics( SM_MOUSEPRESENT ); case GLUT_NUM_MOUSE_BUTTONS: /* We are much more fortunate under Win32 about this... */ #if TARGET_HOST_WINCE return 1; #else return GetSystemMetrics( SM_CMOUSEBUTTONS ); #endif /* TARGET_HOST_WINCE */ #endif case GLUT_HAS_JOYSTICK: return fgJoystickDetect (); case GLUT_OWNS_JOYSTICK: return fgState.JoysticksInitialised; case GLUT_JOYSTICK_POLL_RATE: return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.JoystickPollRate : 0; /* XXX The following two are only for Joystick 0 but this is an improvement */ case GLUT_JOYSTICK_BUTTONS: return glutJoystickGetNumButtons ( 0 ); case GLUT_JOYSTICK_AXES: return glutJoystickGetNumAxes ( 0 ); case GLUT_HAS_SPACEBALL: case GLUT_HAS_DIAL_AND_BUTTON_BOX: case GLUT_HAS_TABLET: return FALSE; case GLUT_NUM_SPACEBALL_BUTTONS: case GLUT_NUM_BUTTON_BOX_BUTTONS: case GLUT_NUM_DIALS: case GLUT_NUM_TABLET_BUTTONS: return 0; case GLUT_DEVICE_IGNORE_KEY_REPEAT: return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.IgnoreKeyRepeat : 0; case GLUT_DEVICE_KEY_REPEAT: return fgState.KeyRepeat; default: fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat ); break; } /* And now -- the failure. */ return -1; }