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