Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS: Set mouse delta to move and drag event #3051

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Numerics;
using OpenTabletDriver.Native.MacOS;
using OpenTabletDriver.Native.MacOS.Input;
using OpenTabletDriver.Platform.Display;
using OpenTabletDriver.Platform.Pointer;

Expand All @@ -12,6 +13,8 @@ namespace OpenTabletDriver.Desktop.Interop.Input.Absolute
public class MacOSAbsolutePointer : MacOSVirtualMouse, IAbsolutePointer
{
private Vector2 offset;
private Vector2? lastPos;
private Vector2? delta;

public MacOSAbsolutePointer(IVirtualScreen virtualScreen)
{
Expand All @@ -22,16 +25,26 @@ public MacOSAbsolutePointer(IVirtualScreen virtualScreen)
public void SetPosition(Vector2 pos)
{
var newPos = pos - offset;
delta = newPos - lastPos;
lastPos = newPos;

QueuePendingPosition(newPos.X, newPos.Y);
}

protected override void SetPendingPosition(IntPtr mouseEvent, float x, float y)
{
CGEventSetLocation(mouseEvent, new CGPoint(x, y));
if (delta is not null)
{
CGEventSetDoubleValueField(mouseEvent, CGEventField.mouseEventDeltaX, delta.Value.X);
CGEventSetDoubleValueField(mouseEvent, CGEventField.mouseEventDeltaY, delta.Value.Y);
}
}

protected override void ResetPendingPosition(IntPtr mouseEvent)
{
lastPos = null;
delta = null;
}
}
}