-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickPaths.cs
More file actions
1534 lines (1390 loc) · 52.3 KB
/
QuickPaths.cs
File metadata and controls
1534 lines (1390 loc) · 52.3 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// QuickPaths.cs - Desktop floating path quick-copy tool (WinForms)
// Build: build.cmd (csc.exe from .NET Framework 4.x)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Win32;
// --- JSON data contracts (keys match legacy paths.json / config.json) ---
[DataContract]
class PathItem
{
[DataMember(Name = "name")] public string Name { get; set; }
[DataMember(Name = "path")] public string ItemPath { get; set; }
}
[DataContract]
class AppConfig
{
[DataMember(Name = "left")] public int Left { get; set; }
[DataMember(Name = "top")] public int Top { get; set; }
[DataMember(Name = "claudeMode")] public bool ClaudeMode { get; set; }
[DataMember(Name = "scale")] public double Scale { get; set; }
}
// --- COM IFileOpenDialog multi-folder picker (Ctrl+click multi-select) ---
class FolderMultiPicker
{
[ComImport, Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7")]
class FileOpenDialogCOM { }
[ComImport, Guid("D57C7288-D4AD-4768-BE02-9D969532D960")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IFileOpenDialog
{
[PreserveSig] int Show(IntPtr hwndOwner);
void SetFileTypes(uint cFileTypes, IntPtr rgFilterSpec);
void SetFileTypeIndex(uint iFileType);
void GetFileTypeIndex(out uint piFileType);
void Advise(IntPtr pfde, out uint pdwCookie);
void Unadvise(uint dwCookie);
void SetOptions(uint fos);
void GetOptions(out uint pfos);
void SetDefaultFolder(IShellItem psi);
void SetFolder(IShellItem psi);
void GetFolder(out IShellItem ppsi);
void GetCurrentSelection(out IShellItem ppsi);
void SetFileName([MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
void SetTitle([MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
void SetOkButtonLabel([MarshalAs(UnmanagedType.LPWStr)] string pszText);
void SetFileNameLabel([MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
void GetResult(out IShellItem ppsi);
void AddPlace(IShellItem psi, int fdap);
void SetDefaultExtension([MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
void Close(int hr);
void SetClientGuid(ref Guid guid);
void ClearClientData();
void SetFilter(IntPtr pFilter);
void GetResults(out IShellItemArray ppenum);
void GetSelectedItems(out IntPtr ppsai);
}
[ComImport, Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IShellItem
{
void BindToHandler(IntPtr pbc, ref Guid bhid, ref Guid riid, out IntPtr ppv);
void GetParent(out IShellItem ppsi);
void GetDisplayName(uint sigdnName, [MarshalAs(UnmanagedType.LPWStr)] out string ppszName);
void GetAttributes(uint sfgaoMask, out uint psfgaoAttribs);
void Compare(IShellItem psi, uint hint, out int piOrder);
}
[ComImport, Guid("B63EA76D-1F85-456F-A19C-48159EFA858B")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IShellItemArray
{
void BindToHandler(IntPtr pbc, ref Guid bhid, ref Guid riid, out IntPtr ppv);
void GetPropertyStore(int flags, ref Guid riid, out IntPtr ppv);
void GetPropertyDescriptionList(IntPtr keyType, ref Guid riid, out IntPtr ppv);
void GetAttributes(int attribFlags, uint sfgaoMask, out uint psfgaoAttribs);
void GetCount(out uint pdwNumItems);
void GetItemAt(uint dwIndex, out IShellItem ppsi);
void EnumItems(out IntPtr ppenumShellItems);
}
public static string[] ShowDialog(string title)
{
IFileOpenDialog dialog = (IFileOpenDialog)new FileOpenDialogCOM();
try
{
uint options;
dialog.GetOptions(out options);
dialog.SetOptions(options | 0x20u | 0x200u | 0x40u);
if (!string.IsNullOrEmpty(title))
dialog.SetTitle(title);
int hr = dialog.Show(IntPtr.Zero);
if (hr != 0) return new string[0];
IShellItemArray results;
dialog.GetResults(out results);
uint count;
results.GetCount(out count);
var paths = new List<string>();
for (uint i = 0; i < count; i++)
{
IShellItem item;
results.GetItemAt(i, out item);
string path;
item.GetDisplayName(0x80058000u, out path);
if (!string.IsNullOrEmpty(path))
paths.Add(path);
}
return paths.ToArray();
}
finally
{
Marshal.ReleaseComObject(dialog);
}
}
}
// --- Double-buffered panel for flicker-free GDI+ drawing ---
class BufferedPanel : Panel
{
public BufferedPanel()
{
SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw,
true);
}
}
// --- Main application ---
class QuickPaths
{
// --- Constants ---
const int DOT_W = 88, DOT_H = 38;
const int ECG_PAD_X = 12, ECG_PAD_Y = 8;
const int ECG_WAVE_W = 60, ECG_WAVE_H = 22;
const int ECG_COUNT = 360;
const string MUTEX_NAME = @"Global\QuickPaths_Singleton";
const string REG_RUN = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
// Panel layout
const int P_PAD = 10, P_PAD_V = 8;
const int ITEM_H = 32, ITEM_GAP = 4;
const int BTN_SZ = 24, BTN_GAP = 3;
const int CLAUDE_H = 30, ADD_H = 30;
const int SEP_MT = 6, SEP_MB = 4;
const int PANEL_MIN_W = 160, PANEL_MAX_W = 280;
// --- State ---
string dir, dataFile, configFile, logFile;
List<PathItem> paths = new List<PathItem>();
bool dialogOpen, expanded, claudeMode, intentionalExit;
int exitCode = 1;
int restartCount;
DateTime startTime;
Mutex mutex;
double scale = 1.0;
// Mouse drag
bool mouseIsDown, hasDragged;
Point mouseDownScreen, formPosOnDown;
// --- UI ---
Form form;
BufferedPanel dotPanel;
Panel expandedPanel;
ToolTip toolTip;
// --- Animation ---
List<double> yValues = new List<double>();
int breathTick;
bool dotHovered, flashActive;
// --- Timers ---
System.Windows.Forms.Timer breathTimer, flashTimer, displayChangeTimer, healthTimer;
// --- System event handlers ---
PowerModeChangedEventHandler onPowerMode;
SessionSwitchEventHandler onSessionSwitch;
EventHandler onDisplayChanged;
// --- Fonts ---
Font fItem, fAdd, fClaude, fHint;
// --- Colors ---
// ECG monitor (alpha-aware, used in GDI+ painting)
Color C_MonBg, C_MonHover, C_MonBdrBlue, C_MonBdrOrange;
Color C_WaveBlue, C_WaveOrange, C_WaveGreen;
Color C_PenBlue, C_PenOrange, C_PenGreen;
// Panel (opaque, pre-blended for WinForms controls)
Color C_PanelBg, C_ItemNormal, C_ItemHover;
Color C_UpNormal, C_UpHover, C_UpText;
Color C_DelNormal, C_DelHover, C_DelText;
Color C_AddBg, C_AddHover, C_AddText;
Color C_Sep;
// Claude toggle
Color C_ClaudeOff, C_ClaudeOn, C_ClaudeHoverOff, C_ClaudeHoverOn;
Color C_ClaudeTextOff, C_ClaudeTextOn;
// Current dot drawing colors (depend on claudeMode + flash)
Color curWave, curPen, curBorder, curGlow;
// =====================================================================
// Entry point
// =====================================================================
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0)
{
string a = args[0].ToLowerInvariant();
if (a == "--install" || a == "/install") { DoInstall(); return; }
if (a == "--uninstall" || a == "/uninstall") { DoUninstall(); return; }
}
int rc = 0;
foreach (string arg in args)
if (arg.StartsWith("--restart-count="))
int.TryParse(arg.Substring(16), out rc);
if (rc > 0) Thread.Sleep(2000);
var qp = new QuickPaths();
qp.restartCount = rc;
qp.Run();
}
// =====================================================================
// Normal run
// =====================================================================
void Run()
{
// --- Singleton ---
mutex = new Mutex(false, MUTEX_NAME);
bool owned = false;
try { owned = mutex.WaitOne(0); }
catch (AbandonedMutexException) { owned = true; }
if (!owned) { Environment.ExitCode = 0; return; }
// --- Exception handling (MUST be before any Form creation) ---
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// --- Paths ---
dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
dataFile = Path.Combine(dir, "paths.json");
configFile = Path.Combine(dir, "config.json");
logFile = Path.Combine(dir, "QuickPaths.log");
startTime = DateTime.Now;
Log("QuickPaths starting (WinForms)...");
// --- Data ---
LoadPaths();
AppConfig cfg = LoadConfig();
scale = cfg.Scale > 0 ? cfg.Scale : 1.0;
// --- Colors & Fonts ---
InitColors();
InitFonts();
UpdateDotColors();
// --- Form ---
form = new Form();
form.AutoScaleMode = AutoScaleMode.Dpi;
form.FormBorderStyle = FormBorderStyle.None;
form.TopMost = true;
form.ShowInTaskbar = false;
form.StartPosition = FormStartPosition.Manual;
form.Location = new Point(cfg.Left, cfg.Top);
form.BackColor = C_MonBg;
form.TransparencyKey = Color.FromArgb(1, 0, 1);
toolTip = new ToolTip();
// --- Dot panel ---
dotPanel = new BufferedPanel();
dotPanel.Dock = DockStyle.Fill;
dotPanel.Paint += OnDotPaint;
dotPanel.MouseDown += OnDotMouseDown;
dotPanel.MouseMove += OnDotMouseMove;
dotPanel.MouseUp += OnDotMouseUp;
dotPanel.MouseWheel += OnDotMouseWheel;
dotPanel.MouseEnter += delegate { dotHovered = true; dotPanel.Invalidate(); };
dotPanel.MouseLeave += delegate { dotHovered = false; dotPanel.Invalidate(); };
dotPanel.Cursor = Cursors.Hand;
form.Controls.Add(dotPanel);
// Init waveform data
double yBot = ECG_PAD_Y + ECG_WAVE_H;
yValues.Clear();
for (int i = 0; i < ECG_COUNT; i++)
yValues.Add(yBot);
ApplyDotSize();
Log("Window built at (" + cfg.Left + ", " + cfg.Top + ")");
// --- Timers ---
breathTimer = new System.Windows.Forms.Timer();
breathTimer.Interval = 50;
breathTimer.Tick += OnBreathTick;
breathTimer.Start();
flashTimer = new System.Windows.Forms.Timer();
flashTimer.Interval = 700;
flashTimer.Tick += delegate
{
try
{
flashActive = false;
UpdateDotColors();
dotPanel.Invalidate();
flashTimer.Stop();
}
catch (Exception ex) { Log("flashTimer error: " + ex.Message); flashTimer.Stop(); }
};
displayChangeTimer = new System.Windows.Forms.Timer();
displayChangeTimer.Interval = 1500;
displayChangeTimer.Tick += delegate
{
try
{
displayChangeTimer.Stop();
Rectangle vs = SystemInformation.VirtualScreen;
int wl = form.Left, wt = form.Top;
Log("DisplayChange settled: Window=(" + wl + "," + wt
+ ") VirtualScreen=(" + vs.X + "," + vs.Y + "," + vs.Width + "," + vs.Height + ")");
if (wl < vs.Left || wl > vs.Right - 30 || wt < vs.Top || wt > vs.Bottom - 30)
{
Log("Window off-screen, resetting");
Rectangle wa = Screen.PrimaryScreen.WorkingArea;
form.Left = wa.Right - 60;
form.Top = wa.Top + (int)(wa.Height * 0.4);
SaveConfig();
}
form.TopMost = false;
form.TopMost = true;
}
catch (Exception ex) { Log("displayChangeTimer error: " + ex.Message); }
};
healthTimer = new System.Windows.Forms.Timer();
healthTimer.Interval = 300000;
healthTimer.Tick += delegate
{
try { form.TopMost = false; form.TopMost = true; }
catch (Exception ex) { Log("healthTimer error: " + ex.Message); }
};
healthTimer.Start();
// --- Click-outside-to-collapse ---
form.Deactivate += delegate
{
try { if (expanded && !dialogOpen) Collapse(); }
catch (Exception ex) { Log("Deactivate error: " + ex.Message); }
};
// --- System events ---
onPowerMode = delegate(object sender, PowerModeChangedEventArgs e)
{
try
{
if (e.Mode == PowerModes.Resume)
{
Log("System resumed from sleep");
ReassertTopmost();
}
}
catch (Exception ex) { Log("PowerModeChanged error: " + ex.Message); }
};
SystemEvents.PowerModeChanged += onPowerMode;
onSessionSwitch = delegate(object sender, SessionSwitchEventArgs e)
{
try
{
if (e.Reason == SessionSwitchReason.SessionUnlock)
{
Log("Session unlocked");
ReassertTopmost();
}
}
catch (Exception ex) { Log("SessionSwitch error: " + ex.Message); }
};
SystemEvents.SessionSwitch += onSessionSwitch;
onDisplayChanged = delegate
{
try
{
Log("Display settings changed (debouncing...)");
form.BeginInvoke((Action)delegate
{
displayChangeTimer.Stop();
displayChangeTimer.Start();
});
}
catch (Exception ex) { Log("DisplaySettingsChanged error: " + ex.Message); }
};
SystemEvents.DisplaySettingsChanged += onDisplayChanged;
// --- Form closed cleanup ---
form.FormClosed += delegate
{
Log("Form closed (intentional=" + intentionalExit + " exitCode=" + exitCode + ")");
healthTimer.Stop();
breathTimer.Stop();
displayChangeTimer.Stop();
SaveConfig();
if (intentionalExit) exitCode = 0;
try { SystemEvents.PowerModeChanged -= onPowerMode; } catch { }
try { SystemEvents.SessionSwitch -= onSessionSwitch; } catch { }
try { SystemEvents.DisplaySettingsChanged -= onDisplayChanged; } catch { }
try { mutex.ReleaseMutex(); } catch { }
DisposeFonts();
};
// --- Exception handling ---
Application.ThreadException += delegate(object sender, System.Threading.ThreadExceptionEventArgs e)
{
LogError("ThreadException", e.Exception);
LogCrashContext();
string msg = e.Exception.GetType().FullName + " " + e.Exception.Message;
bool fatal = msg.Contains("OutOfMemoryException") || msg.Contains("AccessViolation");
if (fatal)
{
Log("FATAL thread error \u2014 closing for restart");
exitCode = 2;
try { form.Close(); } catch { }
}
else
{
Log("Non-fatal thread error \u2014 handled, continuing");
}
};
AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
if (ex != null) LogError("AppDomain.UnhandledException", ex);
LogCrashContext();
exitCode = 3;
try { form.Close(); } catch { }
};
// --- Launch ---
Log("Launching...");
try
{
Application.Run(form);
}
catch (Exception ex)
{
LogError("Application.Run", ex);
LogCrashContext();
exitCode = 1;
}
Log("Exiting with code " + exitCode);
// Self-restart on crash (up to 5 attempts)
if (exitCode != 0 && restartCount < 5)
{
Log("Scheduling restart (attempt " + (restartCount + 1) + "/5)...");
try
{
Process.Start(new ProcessStartInfo
{
FileName = Assembly.GetExecutingAssembly().Location,
Arguments = "--restart-count=" + (restartCount + 1),
UseShellExecute = true
});
}
catch (Exception ex) { Log("Restart failed: " + ex.Message); }
}
Environment.ExitCode = exitCode;
}
// =====================================================================
// Dot sizing & region
// =====================================================================
void ApplyDotSize()
{
int w = (int)(DOT_W * scale);
int h = (int)(DOT_H * scale);
form.ClientSize = new Size(w, h);
form.Region = null;
form.BackColor = form.TransparencyKey;
}
static Region MakeRoundedRegion(int w, int h, int r)
{
if (r < 1) r = 1;
var path = new GraphicsPath();
int d = r * 2;
path.AddArc(0, 0, d, d, 180, 90);
path.AddArc(w - d, 0, d, d, 270, 90);
path.AddArc(w - d, h - d, d, d, 0, 90);
path.AddArc(0, h - d, d, d, 90, 90);
path.CloseFigure();
return new Region(path);
}
// =====================================================================
// Dot painting (GDI+)
// =====================================================================
void OnDotPaint(object sender, PaintEventArgs e)
{
try
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.Clear(form.TransparencyKey);
float s = (float)scale;
int w = dotPanel.Width;
int h = dotPanel.Height;
int cr = (int)(6 * s);
// Background
Color bg = dotHovered ? C_MonHover : C_MonBg;
using (var bgPath = MakeRoundedRectPath(0, 0, w, h, cr))
using (var bgBrush = new SolidBrush(bg))
{
g.FillPath(bgBrush, bgPath);
}
// Border
using (var bdrPath = MakeRoundedRectPath(0, 0, w - 1, h - 1, cr))
using (var bdrPen = new Pen(curBorder, 1f))
{
g.DrawPath(bdrPen, bdrPath);
}
// Waveform
float padX = ECG_PAD_X * s;
float padY = ECG_PAD_Y * s;
float waveW = ECG_WAVE_W * s;
float waveH = ECG_WAVE_H * s;
if (yValues.Count >= 2)
{
var pts = new PointF[ECG_COUNT];
for (int i = 0; i < ECG_COUNT; i++)
{
float x = padX + waveW * (float)i / (ECG_COUNT - 1);
float y = (float)(yValues[i] * s);
pts[i] = new PointF(x, y);
}
using (var wavePen = new Pen(curWave, 1.5f * s))
{
g.DrawLines(wavePen, pts);
}
}
// Pen head position
float headY = (float)(yValues[yValues.Count - 1] * s);
float headX = padX + waveW;
float headR = 3f * s;
// Glow layers
float breathVal = (float)GetCurrentBreathValue();
// Outer glow (30px unscaled)
float glow2R = 15f * s;
float glow2Alpha = (float)(0.08 + 0.30 * breathVal);
DrawGlow(g, headX, headY, glow2R, curGlow, glow2Alpha);
// Inner glow (16px unscaled)
float glow1R = 8f * s;
float glow1Alpha = (float)(0.18 + 0.50 * breathVal);
DrawGlow(g, headX, headY, glow1R, curGlow, glow1Alpha);
// Pen head circle
float shadowAlpha = (float)(0.4 + 0.55 * breathVal);
// Shadow (slightly larger, semi-transparent)
using (var shadowBrush = new SolidBrush(Color.FromArgb((int)(shadowAlpha * 120), curGlow)))
{
float sr = headR + 4f * s;
g.FillEllipse(shadowBrush, headX - sr, headY - sr, sr * 2, sr * 2);
}
// Head
using (var headBrush = new SolidBrush(curPen))
{
g.FillEllipse(headBrush, headX - headR, headY - headR, headR * 2, headR * 2);
}
}
catch (Exception ex)
{
Log("OnDotPaint error: " + ex.Message);
}
}
void DrawGlow(Graphics g, float cx, float cy, float radius, Color color, float alpha)
{
if (radius < 1f || alpha < 0.01f) return;
RectangleF rect = new RectangleF(cx - radius, cy - radius, radius * 2, radius * 2);
using (var path = new GraphicsPath())
{
path.AddEllipse(rect);
try
{
using (var brush = new PathGradientBrush(path))
{
int a = (int)Math.Min(255, alpha * 255);
brush.CenterColor = Color.FromArgb(a, color);
brush.SurroundColors = new Color[] { Color.FromArgb(0, color) };
g.FillPath(brush, path);
}
}
catch { } // PathGradientBrush can fail on degenerate paths
}
}
static GraphicsPath MakeRoundedRectPath(int x, int y, int w, int h, int r)
{
var path = new GraphicsPath();
int d = r * 2;
if (d > w) d = w;
if (d > h) d = h;
path.AddArc(x, y, d, d, 180, 90);
path.AddArc(x + w - d, y, d, d, 270, 90);
path.AddArc(x + w - d, y + h - d, d, d, 0, 90);
path.AddArc(x, y + h - d, d, d, 90, 90);
path.CloseFigure();
return path;
}
double GetCurrentBreathValue()
{
int k = breathTick;
if (k < 80)
return (1 - Math.Cos(k / 80.0 * Math.PI)) / 2;
else if (k < 160)
return 1.0;
else if (k < 320)
return (1 + Math.Cos((k - 160) / 160.0 * Math.PI)) / 2;
else
return 0.0;
}
// =====================================================================
// Breath animation timer
// =====================================================================
void OnBreathTick(object sender, EventArgs e)
{
try
{
breathTick++;
if (breathTick >= 360) breathTick = 0;
double v = GetCurrentBreathValue();
double y = ECG_PAD_Y + ECG_WAVE_H * (1 - v);
yValues.RemoveAt(0);
yValues.Add(y);
if (!expanded)
dotPanel.Invalidate();
}
catch (Exception ex)
{
Log("breathTimer error: " + ex.Message);
breathTimer.Stop();
}
}
// =====================================================================
// Dot mouse events
// =====================================================================
void OnDotMouseDown(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Left)
{
mouseIsDown = true;
mouseDownScreen = Control.MousePosition;
formPosOnDown = form.Location;
hasDragged = false;
}
}
catch { }
}
void OnDotMouseMove(object sender, MouseEventArgs e)
{
try
{
if (mouseIsDown && e.Button == MouseButtons.Left)
{
Point cur = Control.MousePosition;
int dx = cur.X - mouseDownScreen.X;
int dy = cur.Y - mouseDownScreen.Y;
if (!hasDragged && (Math.Abs(dx) > 5 || Math.Abs(dy) > 5))
hasDragged = true;
if (hasDragged)
form.Location = new Point(formPosOnDown.X + dx, formPosOnDown.Y + dy);
}
}
catch (Exception ex) { Log("dot.MouseMove error: " + ex.Message); }
}
void OnDotMouseUp(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Left)
{
if (!hasDragged)
Expand();
else
SaveConfig();
mouseIsDown = false;
}
else if (e.Button == MouseButtons.Right)
{
var r = MessageBox.Show(
"\u9000\u51FA QuickPaths\uFF1F", "\u786E\u8BA4",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (r == DialogResult.Yes)
{
intentionalExit = true;
exitCode = 0;
form.Close();
}
}
}
catch (Exception ex) { Log("dot.MouseUp error: " + ex.Message); }
}
void OnDotMouseWheel(object sender, MouseEventArgs e)
{
try
{
double delta = e.Delta > 0 ? 0.1 : -0.1;
double ns = Math.Round(scale + delta, 1);
ns = Math.Max(0.5, Math.Min(3.0, ns));
scale = ns;
ApplyDotSize();
dotPanel.Invalidate();
SaveConfig();
}
catch (Exception ex) { Log("dot.MouseWheel error: " + ex.Message); }
}
// =====================================================================
// UI state transitions
// =====================================================================
void Collapse()
{
expanded = false;
form.SuspendLayout();
if (expandedPanel != null)
{
form.Controls.Remove(expandedPanel);
expandedPanel.Dispose();
expandedPanel = null;
}
dotPanel.Visible = true;
ApplyDotSize();
form.ResumeLayout(true);
}
void Expand()
{
expanded = true;
form.SuspendLayout();
dotPanel.Visible = false;
RebuildList();
form.ResumeLayout(true);
form.Activate();
}
void FlashDot()
{
flashTimer.Stop();
flashActive = true;
curWave = C_WaveGreen;
curPen = C_PenGreen;
dotPanel.Invalidate();
flashTimer.Start();
}
void ReassertTopmost()
{
form.BeginInvoke((Action)delegate
{
form.TopMost = false;
form.TopMost = true;
});
}
void UpdateDotColors()
{
if (flashActive) return; // don't override flash
if (claudeMode)
{
curBorder = C_MonBdrOrange;
curWave = C_WaveOrange;
curPen = C_PenOrange;
curGlow = Color.FromArgb(217, 119, 87);
}
else
{
curBorder = C_MonBdrBlue;
curWave = C_WaveBlue;
curPen = C_PenBlue;
curGlow = Color.FromArgb(106, 155, 204);
}
}
// =====================================================================
// Rebuild path list panel
// =====================================================================
void PromoteRecentItem(string clickedPath)
{
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if (string.Equals(clickedPath, desktopPath, StringComparison.OrdinalIgnoreCase)) return;
int ci = -1;
for (int i = 0; i < paths.Count; i++)
if (paths[i].ItemPath == clickedPath) { ci = i; break; }
if (ci < 0) return;
bool desktopAtZero = paths.Count > 0 &&
string.Equals(paths[0].ItemPath, desktopPath, StringComparison.OrdinalIgnoreCase);
int insertAt = desktopAtZero ? 1 : 0;
if (ci == insertAt) return;
var item = paths[ci];
paths.RemoveAt(ci);
if (insertAt > paths.Count) insertAt = paths.Count;
paths.Insert(insertAt, item);
SavePaths();
}
bool EnsureDesktopFirst()
{
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
for (int i = 1; i < paths.Count; i++)
{
if (string.Equals(paths[i].ItemPath, desktopPath, StringComparison.OrdinalIgnoreCase))
{
var desktop = paths[i];
paths.RemoveAt(i);
paths.Insert(0, desktop);
return true;
}
}
return false;
}
void RebuildList()
{
// Prune invalid paths
int removed = 0;
for (int i = paths.Count - 1; i >= 0; i--)
{
if (!Directory.Exists(paths[i].ItemPath))
{
Log("Pruned: " + paths[i].Name + " (path gone)");
paths.RemoveAt(i);
removed++;
}
}
if (removed > 0) SavePaths();
if (EnsureDesktopFirst()) SavePaths();
// Remove old panel
if (expandedPanel != null)
{
form.Controls.Remove(expandedPanel);
expandedPanel.Dispose();
}
expandedPanel = new Panel();
expandedPanel.BackColor = C_PanelBg;
expandedPanel.Dock = DockStyle.Fill;
// Calculate panel width
int panelW = PANEL_MIN_W;
foreach (var p in paths)
{
int tw = TextRenderer.MeasureText(p.Name, fItem).Width;
int rowW = P_PAD + tw + 20 + BTN_GAP + BTN_SZ + BTN_GAP + BTN_SZ + P_PAD;
if (rowW > panelW) panelW = rowW;
}
panelW = Math.Max(PANEL_MIN_W, Math.Min(PANEL_MAX_W, panelW));
int contentW = panelW - P_PAD * 2;
int y = P_PAD_V;
// --- Claude mode toggle ---
var claudeBtn = new Label();
claudeBtn.Text = "Claude";
claudeBtn.Font = fClaude;
claudeBtn.TextAlign = ContentAlignment.MiddleCenter;
claudeBtn.Cursor = Cursors.Hand;
claudeBtn.SetBounds(P_PAD, y, contentW, CLAUDE_H);
claudeBtn.BackColor = claudeMode ? C_ClaudeOn : C_ClaudeOff;
claudeBtn.ForeColor = claudeMode ? C_ClaudeTextOn : C_ClaudeTextOff;
claudeBtn.MouseEnter += delegate(object s, EventArgs ev)
{
((Label)s).BackColor = claudeMode ? C_ClaudeHoverOn : C_ClaudeHoverOff;
};
claudeBtn.MouseLeave += delegate(object s, EventArgs ev)
{
((Label)s).BackColor = claudeMode ? C_ClaudeOn : C_ClaudeOff;
};
claudeBtn.Click += delegate
{
claudeMode = !claudeMode;
SaveConfig();
UpdateDotColors();
RebuildList();
};
expandedPanel.Controls.Add(claudeBtn);
y += CLAUDE_H + ITEM_GAP;
// --- Empty hint ---
if (paths.Count == 0)
{
var hint = new Label();
hint.Text = "\u70B9\u51FB + ";
hint.Font = fHint;
hint.ForeColor = Color.FromArgb(140, 140, 140);
hint.BackColor = C_PanelBg;
hint.TextAlign = ContentAlignment.MiddleCenter;
hint.SetBounds(P_PAD, y, contentW, 20);
expandedPanel.Controls.Add(hint);
y += 20 + ITEM_GAP;
}
// --- Path items ---
for (int idx = 0; idx < paths.Count; idx++)
{
PathItem item = paths[idx];
int btnY = y + (ITEM_H - BTN_SZ) / 2;
int rightEdge = P_PAD + contentW;
// Delete button
var del = new Label();
del.Text = "\u2212";
del.Font = fItem;
del.ForeColor = C_DelText;
del.BackColor = C_DelNormal;
del.TextAlign = ContentAlignment.MiddleCenter;
del.Cursor = Cursors.Hand;
del.Tag = item.ItemPath;
del.SetBounds(rightEdge - BTN_SZ, btnY, BTN_SZ, BTN_SZ);
del.MouseEnter += delegate(object s, EventArgs ev) { ((Label)s).BackColor = C_DelHover; };
del.MouseLeave += delegate(object s, EventArgs ev) { ((Label)s).BackColor = C_DelNormal; };
del.Click += delegate(object s, EventArgs ev)
{
string target = (string)((Label)s).Tag;
for (int i = paths.Count - 1; i >= 0; i--)
{
if (paths[i].ItemPath == target) { paths.RemoveAt(i); break; }
}
SavePaths();
RebuildList();
};
expandedPanel.Controls.Add(del);
int nameRight = rightEdge - BTN_SZ - BTN_GAP;
// Move-up button
if (idx > 0)
{
var up = new Label();
up.Text = "\u2191";
up.Font = fItem;
up.ForeColor = C_UpText;
up.BackColor = C_UpNormal;
up.TextAlign = ContentAlignment.MiddleCenter;