diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs index e2014c41..4c3e4541 100755 --- a/Source/OpenTK/Platform/MacOS/HIDInput.cs +++ b/Source/OpenTK/Platform/MacOS/HIDInput.cs @@ -1756,13 +1756,11 @@ namespace OpenTK.Platform.MacOS { if (manual) { - if (MouseEventTap != IntPtr.Zero) - { - CF.CFRelease(MouseEventTap); - MouseEventTap = IntPtr.Zero; - } if (MouseEventTapSource != IntPtr.Zero) { + // Note: releasing the mach port (tap source) + // automatically releases the event tap. + CF.RunLoopRemoveSource(RunLoop, MouseEventTapSource, CF.RunLoopModeDefault); CF.CFRelease(MouseEventTapSource); MouseEventTapSource = IntPtr.Zero; } diff --git a/Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs b/Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs index 262fd7f5..a11b9b9b 100644 --- a/Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs +++ b/Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs @@ -233,5 +233,11 @@ namespace OpenTK.Platform.MacOS.Carbon CFRunLoopRef rl, CFRunLoopSourceRef source, CFStringRef mode); + + [DllImport(appServices, EntryPoint = "CFRunLoopRemoveSource")] + internal static extern void RunLoopRemoveSource( + CFRunLoopRef rl, + CFRunLoopSourceRef source, + CFStringRef mode); } }