Skip to content

Commit

Permalink
Merge pull request #3054 from gonX/06x-backport-pr3051-macos-mouse-de…
Browse files Browse the repository at this point in the history
…lta-in-absmode

[Backport] MacOS: Set mouse delta in Absolute Mode
  • Loading branch information
X9VoiD committed Dec 2, 2023
2 parents 0022f30 + 55d24f6 commit 896cad4
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Numerics;
using OpenTabletDriver.Native.OSX;
using OpenTabletDriver.Native.OSX.Input;
using OpenTabletDriver.Plugin.Platform.Pointer;

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

public MacOSAbsolutePointer()
{
Expand All @@ -21,16 +24,26 @@ public MacOSAbsolutePointer()
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;
}
}
}

0 comments on commit 896cad4

Please sign in to comment.