Skip to content

Commit

Permalink
fix: Fix timestamp issues in injected pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Nov 25, 2024
1 parent 6d2d007 commit eac09dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/Uno.UI.RuntimeTests/Helpers/UITestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Windows.System;
using Windows.UI.Input.Preview.Injection;
using Windows.UI.Popups;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
Expand Down Expand Up @@ -323,6 +324,16 @@ public string TemplateId

public static class InputInjectorExtensions
{
public static IInjectedPointer GetPointer(this InputInjector injector, PointerDeviceType pointer)
=> pointer switch
{
PointerDeviceType.Touch => GetFinger(injector),
#if !WINAPPSDK
PointerDeviceType.Mouse => GetMouse(injector),
#endif
_ => throw new NotSupportedException($"Injection of {pointer} is not supported on this platform.")
};

public static Finger GetFinger(this InputInjector injector, uint id = 42)
=> new(injector, id);

Expand All @@ -336,7 +347,7 @@ public interface IInjectedPointer
{
void Press(Point position);

void MoveTo(Point position);
void MoveTo(Point position, uint? steps = null);

void MoveBy(double deltaX = 0, double deltaY = 0);

Expand Down Expand Up @@ -400,7 +411,7 @@ public void Press(Point position)
}
}

void IInjectedPointer.MoveTo(Point position) => MoveTo(position);
void IInjectedPointer.MoveTo(Point position, uint? steps) => MoveTo(position, steps ?? _defaultMoveSteps);
public void MoveTo(Point position, uint steps = _defaultMoveSteps)
{
if (_currentPosition is { } current)
Expand Down Expand Up @@ -460,6 +471,7 @@ public static IEnumerable<InjectedInputTouchInfo> GetMove(Point fromPosition, Po
{
PointerInfo = new()
{
TimeOffsetInMilliseconds = 1,
PixelLocation = At(fromPosition.X + step * stepX, fromPosition.Y + step * stepY),
PointerOptions = InjectedInputPointerOptions.Update
| InjectedInputPointerOptions.FirstButton
Expand Down Expand Up @@ -604,7 +616,6 @@ public void ReleaseAny()
public void MoveBy(double deltaX, double deltaY)
=> Inject(GetMoveBy(deltaX, deltaY));

void IInjectedPointer.MoveTo(Point position) => MoveTo(position);
public void MoveTo(Point position, uint? steps = null)
=> Inject(GetMoveTo(position.X, position.Y, steps));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable

using System;
using Windows.Devices.Input;
using Windows.Foundation;
using Windows.System;
Expand Down Expand Up @@ -102,7 +103,7 @@ internal PointerEventArgs ToEventArgs(InjectedInputState state, VirtualKeyModifi

var point = new PointerPoint(
state.FrameId + TimeOffsetInMilliseconds,
state.Timestamp + TimeOffsetInMilliseconds,
state.Timestamp + TimeOffsetInMilliseconds * (ulong)TimeSpan.TicksPerMillisecond, // Should be microseconds, not ticks, cf. https://github.com/unoplatform/uno/issues/14535
PointerDevice.For(PointerDeviceType.Mouse),
uint.MaxValue - 42, // Try to avoid conflict with the real mouse pointer
position,
Expand Down

0 comments on commit eac09dc

Please sign in to comment.