even more mac mouse work!

This commit is contained in:
AJ Kelly
2011-02-23 19:15:21 -06:00
parent c6e641df29
commit a6826bc999
2 changed files with 94 additions and 16 deletions
+79 -16
View File
@@ -3,43 +3,106 @@
using __gnu_cxx::hash_map;
/*
Mouse::Mouse() : id( InputDevice_Invalid ),
x_axis( 0 ), x_min( 0 ), x_max( 0 ),
y_axis( 0 ), y_min( 0 ), y_max( 0 ),
z_axis( 0 ), z_min( 0 ), z_max( 0 )
{
}
*/
bool MouseDevice::AddLogicalDevice( int usagePage, int usage )
{
// Mice can either be kHIDUsage_GD_Mouse or kHIDUsage_GD_Pointer...
// Let's just go with kHIDUsage_GD_Mouse for now. -aj
return usagePage == kHIDPage_GenericDesktop && usage == kHIDUsage_GD_Mouse;
if( usagePage != kHIDPage_GenericDesktop )
return false;
switch( usage )
{
// Mice can either be kHIDUsage_GD_Mouse or kHIDUsage_GD_Pointer...
// Let's just go with kHIDUsage_GD_Mouse for now. -aj
case kHIDUsage_GD_Mouse:
//case kHIDUsage_GD_Pointer:
break;
default:
return false;
}
// Init only a single mouse for now.
Mouse();
return true;
}
void MouseDevice::AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties )
{
if( usagePage == kHIDPage_Button )
{
const DeviceButton buttonID = enum_add2( MOUSE_LEFT, usage - kHIDUsage_Button_1 );
if( usagePage >= kHIDPage_VendorDefinedStart )
return;
bool mouseWheel = (buttonID == MOUSE_WHEELUP || buttonID == MOUSE_WHEELDOWN);
if( buttonID <= MOUSE_MIDDLE || mouseWheel )
mapping[cookie] = buttonID;
else
LOG->Warn( "Button id too large: %d.", int(buttonID) );
break;
ASSERT(m_Mouse);
Mouse& m = m_Mouse;
switch( usagePage )
{
case kHIDPage_GenericDesktop:
int iMin = 0;
IntValue( CFDictionaryGetValue(properties, CFSTR(kIOHIDElementMinKey)), iMin );
int iMax = 0;
IntValue( CFDictionaryGetValue(properties, CFSTR(kIOHIDElementMaxKey)), iMax );
// based on usage
switch( usage )
{
case kHIDUsage_GD_X:
m.x_axis = cookie;
m.x_min = iMin;
m.x_max = iMax;
break;
case kHIDUsage_GD_Y:
m.y_axis = cookie;
m.y_min = iMin;
m.y_max = iMax;
break;
case kHIDUsage_GD_Z:
m.z_axis = cookie;
m.z_min = iMin;
m.z_max = iMax;
break;
default:
//LOG->Warn( "Unknown usagePage usage pair: (kHIDPage_GenericDesktop, %d).", usage );
break;
}
break;
case kHIDPage_Button:
{
const DeviceButton buttonID = enum_add2( MOUSE_LEFT, usage - kHIDUsage_Button_1 );
bool mouseWheel = (buttonID == MOUSE_WHEELUP || buttonID == MOUSE_WHEELDOWN);
if( buttonID <= MOUSE_MIDDLE )
mapping[cookie] = buttonID;
else
LOG->Warn( "Button id too large: %d.", int(buttonID) );
break;
}
break;
default:
//LOG->Warn( "Unknown usagePage usage pair: (%d, %d).", usagePage, usage );
break;
}
}
void MouseDevice::Open()
{
//const Mouse& m = m_Mouse;
for( hash_map<IOHIDElementCookie,DeviceButton>::const_iterator i = m_Mapping.begin(); i != m_Mapping.end(); ++i )
{
AddElementToQueue( i->first );
}
}
void MouseDevice::GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const
{
// todo: add mouse axis stuff -aj
hash_map<IOHIDElementCookie, DeviceButton>::const_iterator iter = m_Mapping.find( cookie );
if( iter != m_Mapping.end() )
{
vPresses.push_back( DeviceInput(DEVICE_MOUSE, iter->second, value, now) );
}
}
void MouseDeviceDevice::GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const
+15
View File
@@ -3,16 +3,31 @@
#include "HIDDevice.h"
struct Mouse
{
InputDevice id;
IOHIDElementCookie x_axis, y_axis, z_axis;
int x_min, x_max;
int y_min, y_max;
int z_min, z_max;
Mouse();
};
class MouseDevice : public HIDDevice
{
private:
__gnu_cxx::hash_map<IOHIDElementCookie, DeviceButton> m_Mapping;
Mouse m_Mouse;
protected:
bool AddLogicalDevice( int usagePage, int usage );
void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties )
void Open()
// just in case -aj
Mouse GetMouse(){ return m_Mouse; }
public:
void GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const;
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;