Finish InputHandler_Carbon and use it.
This commit is contained in:
@@ -616,7 +616,7 @@ void InputHandler_Carbon::QueueCallBack( void *target, int result, void *refcon,
|
|||||||
KeyboardDevice *kd = dynamic_cast<KeyboardDevice *>(dev);
|
KeyboardDevice *kd = dynamic_cast<KeyboardDevice *>(dev);
|
||||||
JoystickDevice *jd = dynamic_cast<JoystickDevice *>(dev);
|
JoystickDevice *jd = dynamic_cast<JoystickDevice *>(dev);
|
||||||
|
|
||||||
ASSERT(kd || jd );
|
ASSERT( kd || jd );
|
||||||
|
|
||||||
while( (result = CALL(queue, getNextEvent, &event, zeroTime, 0)) == kIOReturnSuccess )
|
while( (result = CALL(queue, getNextEvent, &event, zeroTime, 0)) == kIOReturnSuccess )
|
||||||
{
|
{
|
||||||
@@ -714,7 +714,43 @@ InputHandler_Carbon::~InputHandler_Carbon()
|
|||||||
mach_port_deallocate( mach_task_self(), mMasterPort );
|
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.
|
// Get a Mach port to initiate communication with I/O Kit.
|
||||||
mach_port_t masterPort;
|
mach_port_t masterPort;
|
||||||
@@ -728,66 +764,54 @@ InputHandler_Carbon::InputHandler_Carbon() : mSem("Input thread started")
|
|||||||
}
|
}
|
||||||
mMasterPort = masterPort;
|
mMasterPort = masterPort;
|
||||||
|
|
||||||
// Build the matching dictionary.
|
// Find the joysticks
|
||||||
CFMutableDictionaryRef dict;
|
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." );
|
// Iterate over the devices and add them
|
||||||
mach_port_deallocate( mach_task_self(), masterPort );
|
io_object_t device;
|
||||||
return;
|
int id = DEVICE_JOY1;
|
||||||
}
|
|
||||||
// Refine the search by only looking for joysticks
|
|
||||||
CFNumberRef usagePage = CFInt( kHIDPage_GenericDesktop );
|
|
||||||
CFNumberRef usage = CFInt( kHIDUsage_GD_Joystick );
|
|
||||||
|
|
||||||
CFDictionarySetValue( dict, CFSTR(kIOHIDPrimaryUsagePageKey), usagePage );
|
while( (device = IOIteratorNext(iter)) )
|
||||||
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<Device *>(jd)->Open(device) )
|
|
||||||
{
|
{
|
||||||
id += jd->AssignJoystickIDs( id );
|
JoystickDevice *jd = new JoystickDevice;
|
||||||
mDevices.push_back( jd );
|
|
||||||
puts( "Added device." );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete jd;
|
|
||||||
}
|
|
||||||
|
|
||||||
IOObjectRelease( device );
|
if( static_cast<Device *>(jd)->Open(device) )
|
||||||
|
{
|
||||||
|
id += jd->AssignJoystickIDs( id );
|
||||||
|
mDevices.push_back( jd );
|
||||||
|
}
|
||||||
|
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.SetName( "Input thread." );
|
||||||
mInputThread.Create(InputHandler_Carbon::Run, this);
|
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 )
|
void InputHandler_Carbon::GetDevicesAndDescriptions( vector<InputDevice>& dev, vector<CString>& desc )
|
||||||
{
|
{
|
||||||
#if 0 // not yet
|
|
||||||
dev.push_back(DEVICE_KEYBOARD);
|
dev.push_back(DEVICE_KEYBOARD);
|
||||||
desc.push_back("Keyboard");
|
desc.push_back("Keyboard");
|
||||||
#endif
|
|
||||||
FOREACH_CONST( Device *, mDevices, i )
|
FOREACH_CONST( Device *, mDevices, i )
|
||||||
{
|
{
|
||||||
const JoystickDevice *jd = dynamic_cast<const JoystickDevice *>(*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.
|
// NOTE: If X11 is available, we don't use LLW_SDL, which IH_SDL depends on.
|
||||||
#if defined(HAVE_X11)
|
#if defined(HAVE_X11)
|
||||||
#include "InputHandler_X11.h"
|
#include "InputHandler_X11.h"
|
||||||
|
#elif defined(HAVE_CARBON)
|
||||||
|
#include "InputHandler_Carbon.h"
|
||||||
#elif defined(HAVE_SDL)
|
#elif defined(HAVE_SDL)
|
||||||
#include "InputHandler_SDL.h"
|
#include "InputHandler_SDL.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -31,29 +31,32 @@ void MakeInputHandlers(CString drivers, vector<InputHandler *> &Add)
|
|||||||
if(!s->CompareNoCase("Joystick") ) ret = new InputHandler_Linux_Joystick;
|
if(!s->CompareNoCase("Joystick") ) ret = new InputHandler_Linux_Joystick;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_INPUT_HANDLER_LINUX_TTY
|
#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
|
#endif
|
||||||
#ifdef USE_INPUT_HANDLER_SDL
|
#ifdef USE_INPUT_HANDLER_SDL
|
||||||
if(!s->CompareNoCase("SDL") ) ret = new InputHandler_SDL;
|
if(!s->CompareNoCase("SDL") ) ret = new InputHandler_SDL;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_INPUT_HANDLER_WIN32_PARA
|
#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
|
#endif
|
||||||
#ifdef USE_INPUT_HANDLER_WIN32_PUMP
|
#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
|
#endif
|
||||||
#ifdef USE_INPUT_HANDLER_WIN32_MIDI
|
#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
|
#endif
|
||||||
#ifdef USE_INPUT_HANDLER_X11
|
#ifdef USE_INPUT_HANDLER_X11
|
||||||
if(!s->CompareNoCase("X11") ) ret = new InputHandler_X11;
|
if(!s->CompareNoCase("X11") ) ret = new InputHandler_X11;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_INPUT_HANDLER_XBOX
|
#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
|
#endif
|
||||||
|
|
||||||
if( ret == NULL )
|
if( ret == NULL )
|
||||||
LOG->Warn( "Unknown lights driver name: %s", s->c_str() );
|
LOG->Warn( "Unknown Input Handler name: %s", s->c_str() );
|
||||||
else
|
else
|
||||||
Add.push_back( ret );
|
Add.push_back( ret );
|
||||||
}
|
}
|
||||||
@@ -267,7 +270,7 @@ RageSoundDriver *MakeRageSoundDriver(CString drivers)
|
|||||||
|
|
||||||
if( ret == NULL )
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
#define DEFAULT_INPUT_DRIVER_LIST "DirectInput,Pump,Para"
|
#define DEFAULT_INPUT_DRIVER_LIST "DirectInput,Pump,Para"
|
||||||
#elif defined(HAVE_X11) // Prefer X11 over SDL
|
#elif defined(HAVE_X11) // Prefer X11 over SDL
|
||||||
#define DEFAULT_INPUT_DRIVER_LIST "X11,Joystick"
|
#define DEFAULT_INPUT_DRIVER_LIST "X11,Joystick"
|
||||||
|
#elif defined(HAVE_CARBON)
|
||||||
|
# define DEFAULT_INPUT_DRIVER_LIST "Carbon"
|
||||||
#elif defined(HAVE_SDL)
|
#elif defined(HAVE_SDL)
|
||||||
#define DEFAULT_INPUT_DRIVER_LIST "SDL"
|
#define DEFAULT_INPUT_DRIVER_LIST "SDL"
|
||||||
#elif defined(LINUX)
|
#elif defined(LINUX)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#define HAVE_MACOSX
|
#define HAVE_MACOSX
|
||||||
#define HAVE_COCOA
|
#define HAVE_COCOA
|
||||||
#define HAVE_COREAUDIO
|
#define HAVE_COREAUDIO
|
||||||
|
#define HAVE_CARBON
|
||||||
#define HAVE_SDL
|
#define HAVE_SDL
|
||||||
#define HAVE_CRYPTOPP
|
#define HAVE_CRYPTOPP
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user