even more mac mouse work!
This commit is contained in:
@@ -3,43 +3,106 @@
|
|||||||
|
|
||||||
using __gnu_cxx::hash_map;
|
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 )
|
bool MouseDevice::AddLogicalDevice( int usagePage, int usage )
|
||||||
{
|
{
|
||||||
// Mice can either be kHIDUsage_GD_Mouse or kHIDUsage_GD_Pointer...
|
if( usagePage != kHIDPage_GenericDesktop )
|
||||||
// Let's just go with kHIDUsage_GD_Mouse for now. -aj
|
return false;
|
||||||
return usagePage == kHIDPage_GenericDesktop && usage == kHIDUsage_GD_Mouse;
|
|
||||||
|
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 )
|
void MouseDevice::AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties )
|
||||||
{
|
{
|
||||||
if( usagePage == kHIDPage_Button )
|
if( usagePage >= kHIDPage_VendorDefinedStart )
|
||||||
{
|
return;
|
||||||
const DeviceButton buttonID = enum_add2( MOUSE_LEFT, usage - kHIDUsage_Button_1 );
|
|
||||||
|
|
||||||
bool mouseWheel = (buttonID == MOUSE_WHEELUP || buttonID == MOUSE_WHEELDOWN);
|
ASSERT(m_Mouse);
|
||||||
if( buttonID <= MOUSE_MIDDLE || mouseWheel )
|
Mouse& m = m_Mouse;
|
||||||
mapping[cookie] = buttonID;
|
|
||||||
else
|
switch( usagePage )
|
||||||
LOG->Warn( "Button id too large: %d.", int(buttonID) );
|
{
|
||||||
break;
|
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()
|
void MouseDevice::Open()
|
||||||
{
|
{
|
||||||
|
//const Mouse& m = m_Mouse;
|
||||||
for( hash_map<IOHIDElementCookie,DeviceButton>::const_iterator i = m_Mapping.begin(); i != m_Mapping.end(); ++i )
|
for( hash_map<IOHIDElementCookie,DeviceButton>::const_iterator i = m_Mapping.begin(); i != m_Mapping.end(); ++i )
|
||||||
{
|
|
||||||
AddElementToQueue( i->first );
|
AddElementToQueue( i->first );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseDevice::GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const
|
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 );
|
hash_map<IOHIDElementCookie, DeviceButton>::const_iterator iter = m_Mapping.find( cookie );
|
||||||
if( iter != m_Mapping.end() )
|
if( iter != m_Mapping.end() )
|
||||||
{
|
|
||||||
vPresses.push_back( DeviceInput(DEVICE_MOUSE, iter->second, value, now) );
|
vPresses.push_back( DeviceInput(DEVICE_MOUSE, iter->second, value, now) );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseDeviceDevice::GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const
|
void MouseDeviceDevice::GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const
|
||||||
|
|||||||
@@ -3,16 +3,31 @@
|
|||||||
|
|
||||||
#include "HIDDevice.h"
|
#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
|
class MouseDevice : public HIDDevice
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
__gnu_cxx::hash_map<IOHIDElementCookie, DeviceButton> m_Mapping;
|
__gnu_cxx::hash_map<IOHIDElementCookie, DeviceButton> m_Mapping;
|
||||||
|
Mouse m_Mouse;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool AddLogicalDevice( int usagePage, int usage );
|
bool AddLogicalDevice( int usagePage, int usage );
|
||||||
void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties )
|
void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties )
|
||||||
void Open()
|
void Open()
|
||||||
|
|
||||||
|
// just in case -aj
|
||||||
|
Mouse GetMouse(){ return m_Mouse; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const;
|
void GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const;
|
||||||
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user