Finish InputHandler_Carbon and use it.
This commit is contained in:
@@ -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,41 +764,11 @@ InputHandler_Carbon::InputHandler_Carbon() : mSem("Input thread started")
|
||||
}
|
||||
mMasterPort = masterPort;
|
||||
|
||||
// Build the matching dictionary.
|
||||
CFMutableDictionaryRef dict;
|
||||
// Find the joysticks
|
||||
io_iterator_t iter = GetDeviceIterator(masterPort, kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick );
|
||||
|
||||
if( (dict = IOServiceMatching(kIOHIDDeviceKey)) == NULL )
|
||||
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 );
|
||||
|
||||
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;
|
||||
@@ -775,7 +781,6 @@ InputHandler_Carbon::InputHandler_Carbon() : mSem("Input thread started")
|
||||
{
|
||||
id += jd->AssignJoystickIDs( id );
|
||||
mDevices.push_back( jd );
|
||||
puts( "Added device." );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -786,8 +791,27 @@ InputHandler_Carbon::InputHandler_Carbon() : mSem("Input thread started")
|
||||
|
||||
}
|
||||
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<InputDevice>& dev, vector<CString>& 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<const JoystickDevice *>(*i);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -51,9 +51,12 @@ void MakeInputHandlers(CString drivers, vector<InputHandler *> &Add)
|
||||
#ifdef USE_INPUT_HANDLER_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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define HAVE_MACOSX
|
||||
#define HAVE_COCOA
|
||||
#define HAVE_COREAUDIO
|
||||
#define HAVE_CARBON
|
||||
#define HAVE_SDL
|
||||
#define HAVE_CRYPTOPP
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user