-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrayIcon.cs
91 lines (82 loc) · 3.44 KB
/
TrayIcon.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
using H.NotifyIcon.Core;
using System.Diagnostics;
namespace PreciseThreeFingersDrag
{
internal class TrayIcon : TrayIconWithContextMenu
{
public PopupMenuItem TitleMenuItem { get; private set; }
public PopupMenuItem DelayNoneMenuItem { get; private set; }
public PopupMenuItem DelayShortMenuItem { get; private set; }
public PopupMenuItem DelayLongMenuItem { get; private set; }
public PopupMenuItem AutoStartMenuItem { get; private set; }
public PopupMenuItem QuitMenuItem { get; private set; }
public delegate void DelayChangeEvent(TouchProcessor.CooldownDelay delay);
public event DelayChangeEvent? DelayChanged;
public TrayIcon()
{
Icon = Properties.Resources.AppIcon.Handle;
UpdateName(ToolTip = "Precise Three Finger Drag");
var version = Process.GetCurrentProcess().MainModule?.FileVersionInfo.ProductVersion;
ContextMenu = new PopupMenu
{
Items =
{
(TitleMenuItem = new PopupMenuItem(
$"Precise Three Fingers Drag ({version})",
(_, _) => System.Diagnostics.Process.Start(
new System.Diagnostics.ProcessStartInfo()
{
FileName = "https://github.com/klkvsk/precise-three-fingers-drag",
UseShellExecute = true
})
)),
new PopupMenuSeparator(),
(AutoStartMenuItem = new PopupMenuItem() { Text = "Auto start on login" }),
new PopupSubMenu("Delay to keep dragging")
{
Items =
{
(DelayNoneMenuItem = new PopupMenuItem("None", DelayItem_OnClick) ),
(DelayShortMenuItem = new PopupMenuItem("Short", DelayItem_OnClick)),
(DelayLongMenuItem = new PopupMenuItem("Long", DelayItem_OnClick)),
}
},
new PopupMenuSeparator(),
(QuitMenuItem = new PopupMenuItem("Exit", (_, _) => Dispose()))
},
};
}
private void DelayItem_OnClick(object? sender, EventArgs e)
{
if (sender == null || DelayChanged == null)
{
return;
}
TouchProcessor.CooldownDelay newDelay;
if (sender == DelayNoneMenuItem)
{
newDelay = TouchProcessor.CooldownDelay.None;
}
else if (sender == DelayShortMenuItem)
{
newDelay = TouchProcessor.CooldownDelay.Short;
}
else if (sender == DelayLongMenuItem)
{
newDelay = TouchProcessor.CooldownDelay.Long;
}
else
{
return;
}
DelayChanged.Invoke(newDelay);
SetCheckedDelay(newDelay);
}
public void SetCheckedDelay(TouchProcessor.CooldownDelay delay)
{
DelayNoneMenuItem.Checked = delay == TouchProcessor.CooldownDelay.None;
DelayShortMenuItem.Checked = delay == TouchProcessor.CooldownDelay.Short;
DelayLongMenuItem.Checked = delay == TouchProcessor.CooldownDelay.Long;
}
}
}