From aa410c8eea7ca21d74ae43f6185145e7035418fe Mon Sep 17 00:00:00 2001 From: Soren Jorvang Date: Sun, 30 Jan 2011 05:46:19 +0000 Subject: [PATCH] Enumerate identically named input devices. Fixes issue 3929. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6984 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Src/ControllerInterface/OSX/OSX.mm | 20 +++++++++++++++---- .../Src/ControllerInterface/OSX/OSXJoystick.h | 3 ++- .../ControllerInterface/OSX/OSXJoystick.mm | 14 +++++-------- .../Src/ControllerInterface/OSX/OSXKeyboard.h | 3 ++- .../ControllerInterface/OSX/OSXKeyboard.mm | 12 +++++------ 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm index 5684c275c2..5c5143fdb2 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSX.mm @@ -14,6 +14,7 @@ namespace OSX static IOHIDManagerRef HIDManager = NULL; static CFStringRef OurRunLoop = CFSTR("DolphinOSXInput"); +static std::map 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 *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& devices) @@ -159,7 +168,7 @@ void Init(std::vector& 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& 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) {}; diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h index c26df5e579..fe851a637f 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h @@ -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; }; } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm index 223e363cce..a88137f0e0 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm @@ -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) { diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h index 6d3467a90e..181a340515 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.h @@ -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; }; } diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm index 0838f481dd..5268720709 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXKeyboard.mm @@ -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)