Browse Source

Call ProcessRawEvent directly from the input manager

pull/1012/head
Nikita Tsukanov 9 years ago
parent
commit
21da2df1ec
  1. 7
      src/Avalonia.Input/IInputDevice.cs
  2. 1
      src/Avalonia.Input/InputManager.cs
  3. 12
      src/Avalonia.Input/KeyboardDevice.cs
  4. 26
      src/Avalonia.Input/MouseDevice.cs

7
src/Avalonia.Input/IInputDevice.cs

@ -1,9 +1,16 @@
// Copyright (c) The Avalonia Project. All rights reserved. // 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. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Input.Raw;
namespace Avalonia.Input namespace Avalonia.Input
{ {
public interface IInputDevice public interface IInputDevice
{ {
/// <summary>
/// Processes raw event. Is called after preprocessing by InputManager
/// </summary>
/// <param name="ev"></param>
void ProcessOwnRawEvent(RawInputEventArgs ev);
} }
} }

1
src/Avalonia.Input/InputManager.cs

@ -35,6 +35,7 @@ namespace Avalonia.Input
public void ProcessInput(RawInputEventArgs e) public void ProcessInput(RawInputEventArgs e)
{ {
_preProcess.OnNext(e); _preProcess.OnNext(e);
e.Device?.ProcessOwnRawEvent(e);
_process.OnNext(e); _process.OnNext(e);
_postProcess.OnNext(e); _postProcess.OnNext(e);
} }

12
src/Avalonia.Input/KeyboardDevice.cs

@ -16,14 +16,6 @@ namespace Avalonia.Input
{ {
private IInputElement _focusedElement; private IInputElement _focusedElement;
public KeyboardDevice()
{
InputManager.Process
.OfType<RawInputEventArgs>()
.Where(e => e.Device == this && !e.Handled)
.Subscribe(ProcessRawEvent);
}
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public static IKeyboardDevice Instance => AvaloniaLocator.Current.GetService<IKeyboardDevice>(); public static IKeyboardDevice Instance => AvaloniaLocator.Current.GetService<IKeyboardDevice>();
@ -77,8 +69,10 @@ namespace Avalonia.Input
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
private void ProcessRawEvent(RawInputEventArgs e) public void ProcessOwnRawEvent(RawInputEventArgs e)
{ {
if(e.Handled)
return;
IInputElement element = FocusedElement; IInputElement element = FocusedElement;
if (element != null) if (element != null)

26
src/Avalonia.Input/MouseDevice.cs

@ -20,18 +20,7 @@ namespace Avalonia.Input
private int _clickCount; private int _clickCount;
private Rect _lastClickRect; private Rect _lastClickRect;
private uint _lastClickTime; private uint _lastClickTime;
/// <summary>
/// Intializes a new instance of <see cref="MouseDevice"/>.
/// </summary>
public MouseDevice()
{
InputManager.Process
.OfType<RawMouseEventArgs>()
.Where(e => e.Device == this && !e.Handled)
.Subscribe(ProcessRawEvent);
}
/// <summary> /// <summary>
/// Gets the control that is currently capturing by the mouse, if any. /// Gets the control that is currently capturing by the mouse, if any.
/// </summary> /// </summary>
@ -45,12 +34,7 @@ namespace Avalonia.Input
get; get;
protected set; protected set;
} }
/// <summary>
/// Gets the application's input manager.
/// </summary>
public IInputManager InputManager => AvaloniaLocator.Current.GetService<IInputManager>();
/// <summary> /// <summary>
/// Gets the mouse position, in screen coordinates. /// Gets the mouse position, in screen coordinates.
/// </summary> /// </summary>
@ -97,6 +81,12 @@ namespace Avalonia.Input
return root.PointToClient(Position) - p; return root.PointToClient(Position) - p;
} }
public void ProcessOwnRawEvent(RawInputEventArgs e)
{
if (!e.Handled && e is RawMouseEventArgs margs)
ProcessRawEvent(margs);
}
private void ProcessRawEvent(RawMouseEventArgs e) private void ProcessRawEvent(RawMouseEventArgs e)
{ {
Contract.Requires<ArgumentNullException>(e != null); Contract.Requires<ArgumentNullException>(e != null);

Loading…
Cancel
Save