Enumerate identically named input devices.
Fixes issue 3929. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6984 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
25716f067c
commit
aa410c8eea
|
@ -14,6 +14,7 @@ namespace OSX
|
|||
|
||||
static IOHIDManagerRef HIDManager = NULL;
|
||||
static CFStringRef OurRunLoop = CFSTR("DolphinOSXInput");
|
||||
static std::map<std::string, int> kbd_name_counts, joy_name_counts;
|
||||
|
||||
void DeviceElementDebugPrint(const void *value, void *context)
|
||||
{
|
||||
|
@ -136,6 +137,9 @@ static void DeviceMatching_callback(void* inContext,
|
|||
void *inSender,
|
||||
IOHIDDeviceRef inIOHIDDeviceRef)
|
||||
{
|
||||
std::string name = [(NSString *)IOHIDDeviceGetProperty(inIOHIDDeviceRef,
|
||||
CFSTR(kIOHIDProductKey)) UTF8String];
|
||||
|
||||
DeviceDebugPrint(inIOHIDDeviceRef);
|
||||
|
||||
std::vector<ControllerInterface::Device*> *devices =
|
||||
|
@ -144,12 +148,17 @@ static void DeviceMatching_callback(void* inContext,
|
|||
// Add to the devices vector if it's of a type we want
|
||||
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
|
||||
kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard))
|
||||
devices->push_back(new Keyboard(inIOHIDDeviceRef));
|
||||
devices->push_back(new Keyboard(inIOHIDDeviceRef,
|
||||
name, kbd_name_counts[name]++));
|
||||
#if 0
|
||||
else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
|
||||
kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
|
||||
return; // XXX devices->push_back(new Mouse(inIOHIDDeviceRef));
|
||||
devices->push_back(new Mouse(inIOHIDDeviceRef,
|
||||
name, mouse_name_counts[name++]));
|
||||
#endif
|
||||
else
|
||||
devices->push_back(new Joystick(inIOHIDDeviceRef));
|
||||
devices->push_back(new Joystick(inIOHIDDeviceRef,
|
||||
name, joy_name_counts[name]++));
|
||||
}
|
||||
|
||||
void Init(std::vector<ControllerInterface::Device*>& devices)
|
||||
|
@ -159,7 +168,7 @@ void Init(std::vector<ControllerInterface::Device*>& devices)
|
|||
if (!HIDManager)
|
||||
NSLog(@"Failed to create HID Manager reference");
|
||||
|
||||
IOHIDManagerSetDeviceMatchingMultiple(HIDManager, NULL);
|
||||
IOHIDManagerSetDeviceMatching(HIDManager, NULL);
|
||||
|
||||
// Callbacks for acquisition or loss of a matching device
|
||||
IOHIDManagerRegisterDeviceMatchingCallback(HIDManager,
|
||||
|
@ -172,6 +181,9 @@ void Init(std::vector<ControllerInterface::Device*>& devices)
|
|||
kIOReturnSuccess)
|
||||
NSLog(@"Failed to open HID Manager");
|
||||
|
||||
kbd_name_counts.clear();
|
||||
joy_name_counts.clear();
|
||||
|
||||
// Wait while current devices are initialized
|
||||
while (CFRunLoopRunInMode(OurRunLoop, 0, TRUE) ==
|
||||
kCFRunLoopRunHandledSource) {};
|
||||
|
|
|
@ -83,7 +83,7 @@ protected:
|
|||
const ControlState state);
|
||||
|
||||
public:
|
||||
Joystick(IOHIDDeviceRef device);
|
||||
Joystick(IOHIDDeviceRef device, std::string name, int index);
|
||||
|
||||
std::string GetName() const;
|
||||
std::string GetSource() const;
|
||||
|
@ -92,6 +92,7 @@ public:
|
|||
private:
|
||||
IOHIDDeviceRef m_device;
|
||||
std::string m_device_name;
|
||||
int m_index;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -11,12 +11,11 @@ namespace OSX
|
|||
|
||||
extern void DeviceElementDebugPrint(const void*, void*);
|
||||
|
||||
Joystick::Joystick(IOHIDDeviceRef device)
|
||||
Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index)
|
||||
: m_device(device)
|
||||
, m_device_name(name)
|
||||
, m_index(index)
|
||||
{
|
||||
m_device_name = [(NSString *)IOHIDDeviceGetProperty(m_device,
|
||||
CFSTR(kIOHIDProductKey)) UTF8String];
|
||||
|
||||
// Buttons
|
||||
NSDictionary *buttonDict =
|
||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
|
@ -103,17 +102,14 @@ std::string Joystick::GetName() const
|
|||
|
||||
std::string Joystick::GetSource() const
|
||||
{
|
||||
return "HID";
|
||||
return "Input";
|
||||
}
|
||||
|
||||
int Joystick::GetId() const
|
||||
{
|
||||
// Overload the "id" to identify devices by HID type when names collide
|
||||
// XXX This class is now a catch-all, so query the usage page number
|
||||
return kHIDUsage_GD_GamePad;
|
||||
return m_index;
|
||||
}
|
||||
|
||||
|
||||
Joystick::Button::Button(IOHIDElementRef element)
|
||||
: m_element(element)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@ protected:
|
|||
const ControlState state);
|
||||
|
||||
public:
|
||||
Keyboard(IOHIDDeviceRef device);
|
||||
Keyboard(IOHIDDeviceRef device, std::string name, int index);
|
||||
|
||||
std::string GetName() const;
|
||||
std::string GetSource() const;
|
||||
|
@ -52,6 +52,7 @@ public:
|
|||
private:
|
||||
IOHIDDeviceRef m_device;
|
||||
std::string m_device_name;
|
||||
int m_index;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,12 +21,11 @@ const struct PrettyKeys
|
|||
|
||||
extern void DeviceElementDebugPrint(const void *, void *);
|
||||
|
||||
Keyboard::Keyboard(IOHIDDeviceRef device)
|
||||
Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index)
|
||||
: m_device(device)
|
||||
, m_device_name(name)
|
||||
, m_index(index)
|
||||
{
|
||||
m_device_name = [(NSString *)IOHIDDeviceGetProperty(m_device,
|
||||
CFSTR(kIOHIDProductKey)) UTF8String];
|
||||
|
||||
// This class should only recieve Keyboard or Keypad devices
|
||||
// Now, filter on just the buttons we can handle sanely
|
||||
NSDictionary *matchingElements =
|
||||
|
@ -83,13 +82,12 @@ std::string Keyboard::GetName() const
|
|||
|
||||
std::string Keyboard::GetSource() const
|
||||
{
|
||||
return "HID";
|
||||
return "Keyboard";
|
||||
}
|
||||
|
||||
int Keyboard::GetId() const
|
||||
{
|
||||
// Overload the "id" to identify devices by HID type when names collide
|
||||
return kHIDUsage_GD_Keyboard;
|
||||
return m_index;
|
||||
}
|
||||
|
||||
Keyboard::Key::Key(IOHIDElementRef element)
|
||||
|
|
Loading…
Reference in New Issue