From 8877741c466c938a6d6297b3e83ce4f41731a926 Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 17 May 2007 15:53:57 +0000 Subject: [PATCH] cvar apple_mouse_noaccel (1 default) disables mouse acceleration git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7303 d7cf8633-e32d-0410-b094-e92efae38249 --- makefile.inc | 2 +- snd_coreaudio.c | 32 ++++++++++++++++---------------- vid_agl.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 17 deletions(-) diff --git a/makefile.inc b/makefile.inc index a4052de0..3fe68d42 100644 --- a/makefile.inc +++ b/makefile.inc @@ -196,7 +196,7 @@ LDFLAGS_LINUXSDL=$(LDFLAGS_UNIXCOMMON) -ldl $(LDFLAGS_UNIXSDL) OBJ_MACOSXCD=$(OBJ_NOCD) # Link -LDFLAGS_MACOSXCL=$(LDFLAGS_UNIXCOMMON) -ldl -framework Carbon $(LIB_SOUND) +LDFLAGS_MACOSXCL=$(LDFLAGS_UNIXCOMMON) -ldl -framework IOKit -framework Carbon $(LIB_SOUND) LDFLAGS_MACOSXSV=$(LDFLAGS_UNIXCOMMON) -ldl LDFLAGS_MACOSXSDL=$(LDFLAGS_UNIXCOMMON) -ldl `$(SDL_CONFIG) --static-libs` diff --git a/snd_coreaudio.c b/snd_coreaudio.c index 9d938125..c10789f0 100644 --- a/snd_coreaudio.c +++ b/snd_coreaudio.c @@ -141,23 +141,11 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested) if (suggested != NULL) memcpy (suggested, requested, sizeof (suggested)); - // Get the device status and suggest any appropriate changes to format - propertySize = sizeof(streamDesc); - status = AudioDeviceGetProperty(outputDeviceID, 0, false, kAudioDevicePropertyStreamFormat, &propertySize, &streamDesc); - if (status) - { - Con_Printf("CoreAudio: AudioDeviceGetProperty() returned %d when getting kAudioDevicePropertyStreamFormat\n", status); - return false; - } - // Suggest proper settings if they differ - if (requested->channels != streamDesc.mChannelsPerFrame || requested->speed != streamDesc.mSampleRate || requested->width != streamDesc.mBitsPerChannel/8) + if(requested->width != 2) { - if (suggested != NULL) - { - suggested->channels = streamDesc.mChannelsPerFrame; - suggested->speed = streamDesc.mSampleRate; - suggested->width = streamDesc.mBitsPerChannel/8; - } + // we can only do 16bit per sample for now + if(suggested != NULL) + suggested->width = 2; return false; } @@ -210,6 +198,7 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested) Con_Printf("CoreAudio: AudioDeviceGetProperty() returned %d when getting kAudioDevicePropertyStreamFormat\n", status); return false; } + Con_DPrint (" Hardware format:\n"); Con_DPrintf(" %5d mSampleRate\n", (unsigned int)streamDesc.mSampleRate); Con_DPrintf(" %c%c%c%c mFormatID\n", @@ -223,6 +212,17 @@ qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested) Con_DPrintf(" %5d mChannelsPerFrame\n", streamDesc.mChannelsPerFrame); Con_DPrintf(" %5d mBitsPerChannel\n", streamDesc.mBitsPerChannel); + // Suggest proper settings if they differ + if (requested->channels != streamDesc.mChannelsPerFrame || requested->speed != streamDesc.mSampleRate) + { + if (suggested != NULL) + { + suggested->channels = streamDesc.mChannelsPerFrame; + suggested->speed = streamDesc.mSampleRate; + } + return false; + } + if(streamDesc.mFormatID != kAudioFormatLinearPCM) { Con_Print("CoreAudio: Default audio device doesn't support linear PCM!\n"); diff --git a/vid_agl.c b/vid_agl.c index ce775d95..8b24ade8 100644 --- a/vid_agl.c +++ b/vid_agl.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "vid_agl_mackeys.h" // this is SDL/src/video/maccommon/SDL_mackeys.h #include "quakedef.h" @@ -67,10 +69,12 @@ static qboolean sound_active = true; static int scr_width, scr_height; static cvar_t apple_multithreadedgl = {CVAR_SAVE, "apple_multithreadedgl", "1", "makes use of a second thread for the OpenGL driver (if possible) rather than using the engine thread (note: this is done automatically on most other operating systems)"}; +static cvar_t apple_mouse_noaccel = {CVAR_SAVE, "apple_mouse_noaccel", "1", "disables mouse acceleration while DarkPlaces is active"}; static AGLContext context; static WindowRef window; +static double originalMouseSpeed = 0.0; void VID_GetWindowSize (int *x, int *y, int *width, int *height) { @@ -100,6 +104,35 @@ static void IN_Activate( qboolean grab ) // Lock the mouse pointer at its current position CGAssociateMouseAndMouseCursorPosition(false); + // Save the status of mouse acceleration + originalMouseSpeed = 0.0; // in case of error + if(apple_mouse_noaccel.integer) + { + NXEventHandle mouseDev = NXOpenEventStatus(); + if(mouseDev != 0) + { + if(IOHIDGetMouseAcceleration((io_connect_t) mouseDev, &originalMouseSpeed) == kIOReturnSuccess) + { + if(IOHIDSetMouseAcceleration((io_connect_t) mouseDev, 0.0) != kIOReturnSuccess) + { + Con_Print("Could not disable mouse acceleration (failed at IOHIDSetMouseAcceleration).\n"); + Cvar_SetValueQuick(&apple_mouse_noaccel, 0); + } + } + else + { + Con_Print("Could not disable mouse acceleration (failed at IOHIDGetMouseAcceleration).\n"); + Cvar_SetValueQuick(&apple_mouse_noaccel, 0); + } + NXCloseEventStatus(mouseDev); + } + else + { + Con_Print("Could not disable mouse acceleration (failed at NXOpenEventStatus).\n"); + Cvar_SetValueQuick(&apple_mouse_noaccel, 0); + } + } + mouse_x = mouse_y = 0; vid_usingmouse = true; } @@ -108,6 +141,19 @@ static void IN_Activate( qboolean grab ) { if (vid_usingmouse) { + if(originalMouseSpeed != 0.0) + { + NXEventHandle mouseDev = NXOpenEventStatus(); + if(mouseDev != 0) + { + if(IOHIDSetMouseAcceleration((io_connect_t) mouseDev, originalMouseSpeed) != kIOReturnSuccess) + Con_Print("Could not re-enable mouse acceleration (failed at IOHIDSetMouseAcceleration).\n"); + NXCloseEventStatus(mouseDev); + } + else + Con_Print("Could not re-enable mouse acceleration (failed at NXOpenEventStatus).\n"); + } + CGAssociateMouseAndMouseCursorPosition(true); CGDisplayShowCursor(CGMainDisplayID()); @@ -275,6 +321,7 @@ void VID_Init(void) { InitSig(); // trap evil signals Cvar_RegisterVariable(&apple_multithreadedgl); + Cvar_RegisterVariable(&apple_mouse_noaccel); // COMMANDLINEOPTION: Input: -nomouse disables mouse support (see also vid_mouse cvar) if (COM_CheckParm ("-nomouse")) mouse_avail = false; -- 2.39.2