From 9dd8339eee82fdb856565d2b4da5eb2b9546fbd9 Mon Sep 17 00:00:00 2001 From: sezero Date: Sat, 7 Jan 2012 09:22:43 +0000 Subject: [PATCH] tidy up osx mouse acceleration hack a bit more. git-svn-id: svn+ssh://svn.code.sf.net/p/quakespasm/code/trunk@602 af15c1b1-3010-417e-b628-4374ebc0bcbd --- quakespasm/Quake/in_sdl.c | 98 ++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/quakespasm/Quake/in_sdl.c b/quakespasm/Quake/in_sdl.c index cbbd9b4b..8663bf2e 100644 --- a/quakespasm/Quake/in_sdl.c +++ b/quakespasm/Quake/in_sdl.c @@ -53,11 +53,6 @@ static int buttonremap[] = /* mouse variables */ cvar_t m_filter = {"m_filter","0",CVAR_NONE}; -#ifdef MACOS_X_ACCELERATION_HACK -static cvar_t in_disablemacosxmouseaccel = {"in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE}; -static double originalMouseSpeed = -1.0; -#endif - /* total accumulated mouse movement since last frame, * gets updated from the main game loop via IN_MouseMove */ static int total_dx, total_dy = 0; @@ -76,12 +71,15 @@ static int FilterMouseEvents (const SDL_Event *event) } #ifdef MACOS_X_ACCELERATION_HACK +static cvar_t in_disablemacosxmouseaccel = {"in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE}; +static double originalMouseSpeed = -1.0; + static io_connect_t IN_GetIOHandle(void) { io_connect_t iohandle = MACH_PORT_NULL; - kern_return_t status; io_service_t iohidsystem = MACH_PORT_NULL; mach_port_t masterport; + kern_return_t status; status = IOMasterPort(MACH_PORT_NULL, &masterport); if (status != KERN_SUCCESS) @@ -96,7 +94,50 @@ static io_connect_t IN_GetIOHandle(void) return iohandle; } -#endif + +static void IN_DisableOSXMouseAccel (void) +{ + io_connect_t mouseDev = IN_GetIOHandle(); + if (mouseDev != 0) + { + if (IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess) + { + if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess) + { + Cvar_Set("in_disablemacosxmouseaccel", "0"); + Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); + } + } + else + { + Cvar_Set("in_disablemacosxmouseaccel", "0"); + Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n"); + } + IOServiceClose(mouseDev); + } + else + { + Cvar_Set("in_disablemacosxmouseaccel", "0"); + Con_Printf("WARNING: Could not disable mouse acceleration (failed at IO_GetIOHandle).\n"); + } +} + +static void IN_ReenableOSXMouseAccel (void) +{ + io_connect_t mouseDev = IN_GetIOHandle(); + if (mouseDev != 0) + { + if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess) + Con_Printf("WARNING: Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); + IOServiceClose(mouseDev); + } + else + { + Con_Printf("WARNING: Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n"); + } + originalMouseSpeed = -1; +} +#endif /* MACOS_X_ACCELERATION_HACK */ void IN_Activate (void) @@ -107,31 +148,7 @@ void IN_Activate (void) #ifdef MACOS_X_ACCELERATION_HACK /* Save the status of mouse acceleration */ if (originalMouseSpeed == -1 && in_disablemacosxmouseaccel.value) - { - io_connect_t mouseDev = IN_GetIOHandle(); - if (mouseDev != 0) - { - if (IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess) - { - if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess) - { - Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); - Cvar_Set ("in_disablemacosxmouseaccel", "0"); - } - } - else - { - Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n"); - Cvar_Set ("in_disablemacosxmouseaccel", "0"); - } - IOServiceClose(mouseDev); - } - else - { - Con_Printf("WARNING: Could not disable mouse acceleration (failed at IO_GetIOHandle).\n"); - Cvar_Set ("in_disablemacosxmouseaccel", "0"); - } - } + IN_DisableOSXMouseAccel(); #endif if (SDL_WM_GrabInput(SDL_GRAB_QUERY) != SDL_GRAB_ON) @@ -161,21 +178,8 @@ void IN_Deactivate (qboolean free_cursor) return; #ifdef MACOS_X_ACCELERATION_HACK - if (originalMouseSpeed != -1.0) - { - io_connect_t mouseDev = IN_GetIOHandle(); - if (mouseDev != 0) - { - if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess) - Con_Printf("WARNING: Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); - IOServiceClose(mouseDev); - } - else - { - Con_Printf("WARNING: Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n"); - } - originalMouseSpeed = -1; - } + if (originalMouseSpeed != -1) + IN_ReenableOSXMouseAccel(); #endif if (free_cursor)