Create JoystickDevices for HID game pads (untested).
This commit is contained in:
@@ -152,86 +152,76 @@ static CFDictionaryRef GetMatchingDictionary( int usagePage, int usage )
|
|||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler_Carbon::InputHandler_Carbon() : m_Sem( "Input thread started" ), m_ChangeLock( "Input handler change lock" )
|
// Factor this out because nothing else in IH_C::AddDevices() needs to know the type of the device.
|
||||||
|
static HIDDevice *MakeDevice( InputDevice id )
|
||||||
{
|
{
|
||||||
// Set up the notify ports
|
if( id == DEVICE_KEYBOARD )
|
||||||
m_NotifyPort = IONotificationPortCreate( kIOMasterPortDefault );
|
return new KeyboardDevice;
|
||||||
|
if( id <= DEVICE_JOY16 )
|
||||||
|
return new JoystickDevice;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Find the keyboards.
|
void InputHandler_Carbon::AddDevices( int usage, InputDevice &id )
|
||||||
|
{
|
||||||
io_iterator_t iter;
|
io_iterator_t iter;
|
||||||
CFDictionaryRef dict = GetMatchingDictionary( kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard );
|
CFDictionaryRef dict = GetMatchingDictionary( kHIDPage_GenericDesktop, usage );
|
||||||
kern_return_t ret = IOServiceAddMatchingNotification( m_NotifyPort, kIOFirstMatchNotification, dict,
|
kern_return_t ret = IOServiceAddMatchingNotification( m_NotifyPort, kIOFirstMatchNotification, dict,
|
||||||
InputHandler_Carbon::DeviceAdded, this, &iter );
|
InputHandler_Carbon::DeviceAdded, this, &iter );
|
||||||
|
io_object_t device;
|
||||||
|
|
||||||
if( ret == KERN_SUCCESS )
|
if( ret != KERN_SUCCESS )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_vIters.push_back( iter );
|
||||||
|
|
||||||
|
// Iterate over the devices and add them
|
||||||
|
while( (device = IOIteratorNext(iter)) )
|
||||||
{
|
{
|
||||||
m_vIters.push_back( iter );
|
HIDDevice *dev = MakeDevice( id );
|
||||||
// Iterate over the keyboards and add them.
|
|
||||||
io_object_t device;
|
|
||||||
|
|
||||||
while( (device = IOIteratorNext(iter)) )
|
if( !dev )
|
||||||
{
|
{
|
||||||
HIDDevice *kd = new KeyboardDevice;
|
|
||||||
|
|
||||||
if( !kd->Open(device) )
|
|
||||||
{
|
|
||||||
delete kd;
|
|
||||||
IOObjectRelease( device );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_vDevices.push_back( kd );
|
|
||||||
|
|
||||||
io_iterator_t i;
|
|
||||||
ret = IOServiceAddInterestNotification( m_NotifyPort, device, kIOGeneralInterest,
|
|
||||||
InputHandler_Carbon::DeviceChanged, this, &i );
|
|
||||||
|
|
||||||
if( ret == KERN_SUCCESS )
|
|
||||||
m_vIters.push_back( i );
|
|
||||||
|
|
||||||
IOObjectRelease( device );
|
IOObjectRelease( device );
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Find the joysticks.
|
if( !dev->Open(device) )
|
||||||
dict = GetMatchingDictionary( kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick );
|
|
||||||
ret = IOServiceAddMatchingNotification( m_NotifyPort, kIOFirstMatchNotification, dict,
|
|
||||||
InputHandler_Carbon::DeviceAdded, this, &iter );
|
|
||||||
|
|
||||||
if( ret == KERN_SUCCESS )
|
|
||||||
{
|
|
||||||
m_vIters.push_back( iter );
|
|
||||||
// Iterate over the joysticks and add them.
|
|
||||||
io_object_t device;
|
|
||||||
InputDevice id = DEVICE_JOY1;
|
|
||||||
|
|
||||||
while( (device = IOIteratorNext(iter)) )
|
|
||||||
{
|
{
|
||||||
HIDDevice *jd = new JoystickDevice;
|
delete dev;
|
||||||
|
|
||||||
if( !jd->Open(device) )
|
|
||||||
{
|
|
||||||
delete jd;
|
|
||||||
IOObjectRelease( device );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int num = jd->AssignIDs( id );
|
|
||||||
|
|
||||||
enum_add( id, num );
|
|
||||||
m_vDevices.push_back( jd );
|
|
||||||
|
|
||||||
io_iterator_t i;
|
|
||||||
ret = IOServiceAddInterestNotification( m_NotifyPort, device, kIOGeneralInterest,
|
|
||||||
InputHandler_Carbon::DeviceChanged, this, &i );
|
|
||||||
|
|
||||||
if( ret == KERN_SUCCESS )
|
|
||||||
m_vIters.push_back( i );
|
|
||||||
IOObjectRelease( device );
|
IOObjectRelease( device );
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
int num = dev->AssignIDs( id );
|
||||||
|
io_iterator_t i;
|
||||||
|
|
||||||
|
enum_add( id, num );
|
||||||
|
m_vDevices.push_back( dev );
|
||||||
|
|
||||||
|
ret = IOServiceAddInterestNotification( m_NotifyPort, device, kIOGeneralInterest,
|
||||||
|
InputHandler_Carbon::DeviceChanged, this, &i );
|
||||||
|
|
||||||
|
if( ret == KERN_SUCCESS )
|
||||||
|
m_vIters.push_back( i );
|
||||||
|
IOObjectRelease( device );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InputHandler_Carbon::InputHandler_Carbon() : m_Sem( "Input thread started" ), m_ChangeLock( "Input handler change lock" )
|
||||||
|
{
|
||||||
|
InputDevice id = DEVICE_KEYBOARD;
|
||||||
|
|
||||||
|
// Set up the notify ports.
|
||||||
|
m_NotifyPort = IONotificationPortCreate( kIOMasterPortDefault );
|
||||||
|
|
||||||
|
// Add devices.
|
||||||
|
AddDevices( kHIDUsage_GD_Keyboard, id );
|
||||||
|
id = DEVICE_JOY1;
|
||||||
|
AddDevices( kHIDUsage_GD_Joystick, id );
|
||||||
|
AddDevices( kHIDUsage_GD_GamePad, id );
|
||||||
m_bChanged = false;
|
m_bChanged = false;
|
||||||
|
|
||||||
if( PREFSMAN->m_bThreadedInput )
|
if( PREFSMAN->m_bThreadedInput )
|
||||||
{
|
{
|
||||||
m_InputThread.SetName( "Input thread" );
|
m_InputThread.SetName( "Input thread" );
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ class HIDDevice;
|
|||||||
class InputHandler_Carbon : public InputHandler
|
class InputHandler_Carbon : public InputHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::vector<HIDDevice *> m_vDevices;
|
vector<HIDDevice *> m_vDevices;
|
||||||
RageThread m_InputThread;
|
RageThread m_InputThread;
|
||||||
RageSemaphore m_Sem;
|
RageSemaphore m_Sem;
|
||||||
CFRunLoopRef m_LoopRef;
|
CFRunLoopRef m_LoopRef;
|
||||||
CFRunLoopSourceRef m_SourceRef;
|
CFRunLoopSourceRef m_SourceRef;
|
||||||
std::vector<io_iterator_t> m_vIters; // We don't really care about these but they need to stick around
|
vector<io_iterator_t> m_vIters; // We don't really care about these but they need to stick around
|
||||||
IONotificationPortRef m_NotifyPort;
|
IONotificationPortRef m_NotifyPort;
|
||||||
RageMutex m_ChangeLock;
|
RageMutex m_ChangeLock;
|
||||||
bool m_bChanged;
|
bool m_bChanged;
|
||||||
@@ -26,6 +26,7 @@ private:
|
|||||||
static void DeviceAdded( void *refCon, io_iterator_t iter );
|
static void DeviceAdded( void *refCon, io_iterator_t iter );
|
||||||
static void DeviceChanged( void *refCon, io_service_t service, natural_t messageType, void *arg );
|
static void DeviceChanged( void *refCon, io_service_t service, natural_t messageType, void *arg );
|
||||||
void StartDevices();
|
void StartDevices();
|
||||||
|
void AddDevices( int usage, InputDevice &id );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InputHandler_Carbon();
|
InputHandler_Carbon();
|
||||||
|
|||||||
Reference in New Issue
Block a user