From 21da2df1ec4d9c52386f5cb41957e811df8aa2ce Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Mon, 5 Jun 2017 21:51:08 +0300 Subject: [PATCH] Call ProcessRawEvent directly from the input manager --- src/Avalonia.Input/IInputDevice.cs | 7 +++++++ src/Avalonia.Input/InputManager.cs | 1 + src/Avalonia.Input/KeyboardDevice.cs | 12 +++--------- src/Avalonia.Input/MouseDevice.cs | 26 ++++++++------------------ 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/Avalonia.Input/IInputDevice.cs b/src/Avalonia.Input/IInputDevice.cs index 916f29376a..5a47504b1b 100644 --- a/src/Avalonia.Input/IInputDevice.cs +++ b/src/Avalonia.Input/IInputDevice.cs @@ -1,9 +1,16 @@ // Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. +using Avalonia.Input.Raw; + namespace Avalonia.Input { public interface IInputDevice { + /// + /// Processes raw event. Is called after preprocessing by InputManager + /// + /// + void ProcessOwnRawEvent(RawInputEventArgs ev); } } diff --git a/src/Avalonia.Input/InputManager.cs b/src/Avalonia.Input/InputManager.cs index 7aa609e65c..b9aacb6a4b 100644 --- a/src/Avalonia.Input/InputManager.cs +++ b/src/Avalonia.Input/InputManager.cs @@ -35,6 +35,7 @@ namespace Avalonia.Input public void ProcessInput(RawInputEventArgs e) { _preProcess.OnNext(e); + e.Device?.ProcessOwnRawEvent(e); _process.OnNext(e); _postProcess.OnNext(e); } diff --git a/src/Avalonia.Input/KeyboardDevice.cs b/src/Avalonia.Input/KeyboardDevice.cs index 51af01f69b..aa90dd1772 100644 --- a/src/Avalonia.Input/KeyboardDevice.cs +++ b/src/Avalonia.Input/KeyboardDevice.cs @@ -16,14 +16,6 @@ namespace Avalonia.Input { private IInputElement _focusedElement; - public KeyboardDevice() - { - InputManager.Process - .OfType() - .Where(e => e.Device == this && !e.Handled) - .Subscribe(ProcessRawEvent); - } - public event PropertyChangedEventHandler PropertyChanged; public static IKeyboardDevice Instance => AvaloniaLocator.Current.GetService(); @@ -77,8 +69,10 @@ namespace Avalonia.Input PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - private void ProcessRawEvent(RawInputEventArgs e) + public void ProcessOwnRawEvent(RawInputEventArgs e) { + if(e.Handled) + return; IInputElement element = FocusedElement; if (element != null) diff --git a/src/Avalonia.Input/MouseDevice.cs b/src/Avalonia.Input/MouseDevice.cs index 383032c625..9fba5799b5 100644 --- a/src/Avalonia.Input/MouseDevice.cs +++ b/src/Avalonia.Input/MouseDevice.cs @@ -20,18 +20,7 @@ namespace Avalonia.Input private int _clickCount; private Rect _lastClickRect; private uint _lastClickTime; - - /// - /// Intializes a new instance of . - /// - public MouseDevice() - { - InputManager.Process - .OfType() - .Where(e => e.Device == this && !e.Handled) - .Subscribe(ProcessRawEvent); - } - + /// /// Gets the control that is currently capturing by the mouse, if any. /// @@ -45,12 +34,7 @@ namespace Avalonia.Input get; protected set; } - - /// - /// Gets the application's input manager. - /// - public IInputManager InputManager => AvaloniaLocator.Current.GetService(); - + /// /// Gets the mouse position, in screen coordinates. /// @@ -97,6 +81,12 @@ namespace Avalonia.Input return root.PointToClient(Position) - p; } + public void ProcessOwnRawEvent(RawInputEventArgs e) + { + if (!e.Handled && e is RawMouseEventArgs margs) + ProcessRawEvent(margs); + } + private void ProcessRawEvent(RawMouseEventArgs e) { Contract.Requires(e != null);