mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
tidy up osx mouse acceleration hack a bit more.
git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@602 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
70f452ed47
commit
42d50749e3
1 changed files with 51 additions and 47 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue