diff --git a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs index 4ae61ca9..45975680 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonBindings/CarbonAPI.cs @@ -99,6 +99,14 @@ namespace OpenTK.Platform.MacOS.Carbon { public float X; public float Y; + public HIPoint(float x, float y) + { + X = x; + Y = y; + } + public HIPoint(double x, double y) + : this((float)x, (float)y) + { } } [StructLayout(LayoutKind.Sequential)] internal struct HISize diff --git a/Source/OpenTK/Platform/MacOS/CarbonBindings/QuartzDisplayServicesAPI.cs b/Source/OpenTK/Platform/MacOS/CarbonBindings/QuartzDisplayServicesAPI.cs index d241a3d6..f15d1a20 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonBindings/QuartzDisplayServicesAPI.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonBindings/QuartzDisplayServicesAPI.cs @@ -12,6 +12,21 @@ namespace OpenTK.Platform.MacOS.Carbon } + enum CGError + { + Success = 0, + Failure = 1000, + IllegalArgument = 1001, + InvalidConnection = 1002, + InvalidContext = 1003, + CannotComplete = 1004, + NotImplemented = 1006, + RangeCheck = 1007, + TypeCheck = 1008, + InvalidOperation = 1010, + NoneAvailable = 1011, + } + internal static class CG { const string appServices = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices"; @@ -50,5 +65,7 @@ namespace OpenTK.Platform.MacOS.Carbon [DllImport(appServices, EntryPoint = "CGDisplaySwitchToMode")] internal static extern IntPtr DisplaySwitchToMode(IntPtr display, IntPtr displayMode); + [DllImport(appServices, EntryPoint = "CGWarpMouseCursorPosition")] + internal static extern CGError WarpMouseCursorPosition(HIPoint newCursorPosition); } } diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs index dabcc218..af160203 100755 --- a/Source/OpenTK/Platform/MacOS/HIDInput.cs +++ b/Source/OpenTK/Platform/MacOS/HIDInput.cs @@ -48,6 +48,8 @@ namespace OpenTK.Platform.MacOS using IOOptionBits = System.IntPtr; using IOReturn = System.IntPtr; + // Requires Mac OS X 10.5 or higher. + // Todo: create a driver for older installations. Maybe use CGGetLastMouseDelta for that? class HIDInput : IMouseDriver2 { #region Fields @@ -195,7 +197,7 @@ namespace OpenTK.Platform.MacOS #region IMouseDriver2 Members - public MouseState GetState() + MouseState IMouseDriver2.GetState() { MouseState master = new MouseState(); foreach (KeyValuePair item in MouseDevices) @@ -206,7 +208,7 @@ namespace OpenTK.Platform.MacOS return master; } - public MouseState GetState(int index) + MouseState IMouseDriver2.GetState(int index) { IntPtr device; if (MouseIndexToDevice.TryGetValue(index, out device)) @@ -217,8 +219,9 @@ namespace OpenTK.Platform.MacOS return new MouseState(); } - public void SetPosition(double x, double y) + void IMouseDriver2.SetPosition(double x, double y) { + CG.WarpMouseCursorPosition(new Carbon.HIPoint(x, y)); } #endregion