mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-11 03:45:31 +00:00
[Mac] Add skeleton HID input implementation for joysticks
This commit is contained in:
parent
3a63496b6d
commit
9659a1d786
|
@ -60,11 +60,17 @@ namespace OpenTK.Platform.MacOS
|
||||||
new Dictionary<IntPtr, MouseState>(new IntPtrEqualityComparer());
|
new Dictionary<IntPtr, MouseState>(new IntPtrEqualityComparer());
|
||||||
readonly Dictionary<int, IntPtr> MouseIndexToDevice =
|
readonly Dictionary<int, IntPtr> MouseIndexToDevice =
|
||||||
new Dictionary<int, IntPtr>();
|
new Dictionary<int, IntPtr>();
|
||||||
|
|
||||||
readonly Dictionary<IntPtr, KeyboardState> KeyboardDevices =
|
readonly Dictionary<IntPtr, KeyboardState> KeyboardDevices =
|
||||||
new Dictionary<IntPtr, KeyboardState>(new IntPtrEqualityComparer());
|
new Dictionary<IntPtr, KeyboardState>(new IntPtrEqualityComparer());
|
||||||
readonly Dictionary<int, IntPtr> KeyboardIndexToDevice =
|
readonly Dictionary<int, IntPtr> KeyboardIndexToDevice =
|
||||||
new Dictionary<int, IntPtr>();
|
new Dictionary<int, IntPtr>();
|
||||||
|
|
||||||
|
readonly Dictionary<IntPtr, JoystickState> JoystickDevices =
|
||||||
|
new Dictionary<IntPtr, JoystickState>(new IntPtrEqualityComparer());
|
||||||
|
readonly Dictionary<int, IntPtr> JoystickIndexToDevice =
|
||||||
|
new Dictionary<int, IntPtr>();
|
||||||
|
|
||||||
readonly CFRunLoop RunLoop = CF.CFRunLoopGetMain();
|
readonly CFRunLoop RunLoop = CF.CFRunLoopGetMain();
|
||||||
readonly CFString InputLoopMode = CF.RunLoopModeDefault;
|
readonly CFString InputLoopMode = CF.RunLoopModeDefault;
|
||||||
readonly CFDictionary DeviceTypes = new CFDictionary();
|
readonly CFDictionary DeviceTypes = new CFDictionary();
|
||||||
|
@ -126,41 +132,19 @@ namespace OpenTK.Platform.MacOS
|
||||||
if (NativeMethods.IOHIDDeviceConformsTo(device,
|
if (NativeMethods.IOHIDDeviceConformsTo(device,
|
||||||
HIDPage.GenericDesktop, (int)HIDUsageGD.Mouse))
|
HIDPage.GenericDesktop, (int)HIDUsageGD.Mouse))
|
||||||
{
|
{
|
||||||
if (!MouseDevices.ContainsKey(device))
|
AddMouse(sender, device);
|
||||||
{
|
|
||||||
Debug.Print("Mouse device {0:x} discovered, sender is {1:x}", device, sender);
|
|
||||||
MouseState state = new MouseState();
|
|
||||||
state.IsConnected = true;
|
|
||||||
MouseIndexToDevice.Add(MouseDevices.Count, device);
|
|
||||||
MouseDevices.Add(device, state);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Print("Mouse device {0:x} reconnected, sender is {1:x}", device, sender);
|
|
||||||
MouseState state = MouseDevices[device];
|
|
||||||
state.IsConnected = true;
|
|
||||||
MouseDevices[device] = state;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NativeMethods.IOHIDDeviceConformsTo(device,
|
if (NativeMethods.IOHIDDeviceConformsTo(device,
|
||||||
HIDPage.GenericDesktop, (int)HIDUsageGD.Keyboard))
|
HIDPage.GenericDesktop, (int)HIDUsageGD.Keyboard))
|
||||||
{
|
{
|
||||||
if (!KeyboardDevices.ContainsKey(device))
|
AddKeyboard(sender, device);
|
||||||
{
|
}
|
||||||
Debug.Print("Keyboard device {0:x} discovered, sender is {1:x}", device, sender);
|
|
||||||
KeyboardState state = new KeyboardState();
|
if (NativeMethods.IOHIDDeviceConformsTo(device,
|
||||||
state.IsConnected = true;
|
HIDPage.GenericDesktop, (int)HIDUsageGD.Joystick))
|
||||||
KeyboardIndexToDevice.Add(KeyboardDevices.Count, device);
|
{
|
||||||
KeyboardDevices.Add(device, state);
|
AddJoystick(sender, device);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.Print("Keyboard device {0:x} reconnected, sender is {1:x}", device, sender);
|
|
||||||
KeyboardState state = KeyboardDevices[device];
|
|
||||||
state.IsConnected = true;
|
|
||||||
KeyboardDevices[device] = state;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The device is not normally available in the InputValueCallback (HandleDeviceValueReceived), so we include
|
// The device is not normally available in the InputValueCallback (HandleDeviceValueReceived), so we include
|
||||||
|
@ -178,23 +162,19 @@ namespace OpenTK.Platform.MacOS
|
||||||
if (NativeMethods.IOHIDDeviceConformsTo(device, HIDPage.GenericDesktop, (int)HIDUsageGD.Mouse) &&
|
if (NativeMethods.IOHIDDeviceConformsTo(device, HIDPage.GenericDesktop, (int)HIDUsageGD.Mouse) &&
|
||||||
MouseDevices.ContainsKey(device))
|
MouseDevices.ContainsKey(device))
|
||||||
{
|
{
|
||||||
Debug.Print("Mouse device {0:x} disconnected, sender is {1:x}", device, sender);
|
RemoveMouse(sender, device);
|
||||||
|
|
||||||
// Keep the device in case it comes back later on
|
|
||||||
MouseState state = MouseDevices[device];
|
|
||||||
state.IsConnected = false;
|
|
||||||
MouseDevices[device] = state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NativeMethods.IOHIDDeviceConformsTo(device, HIDPage.GenericDesktop, (int)HIDUsageGD.Keyboard) &&
|
if (NativeMethods.IOHIDDeviceConformsTo(device, HIDPage.GenericDesktop, (int)HIDUsageGD.Keyboard) &&
|
||||||
KeyboardDevices.ContainsKey(device))
|
KeyboardDevices.ContainsKey(device))
|
||||||
{
|
{
|
||||||
Debug.Print("Keyboard device {0:x} disconnected, sender is {1:x}", device, sender);
|
RemoveKeyboard(sender, device);
|
||||||
|
}
|
||||||
|
|
||||||
// Keep the device in case it comes back later on
|
if (NativeMethods.IOHIDDeviceConformsTo(device, HIDPage.GenericDesktop, (int)HIDUsageGD.Joystick) &&
|
||||||
KeyboardState state = KeyboardDevices[device];
|
JoystickDevices.ContainsKey(device))
|
||||||
state.IsConnected = false;
|
{
|
||||||
KeyboardDevices[device] = state;
|
RemoveJoystick(sender, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeMethods.IOHIDDeviceRegisterInputValueCallback(device, IntPtr.Zero, IntPtr.Zero);
|
NativeMethods.IOHIDDeviceRegisterInputValueCallback(device, IntPtr.Zero, IntPtr.Zero);
|
||||||
|
@ -224,6 +204,36 @@ namespace OpenTK.Platform.MacOS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Mouse
|
||||||
|
|
||||||
|
void AddMouse(CFAllocatorRef sender, CFAllocatorRef device)
|
||||||
|
{
|
||||||
|
if (!MouseDevices.ContainsKey(device))
|
||||||
|
{
|
||||||
|
Debug.Print("Mouse device {0:x} discovered, sender is {1:x}", device, sender);
|
||||||
|
MouseState state = new MouseState();
|
||||||
|
state.IsConnected = true;
|
||||||
|
MouseIndexToDevice.Add(MouseDevices.Count, device);
|
||||||
|
MouseDevices.Add(device, state);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Print("Mouse device {0:x} reconnected, sender is {1:x}", device, sender);
|
||||||
|
MouseState state = MouseDevices[device];
|
||||||
|
state.IsConnected = true;
|
||||||
|
MouseDevices[device] = state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveMouse(CFAllocatorRef sender, CFAllocatorRef device)
|
||||||
|
{
|
||||||
|
Debug.Print("Mouse device {0:x} disconnected, sender is {1:x}", device, sender);
|
||||||
|
// Keep the device in case it comes back later on
|
||||||
|
MouseState state = MouseDevices[device];
|
||||||
|
state.IsConnected = false;
|
||||||
|
MouseDevices[device] = state;
|
||||||
|
}
|
||||||
|
|
||||||
static MouseState UpdateMouse(MouseState state, IOHIDValueRef val)
|
static MouseState UpdateMouse(MouseState state, IOHIDValueRef val)
|
||||||
{
|
{
|
||||||
IOHIDElementRef elem = NativeMethods.IOHIDValueGetElement(val);
|
IOHIDElementRef elem = NativeMethods.IOHIDValueGetElement(val);
|
||||||
|
@ -260,6 +270,38 @@ namespace OpenTK.Platform.MacOS
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Keyboard
|
||||||
|
|
||||||
|
void AddKeyboard(CFAllocatorRef sender, CFAllocatorRef device)
|
||||||
|
{
|
||||||
|
if (!KeyboardDevices.ContainsKey(device))
|
||||||
|
{
|
||||||
|
Debug.Print("Keyboard device {0:x} discovered, sender is {1:x}", device, sender);
|
||||||
|
KeyboardState state = new KeyboardState();
|
||||||
|
state.IsConnected = true;
|
||||||
|
KeyboardIndexToDevice.Add(KeyboardDevices.Count, device);
|
||||||
|
KeyboardDevices.Add(device, state);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Print("Keyboard device {0:x} reconnected, sender is {1:x}", device, sender);
|
||||||
|
KeyboardState state = KeyboardDevices[device];
|
||||||
|
state.IsConnected = true;
|
||||||
|
KeyboardDevices[device] = state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveKeyboard(CFAllocatorRef sender, CFAllocatorRef device)
|
||||||
|
{
|
||||||
|
Debug.Print("Keyboard device {0:x} disconnected, sender is {1:x}", device, sender);
|
||||||
|
// Keep the device in case it comes back later on
|
||||||
|
KeyboardState state = KeyboardDevices[device];
|
||||||
|
state.IsConnected = false;
|
||||||
|
KeyboardDevices[device] = state;
|
||||||
|
}
|
||||||
|
|
||||||
static KeyboardState UpdateKeyboard(KeyboardState state, IOHIDValueRef val)
|
static KeyboardState UpdateKeyboard(KeyboardState state, IOHIDValueRef val)
|
||||||
{
|
{
|
||||||
IOHIDElementRef elem = NativeMethods.IOHIDValueGetElement(val);
|
IOHIDElementRef elem = NativeMethods.IOHIDValueGetElement(val);
|
||||||
|
@ -289,6 +331,22 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Joystick
|
||||||
|
|
||||||
|
void AddJoystick(CFAllocatorRef sender, CFAllocatorRef device)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveJoystick(CFAllocatorRef sender, CFAllocatorRef device)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region IInputDriver2 Members
|
#region IInputDriver2 Members
|
||||||
|
|
||||||
public IMouseDriver2 MouseDriver { get { return this; } }
|
public IMouseDriver2 MouseDriver { get { return this; } }
|
||||||
|
|
Loading…
Reference in a new issue