mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-06-25 05:51:23 +00:00
[Mac] Retrieve HID joystick name
This commit is contained in:
parent
6dadbd3570
commit
07bcda0f57
|
@ -35,6 +35,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
using Carbon;
|
using Carbon;
|
||||||
using CFAllocatorRef = System.IntPtr;
|
using CFAllocatorRef = System.IntPtr;
|
||||||
|
using CFArrayRef = System.IntPtr;
|
||||||
using CFDictionaryRef = System.IntPtr;
|
using CFDictionaryRef = System.IntPtr;
|
||||||
using CFIndex = System.IntPtr;
|
using CFIndex = System.IntPtr;
|
||||||
using CFRunLoop = System.IntPtr;
|
using CFRunLoop = System.IntPtr;
|
||||||
|
@ -58,6 +59,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
public JoystickState State;
|
public JoystickState State;
|
||||||
public JoystickCapabilities Capabilities;
|
public JoystickCapabilities Capabilities;
|
||||||
|
public string Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MacJoystick : JoystickDevice<JoystickDetails>
|
class MacJoystick : JoystickDevice<JoystickDetails>
|
||||||
|
@ -371,12 +373,25 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
MacJoystick CreateJoystick(CFAllocatorRef sender, CFAllocatorRef device)
|
MacJoystick CreateJoystick(CFAllocatorRef sender, CFAllocatorRef device)
|
||||||
{
|
{
|
||||||
MacJoystick joy = new MacJoystick(-1, 0, 0);
|
MacJoystick joy = null;
|
||||||
joy.Details.State.SetIsConnected(true);
|
|
||||||
|
|
||||||
// Todo: discover joystick capabilities
|
// Retrieve all elements of this device
|
||||||
|
CFArrayRef element_array = NativeMethods.IOHIDDeviceCopyMatchingElements(device, IntPtr.Zero, IntPtr.Zero);
|
||||||
|
if (element_array != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
CFStringRef name_ref = NativeMethods.IOHIDDeviceGetProperty(device, NativeMethods.IOHIDProductKey);
|
||||||
|
string name = CF.CFStringGetCString(name_ref);
|
||||||
|
CF.CFRelease(name_ref);
|
||||||
|
|
||||||
|
joy = new MacJoystick(-1, 0, 0);
|
||||||
|
joy.Details.Name = name;
|
||||||
|
joy.Details.State.SetIsConnected(true);
|
||||||
joy.Details.Capabilities = new JoystickCapabilities(0, 0, true);
|
joy.Details.Capabilities = new JoystickCapabilities(0, 0, true);
|
||||||
|
|
||||||
|
//NativeMethods.IOHIDDeviceGetProperty(device, nativem
|
||||||
|
}
|
||||||
|
CF.CFRelease(element_array);
|
||||||
|
|
||||||
return joy;
|
return joy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,9 +401,12 @@ namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
Debug.Print("Joystick device {0:x} discovered, sender is {1:x}", device, sender);
|
Debug.Print("Joystick device {0:x} discovered, sender is {1:x}", device, sender);
|
||||||
MacJoystick joy = CreateJoystick(sender, device);
|
MacJoystick joy = CreateJoystick(sender, device);
|
||||||
|
if (joy != null)
|
||||||
|
{
|
||||||
JoystickIndexToDevice.Add(JoystickDevices.Count, device);
|
JoystickIndexToDevice.Add(JoystickDevices.Count, device);
|
||||||
JoystickDevices.Add(device, joy);
|
JoystickDevices.Add(device, joy);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Print("Joystick device {0:x} reconnected, sender is {1:x}", device, sender);
|
Debug.Print("Joystick device {0:x} reconnected, sender is {1:x}", device, sender);
|
||||||
|
@ -602,6 +620,13 @@ namespace OpenTK.Platform.MacOS
|
||||||
HIDPage inUsagePage, // the usage page to test conformance with
|
HIDPage inUsagePage, // the usage page to test conformance with
|
||||||
int inUsage); // the usage to test conformance with
|
int inUsage); // the usage to test conformance with
|
||||||
|
|
||||||
|
// return the HID elements that match the criteria contained in the matching dictionary
|
||||||
|
[DllImport(hid)]
|
||||||
|
public static extern CFArrayRef IOHIDDeviceCopyMatchingElements(
|
||||||
|
IOHIDDeviceRef inIOHIDDeviceRef, // IOHIDDeviceRef for the HID device
|
||||||
|
CFDictionaryRef inMatchingCFDictRef, // the matching dictionary
|
||||||
|
IOOptionBits inOptions); // Option bits
|
||||||
|
|
||||||
[DllImport(hid)]
|
[DllImport(hid)]
|
||||||
public static extern void IOHIDDeviceRegisterInputValueCallback(
|
public static extern void IOHIDDeviceRegisterInputValueCallback(
|
||||||
IOHIDDeviceRef device,
|
IOHIDDeviceRef device,
|
||||||
|
|
Loading…
Reference in a new issue