From a6826bc999cc3758084a2f218c4c303ffed8d12b Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Wed, 23 Feb 2011 19:15:21 -0600 Subject: [PATCH] even more mac mouse work! --- src/archutils/Darwin/MouseDevice.cpp | 95 +++++++++++++++++++++++----- src/archutils/Darwin/MouseDevice.h | 15 +++++ 2 files changed, 94 insertions(+), 16 deletions(-) diff --git a/src/archutils/Darwin/MouseDevice.cpp b/src/archutils/Darwin/MouseDevice.cpp index 86156db315..6ccb7c4c8a 100644 --- a/src/archutils/Darwin/MouseDevice.cpp +++ b/src/archutils/Darwin/MouseDevice.cpp @@ -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::const_iterator i = m_Mapping.begin(); i != m_Mapping.end(); ++i ) - { AddElementToQueue( i->first ); - } } void MouseDevice::GetButtonPresses( vector& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const { + // todo: add mouse axis stuff -aj hash_map::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& vDevices ) const diff --git a/src/archutils/Darwin/MouseDevice.h b/src/archutils/Darwin/MouseDevice.h index 9d3e2565ca..f1c5406a45 100644 --- a/src/archutils/Darwin/MouseDevice.h +++ b/src/archutils/Darwin/MouseDevice.h @@ -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 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& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const; void GetDevicesAndDescriptions( vector& vDevices ) const;