From 788e19f54d86ba45cdc83d39c0488b17aa1d00dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 14 Jul 2016 10:25:52 +0200 Subject: ControllerInterface: Make the ID assigning code common This makes the device ID assigning code common to all backends, by moving it to AddDevice() instead of copy-pasting or replicating the logic in the backends. Also, to prepare for hotplugging, instead of relying on a name usage count, the new ID assigning system always starts from ID 0 and tries to assign the first ID that is not used. --- Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm | 16 ++++------------ .../InputCommon/ControllerInterface/OSX/OSXJoystick.h | 4 +--- .../InputCommon/ControllerInterface/OSX/OSXJoystick.mm | 9 ++------- .../InputCommon/ControllerInterface/OSX/OSXKeyboard.h | 4 +--- .../InputCommon/ControllerInterface/OSX/OSXKeyboard.mm | 9 ++------- 5 files changed, 10 insertions(+), 32 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/OSX') diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm index 25caec2c4f..e575260a89 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSX.mm @@ -21,7 +21,6 @@ namespace OSX { static IOHIDManagerRef HIDManager = nullptr; static CFStringRef OurRunLoop = CFSTR("DolphinOSXInput"); -static std::map kbd_name_counts, joy_name_counts; void DeviceElementDebugPrint(const void* value, void* context) { @@ -145,17 +144,13 @@ static void DeviceMatching_callback(void* inContext, IOReturn inResult, void* in // Add a device if it's of a type we want if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)) - g_controller_interface.AddDevice( - std::make_shared(inIOHIDDeviceRef, name, kbd_name_counts[name]++, g_window)); + g_controller_interface.AddDevice(std::make_shared(inIOHIDDeviceRef, name, g_window)); #if 0 - else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, - kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse)) - g_controller_interface.AddDevice(new Mouse(inIOHIDDeviceRef, - name, mouse_name_counts[name]++)); + else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse)) + g_controller_interface.AddDevice(new Mouse(inIOHIDDeviceRef, name)); #endif else - g_controller_interface.AddDevice( - std::make_shared(inIOHIDDeviceRef, name, joy_name_counts[name]++)); + g_controller_interface.AddDevice(std::make_shared(inIOHIDDeviceRef, name)); } void Init(void* window) @@ -176,9 +171,6 @@ void Init(void* window) if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != 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/ControllerInterface/OSX/OSXJoystick.h b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h index 3e3d62b2c6..41ea7c8365 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.h @@ -73,17 +73,15 @@ private: }; public: - Joystick(IOHIDDeviceRef device, std::string name, int index); + Joystick(IOHIDDeviceRef device, std::string name); ~Joystick(); std::string GetName() const override; std::string GetSource() const override; - int GetId() const override; private: const IOHIDDeviceRef m_device; const std::string m_device_name; - const int m_index; ForceFeedback::FFDeviceAdapterReference m_ff_device; }; diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm index 06c883ac4e..204e002e25 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXJoystick.mm @@ -14,8 +14,8 @@ namespace ciface { namespace OSX { -Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index) - : m_device(device), m_device_name(name), m_index(index), m_ff_device(nullptr) +Joystick::Joystick(IOHIDDeviceRef device, std::string name) + : m_device(device), m_device_name(name), m_ff_device(nullptr) { // Buttons NSDictionary* buttonDict = @{ @@ -93,11 +93,6 @@ std::string Joystick::GetSource() const return "Input"; } -int Joystick::GetId() const -{ - return m_index; -} - ControlState Joystick::Button::GetState() const { IOHIDValueRef value; diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h index 5b3551a5b7..d73243259e 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.h @@ -60,11 +60,10 @@ private: public: void UpdateInput() override; - Keyboard(IOHIDDeviceRef device, std::string name, int index, void* window); + Keyboard(IOHIDDeviceRef device, std::string name, void* window); std::string GetName() const override; std::string GetSource() const override; - int GetId() const override; private: struct @@ -74,7 +73,6 @@ private: const IOHIDDeviceRef m_device; const std::string m_device_name; - int m_index; uint32_t m_windowid; unsigned char m_mousebuttons[3]; }; diff --git a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm index f5c1e5ac98..a2ca55649d 100644 --- a/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm +++ b/Source/Core/InputCommon/ControllerInterface/OSX/OSXKeyboard.mm @@ -14,8 +14,8 @@ namespace ciface { namespace OSX { -Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index, void* window) - : m_device(device), m_device_name(name), m_index(index) +Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, void* window) + : m_device(device), m_device_name(name) { // This class should only recieve Keyboard or Keypad devices // Now, filter on just the buttons we can handle sanely @@ -98,11 +98,6 @@ std::string Keyboard::GetSource() const return "Keyboard"; } -int Keyboard::GetId() const -{ - return m_index; -} - Keyboard::Key::Key(IOHIDElementRef element, IOHIDDeviceRef device) : m_element(element), m_device(device) { -- cgit v1.2.3