Browse Source

Merge pull request #4899 from AvaloniaUI/xi2-leave-event

Pointerover fixes
Nikita Tsukanov 5 năm trước cách đây
mục cha
commit
78fb13566c
2 tập tin đã thay đổi với 25 bổ sung5 xóa
  1. 16 4
      src/Avalonia.Input/MouseDevice.cs
  2. 9 1
      src/Avalonia.X11/XI2Manager.cs

+ 16 - 4
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
         /// <summary>
         /// Gets the mouse position, in screen coordinates.
         /// </summary>
+        [Obsolete("Use events instead")]
         public PixelPoint Position
         {
-            get;
-            protected set;
+            get => _position ?? new PixelPoint(-1, -1);
+            protected set => _position = value;
         }
 
         /// <summary>
@@ -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);
         }
 

+ 9 - 1
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;