Skip to content

Commit

Permalink
in_sdl.c: replace uses of deprecated IOHID{Get|Set}AccelerationWithKey
Browse files Browse the repository at this point in the history
Thanks to a tip found at: https://stackoverflow.com/questions/49679753

Fixes deprecation warnings from Apple compiler:

in_sdl.c:167:7: 'IOHIDGetAccelerationWithKey' is deprecated: first deprecated in macOS 10.12 [-Wdeprecated-declarations]
                if (IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess)
                    ^
in_sdl.c:169:8: 'IOHIDSetAccelerationWithKey' is deprecated: first deprecated in macOS 10.12 [-Wdeprecated-declarations]
                        if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess)
                            ^
in_sdl.c:194:7: 'IOHIDSetAccelerationWithKey' is deprecated: first deprecated in macOS 10.12 [-Wdeprecated-declarations]
                if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess)
                    ^
  • Loading branch information
sezero committed Aug 18, 2023
1 parent 48f94dd commit ec0f9f4
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static void IN_EndIgnoringMouseEvents(void)

#ifdef MACOS_X_ACCELERATION_HACK
static cvar_t in_disablemacosxmouseaccel = {"in_disablemacosxmouseaccel", "1", CVAR_ARCHIVE};
static double originalMouseSpeed = -1.0;
static unsigned int originalMouseSpeed = (unsigned int) (-65536);

static io_connect_t IN_GetIOHandle(void)
{
Expand Down Expand Up @@ -164,18 +164,20 @@ static void IN_DisableOSXMouseAccel (void)
io_connect_t mouseDev = IN_GetIOHandle();
if (mouseDev != 0)
{
if (IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess)
IOByteCount size;
if (IOHIDGetParameter(mouseDev, CFSTR(kIOHIDMouseAccelerationType), sizeof(originalMouseSpeed), &originalMouseSpeed, &size) == kIOReturnSuccess)
{
if (IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess)
unsigned int noaccel = (unsigned) (-65536);
if (IOHIDSetParameter(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &noaccel, sizeof(noaccel)) != kIOReturnSuccess)
{
Cvar_Set("in_disablemacosxmouseaccel", "0");
Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n");
Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDSetParameter).\n");
}
}
else
{
Cvar_Set("in_disablemacosxmouseaccel", "0");
Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n");
Con_Printf("WARNING: Could not disable mouse acceleration (failed at IOHIDGetParameter).\n");
}
IOServiceClose(mouseDev);
}
Expand All @@ -191,15 +193,15 @@ 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");
if (IOHIDSetParameter(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed, sizeof(originalMouseSpeed)) != kIOReturnSuccess)
Con_Printf("WARNING: Could not re-enable mouse acceleration (failed at IOHIDSetParameter).\n");
IOServiceClose(mouseDev);
}
else
{
Con_Printf("WARNING: Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n");
}
originalMouseSpeed = -1;
originalMouseSpeed = (unsigned)(-65536);
}
#endif /* MACOS_X_ACCELERATION_HACK */

Expand All @@ -211,7 +213,7 @@ void IN_Activate (void)

#ifdef MACOS_X_ACCELERATION_HACK
/* Save the status of mouse acceleration */
if (originalMouseSpeed == -1 && in_disablemacosxmouseaccel.value)
if (originalMouseSpeed == (unsigned)(-65536) && in_disablemacosxmouseaccel.value)
IN_DisableOSXMouseAccel();
#endif

Expand Down Expand Up @@ -257,7 +259,7 @@ void IN_Deactivate (qboolean free_cursor)
return;

#ifdef MACOS_X_ACCELERATION_HACK
if (originalMouseSpeed != -1)
if (originalMouseSpeed != (unsigned)(-65536))
IN_ReenableOSXMouseAccel();
#endif

Expand Down

0 comments on commit ec0f9f4

Please sign in to comment.