diff --git a/stepmania/src/arch/InputHandler/InputHandler_Carbon.cpp b/stepmania/src/arch/InputHandler/InputHandler_Carbon.cpp index 7b4f60071b..0e6064a486 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Carbon.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_Carbon.cpp @@ -616,7 +616,7 @@ void InputHandler_Carbon::QueueCallBack( void *target, int result, void *refcon, KeyboardDevice *kd = dynamic_cast(dev); JoystickDevice *jd = dynamic_cast(dev); - ASSERT(kd || jd ); + ASSERT( kd || jd ); while( (result = CALL(queue, getNextEvent, &event, zeroTime, 0)) == kIOReturnSuccess ) { @@ -714,7 +714,43 @@ InputHandler_Carbon::~InputHandler_Carbon() mach_port_deallocate( mach_task_self(), mMasterPort ); } -InputHandler_Carbon::InputHandler_Carbon() : mSem("Input thread started") +static io_iterator_t GetDeviceIterator( mach_port_t mp, int usagePage, int usage ) +{ + // Build the matching dictionary. + CFMutableDictionaryRef dict; + + if( (dict = IOServiceMatching(kIOHIDDeviceKey)) == NULL ) + { + LOG->Warn( "Couldn't create a matching dictionary." ); + return NULL; + } + // Refine the search by only looking for joysticks + CFNumberRef usagePageRef = CFInt( usagePage ); + CFNumberRef usageRef = CFInt( usage ); + + CFDictionarySetValue( dict, CFSTR(kIOHIDPrimaryUsagePageKey), usagePageRef ); + CFDictionarySetValue( dict, CFSTR(kIOHIDPrimaryUsageKey), usageRef ); + + // Cleanup after ourselves + CFRelease( usagePageRef ); + CFRelease( usageRef ); + + // Find the HID devices. + io_iterator_t iter; + + /* Get an iterator to the matching devies + * This consumes a reference to the dictionary so we should retain it + * have to Release() later. + */ + if( IOServiceGetMatchingServices(mp, dict, &iter) != kIOReturnSuccess ) + { + LOG->Warn( "Couldn't get matching services" ); + return NULL; + } + return iter; +} + +InputHandler_Carbon::InputHandler_Carbon() : mMasterPort(0), mSem("Input thread started") { // Get a Mach port to initiate communication with I/O Kit. mach_port_t masterPort; @@ -728,66 +764,54 @@ InputHandler_Carbon::InputHandler_Carbon() : mSem("Input thread started") } mMasterPort = masterPort; - // Build the matching dictionary. - CFMutableDictionaryRef dict; - - if( (dict = IOServiceMatching(kIOHIDDeviceKey)) == NULL ) + // Find the joysticks + io_iterator_t iter = GetDeviceIterator(masterPort, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick ); + + if( iter ) { - LOG->Warn( "Couldn't create a matching dictionary." ); - mach_port_deallocate( mach_task_self(), masterPort ); - return; - } - // Refine the search by only looking for joysticks - CFNumberRef usagePage = CFInt( kHIDPage_GenericDesktop ); - CFNumberRef usage = CFInt( kHIDUsage_GD_Joystick ); + // Iterate over the devices and add them + io_object_t device; + int id = DEVICE_JOY1; + + while( (device = IOIteratorNext(iter)) ) + { + JoystickDevice *jd = new JoystickDevice; + + if( static_cast(jd)->Open(device) ) + { + id += jd->AssignJoystickIDs( id ); + mDevices.push_back( jd ); + } + else + { + delete jd; + } + + IOObjectRelease( device ); - CFDictionarySetValue( dict, CFSTR(kIOHIDPrimaryUsagePageKey), usagePage ); - CFDictionarySetValue( dict, CFSTR(kIOHIDPrimaryUsageKey), usage); - - // Cleanup after ourselves - CFRelease(usagePage); - CFRelease(usage); - - // Find the HID devices. - io_iterator_t iter; - - /* Get an iterator to the matching devies - * This consumes a reference to the dictionary so we don't - * have to Release() later. - */ - ret = IOServiceGetMatchingServices( masterPort, dict, &iter ); - if( (ret != kIOReturnSuccess) || !iter ) - { - mach_port_deallocate( mach_task_self(), masterPort ); - masterPort = 0; - return; - } - - // Iterate over the devices and add them - io_object_t device; - int id = DEVICE_JOY1; - - while( (device = IOIteratorNext(iter)) ) - { - JoystickDevice *jd = new JoystickDevice; - - if( static_cast(jd)->Open(device) ) - { - id += jd->AssignJoystickIDs( id ); - mDevices.push_back( jd ); - puts( "Added device." ); } - else - { - delete jd; - } - - IOObjectRelease( device ); - + IOObjectRelease( iter ); } - IOObjectRelease( iter ); + // Now find the keyboards + iter = GetDeviceIterator( masterPort, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard ); - // XXX now find the keyboards + if( iter ) + { + io_object_t device; + + while( (device = IOIteratorNext(iter)) ) + { + Device *kd = new KeyboardDevice; + + if( kd->Open(device) ) + mDevices.push_back( kd ); + else + delete kd; + + IOObjectRelease( device ); + } + IOObjectRelease( iter ); + } mInputThread.SetName( "Input thread." ); mInputThread.Create(InputHandler_Carbon::Run, this); @@ -797,10 +821,9 @@ InputHandler_Carbon::InputHandler_Carbon() : mSem("Input thread started") void InputHandler_Carbon::GetDevicesAndDescriptions( vector& dev, vector& desc ) { -#if 0 // not yet dev.push_back(DEVICE_KEYBOARD); desc.push_back("Keyboard"); -#endif + FOREACH_CONST( Device *, mDevices, i ) { const JoystickDevice *jd = dynamic_cast(*i); diff --git a/stepmania/src/arch/InputHandler/Selector_InputHandler.h b/stepmania/src/arch/InputHandler/Selector_InputHandler.h index 921e9ad588..8c78ba6b12 100644 --- a/stepmania/src/arch/InputHandler/Selector_InputHandler.h +++ b/stepmania/src/arch/InputHandler/Selector_InputHandler.h @@ -19,6 +19,8 @@ // NOTE: If X11 is available, we don't use LLW_SDL, which IH_SDL depends on. #if defined(HAVE_X11) #include "InputHandler_X11.h" +#elif defined(HAVE_CARBON) +#include "InputHandler_Carbon.h" #elif defined(HAVE_SDL) #include "InputHandler_SDL.h" #endif diff --git a/stepmania/src/arch/arch.cpp b/stepmania/src/arch/arch.cpp index 8999dbcdae..ad433abbe2 100644 --- a/stepmania/src/arch/arch.cpp +++ b/stepmania/src/arch/arch.cpp @@ -31,29 +31,32 @@ void MakeInputHandlers(CString drivers, vector &Add) if(!s->CompareNoCase("Joystick") ) ret = new InputHandler_Linux_Joystick; #endif #ifdef USE_INPUT_HANDLER_LINUX_TTY - if(!s->CompareNoCase("tty") ) ret = new InputHandler_Linux_tty; + if(!s->CompareNoCase("tty") ) ret = new InputHandler_Linux_tty; #endif #ifdef USE_INPUT_HANDLER_SDL - if(!s->CompareNoCase("SDL") ) ret = new InputHandler_SDL; + if(!s->CompareNoCase("SDL") ) ret = new InputHandler_SDL; #endif #ifdef USE_INPUT_HANDLER_WIN32_PARA - if(!s->CompareNoCase("Para") ) ret = new InputHandler_Win32_Para; + if(!s->CompareNoCase("Para") ) ret = new InputHandler_Win32_Para; #endif #ifdef USE_INPUT_HANDLER_WIN32_PUMP - if(!s->CompareNoCase("Pump") ) ret = new InputHandler_Win32_Pump; + if(!s->CompareNoCase("Pump") ) ret = new InputHandler_Win32_Pump; #endif #ifdef USE_INPUT_HANDLER_WIN32_MIDI - if(!s->CompareNoCase("MIDI") ) ret = new InputHandler_Win32_MIDI; + if(!s->CompareNoCase("MIDI") ) ret = new InputHandler_Win32_MIDI; #endif #ifdef USE_INPUT_HANDLER_X11 - if(!s->CompareNoCase("X11") ) ret = new InputHandler_X11; + if(!s->CompareNoCase("X11") ) ret = new InputHandler_X11; #endif #ifdef USE_INPUT_HANDLER_XBOX - if(!s->CompareNoCase("Xbox") ) ret = new InputHandler_Xbox; + if(!s->CompareNoCase("Xbox") ) ret = new InputHandler_Xbox; +#endif +#ifdef USE_INPUT_HANDLER_CARBON + if(!s->CompareNoCase("Carbon") ) ret = new InputHandler_Carbon; #endif if( ret == NULL ) - LOG->Warn( "Unknown lights driver name: %s", s->c_str() ); + LOG->Warn( "Unknown Input Handler name: %s", s->c_str() ); else Add.push_back( ret ); } @@ -267,7 +270,7 @@ RageSoundDriver *MakeRageSoundDriver(CString drivers) if( ret == NULL ) { - LOG->Warn( "Unknown sound driver name: %s", DriversToTry[i].c_str() ); + LOG->Trace( "Unknown sound driver name: %s", DriversToTry[i].c_str() ); continue; } diff --git a/stepmania/src/arch/arch_default.h b/stepmania/src/arch/arch_default.h index 38abaa199c..a2b4b02a48 100644 --- a/stepmania/src/arch/arch_default.h +++ b/stepmania/src/arch/arch_default.h @@ -15,6 +15,8 @@ #define DEFAULT_INPUT_DRIVER_LIST "DirectInput,Pump,Para" #elif defined(HAVE_X11) // Prefer X11 over SDL #define DEFAULT_INPUT_DRIVER_LIST "X11,Joystick" +#elif defined(HAVE_CARBON) +# define DEFAULT_INPUT_DRIVER_LIST "Carbon" #elif defined(HAVE_SDL) #define DEFAULT_INPUT_DRIVER_LIST "SDL" #elif defined(LINUX) diff --git a/stepmania/src/arch/arch_platform.h b/stepmania/src/arch/arch_platform.h index 66b7cdc74e..312101a0cf 100644 --- a/stepmania/src/arch/arch_platform.h +++ b/stepmania/src/arch/arch_platform.h @@ -10,6 +10,7 @@ #define HAVE_MACOSX #define HAVE_COCOA #define HAVE_COREAUDIO +#define HAVE_CARBON #define HAVE_SDL #define HAVE_CRYPTOPP #endif