-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
169 lines (144 loc) · 4.87 KB
/
Program.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using Linearstar.Windows.RawInput;
using Linearstar.Windows.RawInput.Native;
using System.Configuration;
///ref
namespace PreciseThreeFingersDrag
{
internal static class Program
{
private static TrayIcon? ui;
private static InputMessageLoop? input;
private static TouchProcessor? touch;
public static Configuration GetConfig()
{
return ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
}
[STAThread]
private static void Main()
{
ui = new TrayIcon();
input = new InputMessageLoop(OnInputEvent);
touch = new TouchProcessor();
var createdNew = false;
new Mutex(true, "precise-three-fingers-drag", out createdNew);
if (!createdNew)
{
return;
}
var hwnd = input.Create();
touch.Register(hwnd);
touch.StateChange += Touch_StateChange;
ui.Created += Ui_Created;
ui.QuitMenuItem.Click += Quit;
ui.UseStandardTooltip = true;
ui.Create();
input.HwndThread?.Join();
}
private static void Ui_Created(object? sender, EventArgs e)
{
if (ui == null)
{
throw new NullReferenceException();
}
ui.AutoStartMenuItem.Checked = AutostartHelper.IsEnabled;
ui.AutoStartMenuItem.Click += Ui_AutostartToggle;
ui.DelayChanged += Ui_DelayChanged;
Configuration config = GetConfig();
KeyValueConfigurationElement delayCfg = config.AppSettings.Settings["delay"];
TouchProcessor.CooldownDelay delay = TouchProcessor.CooldownDelay.Long;
if (delayCfg == null)
{
config.AppSettings.Settings.Add(new KeyValueConfigurationElement("delay", ((uint)delay).ToString()));
config.Save();
}
else
{
if (Enum.TryParse(delayCfg.Value, out TouchProcessor.CooldownDelay storedDelay))
{
delay = storedDelay;
}
else
{
// clean up unparseable value
config.AppSettings.Settings.Remove("delay");
config.Save();
}
}
if (touch != null)
{
touch.DragCooldownDelay = delay;
}
ui.SetCheckedDelay(delay);
}
private static void Ui_DelayChanged(TouchProcessor.CooldownDelay delay)
{
if (touch != null)
{
touch.DragCooldownDelay = delay;
}
Configuration config = GetConfig();
KeyValueConfigurationElement? delayCfg = config.AppSettings.Settings["delay"];
if (delayCfg == null)
{
delayCfg = new KeyValueConfigurationElement("delay", ((uint)delay).ToString());
config.AppSettings.Settings.Add(delayCfg);
}
else
{
delayCfg.Value = ((uint)delay).ToString();
}
config.Save();
}
private static void Ui_AutostartToggle(object? sender, EventArgs e)
{
if (ui == null)
{
return;
}
if (AutostartHelper.IsEnabled)
{
AutostartHelper.Disable();
ui.ShowNotification(
"Autostart is OFF",
"Precise Three Fingers Drag is removed from autostart.",
timeout: TimeSpan.FromMilliseconds(1500)
);
}
else
{
AutostartHelper.Enable();
ui.ShowNotification(
"Autostart is ON",
"Precise Three Fingers Drag will start with your system.",
timeout: TimeSpan.FromMilliseconds(1500)
);
}
ui.AutoStartMenuItem.Checked = AutostartHelper.IsEnabled;
}
private static void Quit(object? sender, EventArgs e)
{
input?.Dispose();
touch?.Dispose();
}
private static void OnInputEvent(nint lParam)
{
if (touch == null)
{
return;
}
RawInputData data = RawInputData.FromHandle(lParam);
if (data is RawInputDigitizerData digitizerData)
{
touch.Update(digitizerData);
}
if (data is RawInputMouseData mouseData)
{
touch.Update(mouseData);
}
}
private static void Touch_StateChange(object sender, TouchProcessor.State newState)
{
//Debug.WriteLine(newState);
}
}
}