diff options
Diffstat (limited to 'src/unix/sdl_glimp.c')
-rw-r--r-- | src/unix/sdl_glimp.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/unix/sdl_glimp.c b/src/unix/sdl_glimp.c index 6fa5943b..dcfa0a89 100644 --- a/src/unix/sdl_glimp.c +++ b/src/unix/sdl_glimp.c @@ -84,6 +84,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /* Just hack it for now. */ #ifdef MACOS_X +#include <IOKit/hidsystem/IOHIDLib.h> +#include <IOKit/hidsystem/IOHIDParameter.h> +#include <drivers/event_status_driver.h> typedef CGLContextObj QGLContext; #define GLimp_GetCurrentContext() CGLGetCurrentContext() #define GLimp_SetCurrentContext(ctx) CGLSetCurrentContext(ctx) @@ -117,6 +120,10 @@ static qboolean mouse_active = qfalse; static qboolean sdlrepeatenabled = qfalse; static cvar_t *in_mouse; +static cvar_t *in_disablemacosxmouseaccel; +#ifdef MACOS_X +static double originalMouseSpeed = -1.0; +#endif cvar_t *in_subframe; cvar_t *in_nograb; // this is strictly for developers @@ -433,11 +440,69 @@ void KBD_Close(void) { } +#ifdef MACOS_X +io_connect_t IN_GetIOHandle() // mac os x mouse accel hack + { + io_connect_t iohandle = MACH_PORT_NULL; + kern_return_t status; + io_service_t iohidsystem = MACH_PORT_NULL; + mach_port_t masterport; + + status = IOMasterPort(MACH_PORT_NULL, &masterport); + if(status != KERN_SUCCESS) + return 0; + + iohidsystem = IORegistryEntryFromPath(masterport, kIOServicePlane ":/IOResources/IOHIDSystem"); + if(!iohidsystem) + return 0; + + status = IOServiceOpen(iohidsystem, mach_task_self(), kIOHIDParamConnectType, &iohandle); + IOObjectRelease(iohidsystem); + + return iohandle; + } +#endif + void IN_ActivateMouse( void ) { if (!mouse_avail || !screen) return; + #ifdef MACOS_X + if (!mouse_active && mouse_avail) // mac os x mouse accel hack + { + // Save the status of mouse acceleration + originalMouseSpeed = -1.0; // in case of error + if(in_disablemacosxmouseaccel->integer) + { + io_connect_t mouseDev = IN_GetIOHandle(); + if(mouseDev != 0) + { + if(IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess) + { + Com_Printf("previous mouse acceleration: %f\n", originalMouseSpeed); + if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess) + { + Com_Printf("Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); + Cvar_Set ("in_disablemacosxmouseaccel", 0); + } + } + else + { + Com_Printf("Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n"); + Cvar_Set ("in_disablemacosxmouseaccel", 0); + } + IOServiceClose(mouseDev); + } + else + { + Com_Printf("Could not disable mouse acceleration (failed at IO_GetIOHandle).\n"); + Cvar_Set ("in_disablemacosxmouseaccel", 0); + } + } + } + #endif + if (!mouse_active) { if (!in_nograb->value) @@ -450,6 +515,25 @@ void IN_DeactivateMouse( void ) { if (!mouse_avail || !screen) return; + + #ifdef MACOS_X + if (mouse_active) // mac os x mouse accel hack + { + if(originalMouseSpeed != -1.0) + { + io_connect_t mouseDev = IN_GetIOHandle(); + if(mouseDev != 0) + { + Com_Printf("restoring mouse acceleration to: %f\n", originalMouseSpeed); + if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess) + Com_Printf("Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); + IOServiceClose(mouseDev); + } + else + Com_Printf("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n"); + } + } + #endif if (mouse_active) { @@ -690,6 +774,13 @@ static int GLW_SetMode( const char *drivername, int mode, qboolean fullscreen ) SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, tstencilbits ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); +#if SDL_VERSION_ATLEAST( 1, 2, 10 ) + if( SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, r_swapInterval->integer ) ) + ri.Printf( PRINT_ALL, "r_swapInterval requires libSDL >= 1.2.10\n" ); +#else + #warning libSDL >= 1.2.10 required for r_swapInterval support +#endif // SDL_GL_SWAP_CONTROL + SDL_WM_SetCaption(CLIENT_WINDOW_TITLE, CLIENT_WINDOW_ICON); SDL_ShowCursor(0); SDL_EnableUNICODE(1); @@ -1291,6 +1382,7 @@ void IN_Init(void) { Com_Printf ("\n------- Input Initialization -------\n"); // mouse variables in_mouse = Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE); + in_disablemacosxmouseaccel = Cvar_Get ("in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE); // turn on-off sub-frame timing of X events in_subframe = Cvar_Get ("in_subframe", "1", CVAR_ARCHIVE); |