-
Notifications
You must be signed in to change notification settings - Fork 30
/
VncView.MouseInput.cs
107 lines (87 loc) · 3.32 KB
/
VncView.MouseInput.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Avalonia;
using Avalonia.Input;
using MarcusW.VncClient.Protocol.Implementation.MessageTypes.Outgoing;
namespace MarcusW.VncClient.Avalonia
{
public partial class VncView
{
/// <inheritdoc />
protected override void OnPointerMoved(PointerEventArgs e)
{
base.OnPointerMoved(e);
if (e.Handled)
return;
PointerPoint point = e.GetCurrentPoint(this);
if (HandlePointerEvent(point, Vector.Zero))
e.Handled = true;
}
/// <inheritdoc />
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
if (e.Handled)
return;
PointerPoint point = e.GetCurrentPoint(this);
if (HandlePointerEvent(point, Vector.Zero))
e.Handled = true;
}
/// <inheritdoc />
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{
base.OnPointerReleased(e);
if (e.Handled)
return;
PointerPoint point = e.GetCurrentPoint(this);
if (HandlePointerEvent(point, Vector.Zero))
e.Handled = true;
}
/// <inheritdoc />
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
base.OnPointerWheelChanged(e);
if (e.Handled)
return;
PointerPoint point = e.GetCurrentPoint(this);
if (HandlePointerEvent(point, e.Delta))
e.Handled = true;
}
private bool HandlePointerEvent(PointerPoint pointerPoint, Vector wheelDelta)
{
RfbConnection? connection = Connection;
if (connection == null)
return false;
Position position = Conversions.GetPosition(pointerPoint.Position);
MouseButtons buttonsMask = GetButtonsMask(pointerPoint.Properties);
MouseButtons wheelMask = GetWheelMask(wheelDelta);
// For scrolling, set the wheel buttons and remove them quickly after that.
if (wheelMask != MouseButtons.None)
connection.EnqueueMessage(new PointerEventMessage(position, buttonsMask | wheelMask));
connection.EnqueueMessage(new PointerEventMessage(position, buttonsMask));
return true;
}
private MouseButtons GetButtonsMask(PointerPointProperties pointProperties)
{
var mask = MouseButtons.None;
if (pointProperties.IsLeftButtonPressed)
mask |= MouseButtons.Left;
if (pointProperties.IsMiddleButtonPressed)
mask |= MouseButtons.Middle;
if (pointProperties.IsRightButtonPressed)
mask |= MouseButtons.Right;
return mask;
}
private MouseButtons GetWheelMask(Vector wheelDelta)
{
var mask = MouseButtons.None;
if (wheelDelta.X > 0)
mask |= MouseButtons.WheelRight;
else if (wheelDelta.X < 0)
mask |= MouseButtons.WheelLeft;
if (wheelDelta.Y > 0)
mask |= MouseButtons.WheelUp;
else if (wheelDelta.Y < 0)
mask |= MouseButtons.WheelDown;
return mask;
}
}
}