/* =============== IN_DeactivateMouse =============== */ void IN_DeactivateMouse( void ) { if ( !SDL_WasInit( SDL_INIT_VIDEO ) ) { return; } // Always show the cursor when the mouse is disabled, // but not when fullscreen if ( !Cvar_VariableIntegerValue( "r_fullscreen" ) ) { SDL_ShowCursor( 1 ); } if ( !mouseAvailable ) { return; } #ifdef MACOS_X_ACCELERATION_HACK if ( mouseActive ) // mac os x mouse accel hack { if ( originalMouseSpeed != -1.0 ) { io_connect_t mouseDev = IN_GetIOHandle(); if ( mouseDev != 0 ) { Com_DPrintf( "restoring mouse acceleration to: %f\n", originalMouseSpeed ); if ( IOHIDSetAccelerationWithKey( mouseDev, CFSTR( kIOHIDMouseAccelerationType ), originalMouseSpeed ) != kIOReturnSuccess ) { Com_DPrintf( "Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n" ); } IOServiceClose( mouseDev ); } else { Com_DPrintf( "Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n" ); } } } #endif if ( mouseActive ) { IN_GobbleMotionEvents(); SDL_WM_GrabInput( SDL_GRAB_OFF ); // Don't warp the mouse unless the cursor is within the window //if( SDL_GetAppState( ) & SDL_APPMOUSEFOCUS ) //SDL_WarpMouse( cls.glconfig.vidWidth / 2, cls.glconfig.vidHeight / 2 ); mouseActive = qfalse; } }
/* =============== IN_DeactivateMouse =============== */ void IN_DeactivateMouse( void ) { if( !SDL_WasInit( SDL_INIT_VIDEO ) ) return; // Always show the cursor when the mouse is disabled, // but not when fullscreen if( !r_fullscreen->integer ) { if( ( Key_GetCatcher( ) == KEYCATCH_UI ) && ( SDL_GetAppState( ) & (SDL_APPMOUSEFOCUS|SDL_APPINPUTFOCUS) ) == (SDL_APPMOUSEFOCUS|SDL_APPINPUTFOCUS) ) SDL_ShowCursor( 0 ); else SDL_ShowCursor( 1 ); } if( !mouseAvailable ) return; #ifdef MACOS_X_ACCELERATION_HACK if (mouseActive) // mac os x mouse accel hack { if(originalMouseSpeed != -1.0) { io_connect_t mouseDev = IN_GetIOHandle(); if(mouseDev != 0) { Com_Printf("restoring mouse acceleration to: %f\n", originalMouseSpeed); if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess) Com_Printf("Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); IOServiceClose(mouseDev); } else Com_Printf("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n"); } } #endif if( mouseActive ) { IN_GobbleMotionEvents( ); SDL_WM_GrabInput( SDL_GRAB_OFF ); // Don't warp the mouse unless the cursor is within the window if( SDL_GetAppState( ) & SDL_APPMOUSEFOCUS ) { int x, y; x = glConfig.vidWidth / 2, y = glConfig.vidHeight / 2; SDL_WarpMouse( x, y ); } mouseActive = qfalse; } }
/* =============== IN_DeactivateMouse =============== */ static void IN_DeactivateMouse( void ) { if( !SDL_WasInit( SDL_INIT_VIDEO ) ) return; // Always show the cursor when the mouse is disabled, // but not when fullscreen if( !Cvar_VariableIntegerValue("r_fullscreen") ) SDL_ShowCursor( 1 ); if( !mouseAvailable ) return; #ifdef MACOS_X_ACCELERATION_HACK if (mouseActive) // mac os x mouse accel hack { if(originalMouseSpeed != -1.0) { io_connect_t mouseDev = IN_GetIOHandle(); if(mouseDev != 0) { Com_Printf("restoring mouse acceleration to: %f\n", originalMouseSpeed); if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess) Com_Printf("Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); IOServiceClose(mouseDev); } else Com_Printf("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n"); } } #endif if( mouseActive ) { IN_GobbleMotionEvents( ); SDL_WM_GrabInput( SDL_GRAB_OFF ); mouseActive = qfalse; } }
/* =============== IN_ActivateMouse =============== */ static void IN_ActivateMouse( void ) { if (!mouseAvailable || !SDL_WasInit( SDL_INIT_VIDEO ) ) return; #ifdef MACOS_X_ACCELERATION_HACK if (!mouseActive) // mac os x mouse accel hack { // Save the status of mouse acceleration originalMouseSpeed = -1.0; // in case of error if(in_disablemacosxmouseaccel->integer) { io_connect_t mouseDev = IN_GetIOHandle(); if(mouseDev != 0) { if(IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess) { Com_Printf("previous mouse acceleration: %f\n", originalMouseSpeed); if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess) { Com_Printf("Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); Cvar_Set ("in_disablemacosxmouseaccel", 0); } } else { Com_Printf("Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n"); Cvar_Set ("in_disablemacosxmouseaccel", 0); } IOServiceClose(mouseDev); } else { Com_Printf("Could not disable mouse acceleration (failed at IO_GetIOHandle).\n"); Cvar_Set ("in_disablemacosxmouseaccel", 0); } } } #endif if( !mouseActive ) { SDL_ShowCursor( 0 ); #ifdef MACOS_X_CURSOR_HACK // This is a bug in the current SDL/macosx...have to toggle it a few // times to get the cursor to hide. SDL_ShowCursor( 1 ); SDL_ShowCursor( 0 ); #endif SDL_WM_GrabInput( SDL_GRAB_ON ); IN_GobbleMotionEvents( ); } // in_nograb makes no sense in fullscreen mode if( !Cvar_VariableIntegerValue("r_fullscreen") ) { if( in_nograb->modified || !mouseActive ) { if( in_nograb->integer ) SDL_WM_GrabInput( SDL_GRAB_OFF ); else SDL_WM_GrabInput( SDL_GRAB_ON ); in_nograb->modified = qfalse; } } mouseActive = qtrue; }
void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor) { if (!mouse_avail || !window) relative = hidecursor = false; if (relative) { if(vid_usingmouse && (vid_usingnoaccel != !!apple_mouse_noaccel.integer)) VID_SetMouse(false, false, false); // ungrab first! if (!vid_usingmouse) { Rect winBounds; CGPoint winCenter; SelectWindow(window); // Put the mouse cursor at the center of the window GetWindowBounds (window, kWindowContentRgn, &winBounds); winCenter.x = (winBounds.left + winBounds.right) / 2; winCenter.y = (winBounds.top + winBounds.bottom) / 2; CGWarpMouseCursorPosition(winCenter); // Lock the mouse pointer at its current position CGAssociateMouseAndMouseCursorPosition(false); // Save the status of mouse acceleration originalMouseSpeed = -1.0; // in case of error if(apple_mouse_noaccel.integer) { io_connect_t mouseDev = IN_GetIOHandle(); if(mouseDev != 0) { if(IOHIDGetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), &originalMouseSpeed) == kIOReturnSuccess) { Con_DPrintf("previous mouse acceleration: %f\n", originalMouseSpeed); if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), -1.0) != kIOReturnSuccess) { Con_Print("Could not disable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); Cvar_SetValueQuick(&apple_mouse_noaccel, 0); } } else { Con_Print("Could not disable mouse acceleration (failed at IOHIDGetAccelerationWithKey).\n"); Cvar_SetValueQuick(&apple_mouse_noaccel, 0); } IOServiceClose(mouseDev); } else { Con_Print("Could not disable mouse acceleration (failed at IO_GetIOHandle).\n"); Cvar_SetValueQuick(&apple_mouse_noaccel, 0); } } vid_usingmouse = true; vid_usingnoaccel = !!apple_mouse_noaccel.integer; } } else { if (vid_usingmouse) { if(originalMouseSpeed != -1.0) { io_connect_t mouseDev = IN_GetIOHandle(); if(mouseDev != 0) { Con_DPrintf("restoring mouse acceleration to: %f\n", originalMouseSpeed); if(IOHIDSetAccelerationWithKey(mouseDev, CFSTR(kIOHIDMouseAccelerationType), originalMouseSpeed) != kIOReturnSuccess) Con_Print("Could not re-enable mouse acceleration (failed at IOHIDSetAccelerationWithKey).\n"); IOServiceClose(mouseDev); } else Con_Print("Could not re-enable mouse acceleration (failed at IO_GetIOHandle).\n"); } CGAssociateMouseAndMouseCursorPosition(true); vid_usingmouse = false; } } if (vid_usinghidecursor != hidecursor) { vid_usinghidecursor = hidecursor; if (hidecursor) CGDisplayHideCursor(CGMainDisplayID()); else CGDisplayShowCursor(CGMainDisplayID()); } }