mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-06-04 14:28:19 +00:00
[Mac] Correctly shutdown HID input driver
This commit is contained in:
parent
bdff76c639
commit
a047c08d3d
|
@ -77,7 +77,7 @@ namespace OpenTK.Platform.MacOS
|
||||||
new Dictionary<IOHIDElementRef, JoystickHat>(new IntPtrEqualityComparer());
|
new Dictionary<IOHIDElementRef, JoystickHat>(new IntPtrEqualityComparer());
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly IOHIDManagerRef hidmanager;
|
IOHIDManagerRef hidmanager;
|
||||||
|
|
||||||
readonly Dictionary<IntPtr, MouseData> MouseDevices =
|
readonly Dictionary<IntPtr, MouseData> MouseDevices =
|
||||||
new Dictionary<IntPtr, MouseData>(new IntPtrEqualityComparer());
|
new Dictionary<IntPtr, MouseData>(new IntPtrEqualityComparer());
|
||||||
|
@ -124,6 +124,12 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
// For retrieving input directly from the hardware
|
// For retrieving input directly from the hardware
|
||||||
hidmanager = CreateHIDManager();
|
hidmanager = CreateHIDManager();
|
||||||
|
if (hidmanager == IntPtr.Zero)
|
||||||
|
{
|
||||||
|
Debug.Print("[Mac] Failed to create IO HID manager, HIDInput driver not supported.");
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
RegisterHIDCallbacks(hidmanager);
|
RegisterHIDCallbacks(hidmanager);
|
||||||
|
|
||||||
// For retrieving the global cursor position
|
// For retrieving the global cursor position
|
||||||
|
@ -1032,7 +1038,11 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
[DllImport(hid)]
|
[DllImport(hid)]
|
||||||
public static extern IOHIDManagerRef IOHIDManagerCreate(
|
public static extern IOHIDManagerRef IOHIDManagerCreate(
|
||||||
CFAllocatorRef allocator, IOOptionBits options) ;
|
CFAllocatorRef allocator, IOOptionBits options);
|
||||||
|
|
||||||
|
[DllImport(hid)]
|
||||||
|
public static extern IOReturn IOHIDManagerClose(
|
||||||
|
IOHIDManagerRef allocator, IOOptionBits options);
|
||||||
|
|
||||||
// This routine will be called when a new (matching) device is connected.
|
// This routine will be called when a new (matching) device is connected.
|
||||||
[DllImport(hid)]
|
[DllImport(hid)]
|
||||||
|
@ -1724,6 +1734,17 @@ namespace OpenTK.Platform.MacOS
|
||||||
{
|
{
|
||||||
if (manual)
|
if (manual)
|
||||||
{
|
{
|
||||||
|
if (MouseEventTap != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
CF.CFRelease(MouseEventTap);
|
||||||
|
MouseEventTap = IntPtr.Zero;
|
||||||
|
}
|
||||||
|
if (MouseEventTapSource != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
CF.CFRelease(MouseEventTapSource);
|
||||||
|
MouseEventTapSource = IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
NativeMethods.IOHIDManagerRegisterDeviceMatchingCallback(
|
NativeMethods.IOHIDManagerRegisterDeviceMatchingCallback(
|
||||||
hidmanager, IntPtr.Zero, IntPtr.Zero);
|
hidmanager, IntPtr.Zero, IntPtr.Zero);
|
||||||
NativeMethods.IOHIDManagerRegisterDeviceRemovalCallback(
|
NativeMethods.IOHIDManagerRegisterDeviceRemovalCallback(
|
||||||
|
@ -1750,15 +1771,10 @@ namespace OpenTK.Platform.MacOS
|
||||||
HandleDeviceRemoved = null;
|
HandleDeviceRemoved = null;
|
||||||
HandleDeviceValueReceived = null;
|
HandleDeviceValueReceived = null;
|
||||||
|
|
||||||
if (MouseEventTap != IntPtr.Zero)
|
if (hidmanager != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
CF.CFRelease(MouseEventTap);
|
NativeMethods.IOHIDManagerClose(hidmanager, IOOptionBits.Zero);
|
||||||
MouseEventTap = IntPtr.Zero;
|
hidmanager = IntPtr.Zero;
|
||||||
}
|
|
||||||
if (MouseEventTapSource != IntPtr.Zero)
|
|
||||||
{
|
|
||||||
CF.CFRelease(MouseEventTapSource);
|
|
||||||
MouseEventTapSource = IntPtr.Zero;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue