mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 05:40:01 -06:00
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.
This commit is contained in:
@ -21,7 +21,6 @@ namespace OSX
|
||||
{
|
||||
static IOHIDManagerRef HIDManager = nullptr;
|
||||
static CFStringRef OurRunLoop = CFSTR("DolphinOSXInput");
|
||||
static std::map<std::string, int> 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<Keyboard>(inIOHIDDeviceRef, name, kbd_name_counts[name]++, g_window));
|
||||
g_controller_interface.AddDevice(std::make_shared<Keyboard>(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<Joystick>(inIOHIDDeviceRef, name, joy_name_counts[name]++));
|
||||
g_controller_interface.AddDevice(std::make_shared<Joystick>(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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user