diff --git a/src/Avalonia.Input/MouseDevice.cs b/src/Avalonia.Input/MouseDevice.cs
index cec5029c18..5c63546f5d 100644
--- a/src/Avalonia.Input/MouseDevice.cs
+++ b/src/Avalonia.Input/MouseDevice.cs
@@ -19,6 +19,7 @@ namespace Avalonia.Input
private readonly Pointer _pointer;
private bool _disposed;
+ private PixelPoint? _position;
public MouseDevice(Pointer? pointer = null)
{
@@ -39,10 +40,11 @@ namespace Avalonia.Input
///
/// Gets the mouse position, in screen coordinates.
///
+ [Obsolete("Use events instead")]
public PixelPoint Position
{
- get;
- protected set;
+ get => _position ?? new PixelPoint(-1, -1);
+ protected set => _position = value;
}
///
@@ -91,7 +93,16 @@ namespace Avalonia.Input
public void SceneInvalidated(IInputRoot root, Rect rect)
{
- var clientPoint = root.PointToClient(Position);
+ // Pointer is outside of the target area
+ if (_position == null )
+ {
+ if (root.PointerOverElement != null)
+ ClearPointerOver(this, 0, root, PointerPointProperties.None, KeyModifiers.None);
+ return;
+ }
+
+
+ var clientPoint = root.PointToClient(_position.Value);
if (rect.Contains(clientPoint))
{
@@ -132,7 +143,7 @@ namespace Avalonia.Input
if(mouse._disposed)
return;
- Position = e.Root.PointToScreen(e.Position);
+ _position = e.Root.PointToScreen(e.Position);
var props = CreateProperties(e);
var keyModifiers = KeyModifiersUtils.ConvertToKey(e.InputModifiers);
switch (e.Type)
@@ -176,6 +187,7 @@ namespace Avalonia.Input
device = device ?? throw new ArgumentNullException(nameof(device));
root = root ?? throw new ArgumentNullException(nameof(root));
+ _position = null;
ClearPointerOver(this, timestamp, root, properties, inputModifiers);
}
diff --git a/src/Avalonia.X11/XI2Manager.cs b/src/Avalonia.X11/XI2Manager.cs
index 742973e0da..9349824525 100644
--- a/src/Avalonia.X11/XI2Manager.cs
+++ b/src/Avalonia.X11/XI2Manager.cs
@@ -162,7 +162,9 @@ namespace Avalonia.X11
| XEventMask.Button4MotionMask
| XEventMask.Button5MotionMask
| XEventMask.ButtonPressMask
- | XEventMask.ButtonReleaseMask;
+ | XEventMask.ButtonReleaseMask
+ | XEventMask.LeaveWindowMask
+ | XEventMask.EnterWindowMask;
}
public void OnWindowDestroyed(IntPtr xid) => _clients.Remove(xid);
@@ -201,6 +203,12 @@ namespace Avalonia.X11
return;
}
+ if (ev.Type == XiEventType.XI_Leave)
+ {
+ client.ScheduleXI2Input(new RawPointerEventArgs(client.MouseDevice, ev.Timestamp, client.InputRoot,
+ RawPointerEventType.LeaveWindow, ev.Position, ev.Modifiers));
+ }
+
if (_multitouch && ev.Emulated)
return;