]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
cvar apple_mouse_noaccel (1 default) disables mouse acceleration
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 17 May 2007 15:53:57 +0000 (15:53 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 17 May 2007 15:53:57 +0000 (15:53 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7303 d7cf8633-e32d-0410-b094-e92efae38249

makefile.inc
snd_coreaudio.c
vid_agl.c

index a4052de0689dc50b87647661555eb8d949767e68..3fe68d427b365b997057f6893d04435991ef024c 100644 (file)
@@ -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`
 
index 9d9381253fdc42aa52f5d69023722a391ec4876d..c10789f0173ef48058d7f6fb9a2946c4c47210cb 100644 (file)
@@ -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");
index ce775d95d37a380c0b4029279c13fb6e52c92ac6..8b24ade88b02bb026048e50348f3ca240ff0bd37 100644 (file)
--- a/vid_agl.c
+++ b/vid_agl.c
@@ -26,6 +26,8 @@
 #include <AGL/agl.h>
 #include <OpenGL/OpenGL.h>
 #include <Carbon/Carbon.h>
+#include <IOKit/hidsystem/IOHIDLib.h>
+#include <IOKit/hidsystem/event_status_driver.h>
 #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;