Repository navigation
Expand file tree
/
Copy pathchanges_utf8.patch
More file actions
754 lines (718 loc) · 34.4 KB
/
Copy pathchanges_utf8.patch
File metadata and controls
754 lines (718 loc) · 34.4 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
diff --git a/App.xaml.cs b/App.xaml.cs
index 4775b06..847577f 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -205,8 +205,11 @@ namespace DesktopNotes
{
try
{
- if (!note.IsAlwaysOnTop)
+ if (!note.IsAlwaysOnTop && !note.IsClickThrough)
+ {
_desktopWindowService.AttachWindow(window);
+ RefreshDesktopZOrder();
+ }
}
catch (Exception ex) { Trace($"Attach error: {ex.Message}"); }
};
@@ -217,10 +220,15 @@ namespace DesktopNotes
// Always-on-Top toggle: attach/detach from desktop
window.AlwaysOnTopChanged += (s, _) =>
{
- if (note.IsAlwaysOnTop)
+ if (note.IsAlwaysOnTop || note.IsClickThrough)
+ {
_desktopWindowService.DetachWindow(window);
+ }
else
+ {
_desktopWindowService.AttachWindow(window);
+ RefreshDesktopZOrder();
+ }
};
// Note actions
@@ -275,10 +283,40 @@ namespace DesktopNotes
/// </summary>
internal void CloseNoteWindow(NoteWindow window)
{
+ // If the note has no content and title is default, delete it permanently instead of just closing it
+ bool isEmpty = string.IsNullOrWhiteSpace(window.NoteModel.Text) &&
+ window.NoteModel.Title == "New Note";
+
+ if (isEmpty)
+ {
+ DeleteNoteWindow(window);
+ return;
+ }
+
window.NoteModel.IsClosed = true;
_activeNoteWindows.Remove(window);
window.Close();
OnNotesStateChanged();
+ RefreshDesktopZOrder();
+ }
+
+ /// <summary>
+ /// Reorders all desktop-attached notes so that newer notes appear above older notes,
+ /// while keeping all of them behind normal applications.
+ /// </summary>
+ internal void RefreshDesktopZOrder()
+ {
+ // Iterate from newest to oldest.
+ // Pushing a note to HWND_BOTTOM puts it under all previously pushed notes.
+ // By pushing the newest first, it ends up above the older notes.
+ for (int i = _activeNoteWindows.Count - 1; i >= 0; i--)
+ {
+ var window = _activeNoteWindows[i];
+ if (!window.NoteModel.IsAlwaysOnTop && !window.NoteModel.IsClickThrough)
+ {
+ window.SetDesktopZOrder(DesktopNotes.Interop.NativeMethods.HWND_BOTTOM);
+ }
+ }
}
/// <summary>
@@ -619,7 +657,7 @@ namespace DesktopNotes
{
foreach (var window in _activeNoteWindows)
{
- if (!window.NoteModel.IsAlwaysOnTop)
+ if (!window.NoteModel.IsAlwaysOnTop && !window.NoteModel.IsClickThrough)
{
_desktopWindowService.AttachWindow(window);
}
diff --git a/Interop/NativeMethods.cs b/Interop/NativeMethods.cs
index d840ad6..0a43ecf 100644
--- a/Interop/NativeMethods.cs
+++ b/Interop/NativeMethods.cs
@@ -64,6 +64,18 @@ namespace DesktopNotes.Interop
IntPtr hWnd, IntPtr hWndInsertAfter,
int X, int Y, int cx, int cy, uint uFlags);
+ [StructLayout(LayoutKind.Sequential)]
+ public struct WINDOWPOS
+ {
+ public IntPtr hwnd;
+ public IntPtr hwndInsertAfter;
+ public int x;
+ public int y;
+ public int cx;
+ public int cy;
+ public uint flags;
+ }
+
// --- Global hotkeys ---
[DllImport("user32.dll", SetLastError = true)]
diff --git a/Models/Note.cs b/Models/Note.cs
index d58362b..9377773 100644
--- a/Models/Note.cs
+++ b/Models/Note.cs
@@ -78,6 +78,14 @@ namespace DesktopNotes.Models
/// </summary>
public bool IsLocked { get; set; } = false;
+ /// <summary>
+ /// When <c>true</c> all mouse input passes through the note to the window beneath,
+ /// except for the reserved click-through handle region (top-left corner).
+ /// Forces <see cref="IsAlwaysOnTop"/> = true when enabled.
+ /// Toggle via right-click context menu or by clicking the on-canvas pin handle.
+ /// </summary>
+ public bool IsClickThrough { get; set; } = false;
+
/// <summary>UTC timestamp of when this note was first created.</summary>
public DateTime CreatedAt { get; set; } = DateTime.Now;
diff --git a/Services/DesktopWindowService.cs b/Services/DesktopWindowService.cs
index aaaa209..7195370 100644
--- a/Services/DesktopWindowService.cs
+++ b/Services/DesktopWindowService.cs
@@ -119,6 +119,10 @@ namespace DesktopNotes.Services
style &= ~NativeMethods.WS_EX_APPWINDOW; // remove APPWINDOW if present
NativeMethods.SetWindowLongPtr(hwnd, NativeMethods.GWL_EXSTYLE, new IntPtr(style));
+ // Explicitly push it to the bottom behind normal windows
+ NativeMethods.SetWindowPos(hwnd, NativeMethods.HWND_BOTTOM, 0, 0, 0, 0,
+ NativeMethods.SWP_NOMOVE | NativeMethods.SWP_NOSIZE | NativeMethods.SWP_NOACTIVATE);
+
Debug.WriteLine($"Attached window 0x{hwnd:X} to WorkerW 0x{WorkerWHandle:X}");
return true;
}
diff --git a/Views/ColorWheelDialog.xaml b/Views/ColorWheelDialog.xaml
index d2aa6a4..be6d103 100644
--- a/Views/ColorWheelDialog.xaml
+++ b/Views/ColorWheelDialog.xaml
@@ -7,6 +7,10 @@
WindowStartupLocation="CenterOwner"
ResizeMode="CanResize"
ShowInTaskbar="False"
+ UseLayoutRounding="True"
+ SnapsToDevicePixels="True"
+ TextOptions.TextFormattingMode="Display"
+ TextOptions.TextRenderingMode="ClearType"
Background="#F5F5F5">
<Window.Resources>
diff --git a/Views/NoteManagerWindow.xaml b/Views/NoteManagerWindow.xaml
index 38ae3ae..0ba520e 100644
--- a/Views/NoteManagerWindow.xaml
+++ b/Views/NoteManagerWindow.xaml
@@ -6,6 +6,10 @@
mc:Ignorable="d"
Title="Note Manager" Height="450" Width="600"
WindowStartupLocation="CenterScreen"
+ UseLayoutRounding="True"
+ SnapsToDevicePixels="True"
+ TextOptions.TextFormattingMode="Display"
+ TextOptions.TextRenderingMode="ClearType"
Background="#1E1E1E" Foreground="#EEEEEE"
FontFamily="Inter, Roboto, Segoe UI Variable, Segoe UI">
@@ -115,6 +119,7 @@
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,15,0,0">
<Button Content="New Note" Style="{StaticResource ActionButtonStyle}" Click="NewNote_Click"/>
<Button Content="Toggle Open/Close" Style="{StaticResource ActionButtonStyle}" Click="ToggleState_Click"/>
+ <Button Content="Toggle Click-Through" Style="{StaticResource ActionButtonStyle}" Click="ToggleClickThrough_Click" Background="#5C3D8F"/>
<Button Content="Delete" Style="{StaticResource ActionButtonStyle}" Background="#8B0000" Click="DeleteNote_Click"/>
</StackPanel>
</Grid>
diff --git a/Views/NoteManagerWindow.xaml.cs b/Views/NoteManagerWindow.xaml.cs
index ac5a01b..4494a40 100644
--- a/Views/NoteManagerWindow.xaml.cs
+++ b/Views/NoteManagerWindow.xaml.cs
@@ -159,6 +159,26 @@ namespace DesktopNotes.Views
}
}
}
+
+ /// <summary>
+ /// Fallback toggle for notes that are partially off-screen and whose on-canvas
+ /// handle is unreachable. Syncs the live <see cref="NoteWindow"/> if it exists.
+ /// </summary>
+ private void ToggleClickThrough_Click(object sender, RoutedEventArgs e)
+ {
+ if (NotesListView.SelectedItem is NoteViewModel vm)
+ {
+ vm.Model.IsClickThrough = !vm.Model.IsClickThrough;
+
+ // Sync the live window immediately (updates handle visibility + Topmost)
+ var window = System.Windows.Application.Current.Windows.OfType<NoteWindow>()
+ .FirstOrDefault(w => w.NoteModel == vm.Model);
+ window?.ApplyClickThroughState();
+
+ _app.OnNotesStateChanged();
+ RefreshList();
+ }
+ }
}
/// <summary>
@@ -185,10 +205,10 @@ namespace DesktopNotes.Views
/// <summary>Timestamp of the last edit, shown in the "Last Updated" column.</summary>
public DateTime UpdatedAt => Model.UpdatedAt;
- /// <summary>"Open" or "Closed" status text.</summary>
- public string StatusText => Model.IsClosed ? "Closed" : "Open";
+ /// <summary>"Open", "Closed", or "Click-Through" status text.</summary>
+ public string StatusText => Model.IsClosed ? "Closed" : (Model.IsClickThrough ? "Click-Through" : "Open");
- /// <summary>Green (#4CAF50) for open notes, grey (#888888) for closed ones.</summary>
- public string StatusColor => Model.IsClosed ? "#888888" : "#4CAF50";
+ /// <summary>Green for open, grey for closed, orange for click-through.</summary>
+ public string StatusColor => Model.IsClosed ? "#888888" : (Model.IsClickThrough ? "#FF9800" : "#4CAF50");
}
}
diff --git a/Views/NoteWindow.xaml b/Views/NoteWindow.xaml
index 4133ddc..74f4b5b 100644
--- a/Views/NoteWindow.xaml
+++ b/Views/NoteWindow.xaml
@@ -6,22 +6,26 @@
MinHeight="150" MinWidth="200"
WindowStyle="None"
AllowsTransparency="True"
- Background="#01000000"
+ Background="Transparent"
ResizeMode="CanResize"
ShowInTaskbar="False"
WindowStartupLocation="Manual"
+ UseLayoutRounding="True"
+ SnapsToDevicePixels="True"
+ TextOptions.TextFormattingMode="Display"
+ TextOptions.TextRenderingMode="ClearType"
Loaded="Window_Loaded"
StateChanged="Window_StateChanged"
KeyDown="Window_KeyDown"
ContextMenu="{DynamicResource NoteContextMenu}">
<WindowChrome.WindowChrome>
- <WindowChrome ResizeBorderThickness="8" CaptionHeight="0" CornerRadius="0" GlassFrameThickness="0" UseAeroCaptionButtons="False"/>
+ <WindowChrome ResizeBorderThickness="20" CaptionHeight="0" CornerRadius="0" GlassFrameThickness="0" UseAeroCaptionButtons="False"/>
</WindowChrome.WindowChrome>
<Window.Resources>
<!-- Full Context Menu -->
- <ContextMenu x:Key="NoteContextMenu">
+ <ContextMenu x:Key="NoteContextMenu" Opened="ContextMenu_Opened">
<!-- Context Menu (Reorganized) -->
<MenuItem Command="ApplicationCommands.Cut" Header="Cut" InputGestureText="Ctrl+X" />
<MenuItem Command="ApplicationCommands.Copy" Header="Copy" InputGestureText="Ctrl+C" />
@@ -89,19 +93,20 @@
<Separator/>
<MenuItem Header="Custom Color..." Click="CustomColorMenu_Click"/>
</MenuItem>
- <MenuItem Header="Opacity">
- <MenuItem Header="100%" Click="OpacityMenu_Click" Tag="1.0"/>
- <MenuItem Header="90%" Click="OpacityMenu_Click" Tag="0.90"/>
- <MenuItem Header="80%" Click="OpacityMenu_Click" Tag="0.80"/>
- <MenuItem Header="70%" Click="OpacityMenu_Click" Tag="0.70"/>
- <MenuItem Header="60%" Click="OpacityMenu_Click" Tag="0.60"/>
- <MenuItem Header="50%" Click="OpacityMenu_Click" Tag="0.50"/>
- <MenuItem Header="40%" Click="OpacityMenu_Click" Tag="0.40"/>
- <MenuItem Header="30%" Click="OpacityMenu_Click" Tag="0.30"/>
+ <MenuItem x:Name="OpacityMenuItem" Header="Opacity">
+ <MenuItem Header="100%" Click="OpacityMenu_Click" Tag="1.0" IsCheckable="True"/>
+ <MenuItem Header="90%" Click="OpacityMenu_Click" Tag="0.90" IsCheckable="True"/>
+ <MenuItem Header="80%" Click="OpacityMenu_Click" Tag="0.80" IsCheckable="True"/>
+ <MenuItem Header="70%" Click="OpacityMenu_Click" Tag="0.70" IsCheckable="True"/>
+ <MenuItem Header="60%" Click="OpacityMenu_Click" Tag="0.60" IsCheckable="True"/>
+ <MenuItem Header="50%" Click="OpacityMenu_Click" Tag="0.50" IsCheckable="True"/>
+ <MenuItem Header="40%" Click="OpacityMenu_Click" Tag="0.40" IsCheckable="True"/>
+ <MenuItem Header="30%" Click="OpacityMenu_Click" Tag="0.30" IsCheckable="True"/>
</MenuItem>
<Separator/>
<MenuItem x:Name="AlwaysOnTopMenuItem" Header="Always on Top" IsCheckable="True" Click="AlwaysOnTopMenu_Click"/>
<MenuItem x:Name="LockNoteMenuItem" Header="Lock Note" Click="LockNoteButton_Click" InputGestureText="Ctrl+Shift+L"/>
+ <MenuItem x:Name="ClickThroughMenuItem" Header="Enable Click-Through" Click="ClickThroughMenu_Click"/>
<Separator/>
<MenuItem Header="Close this Note" Click="CloseNoteMenu_Click"/>
<MenuItem Header="Delete Note" Click="DeleteNoteButton_Click"/>
@@ -208,11 +213,16 @@
</Style>
</Window.Resources>
- <Grid Margin="20">
- <Grid.Effect>
- <!-- Soft, expansive shadow for modern floating look -->
- <DropShadowEffect x:Name="WindowShadow" BlurRadius="25" ShadowDepth="4" Direction="270" Color="Black" Opacity="0.15"/>
- </Grid.Effect>
+ <Grid Margin="15">
+ <!-- Separate shadow border for hardware acceleration and snappy dragging -->
+ <Border Background="{Binding Background, ElementName=CardBorder}" Style="{StaticResource CardBorderStyle}">
+ <Border.CacheMode>
+ <BitmapCache SnapsToDevicePixels="True"/>
+ </Border.CacheMode>
+ <Border.Effect>
+ <DropShadowEffect x:Name="WindowShadow" BlurRadius="15" ShadowDepth="4" Direction="270" Color="Black" Opacity="0.15" RenderingBias="Performance"/>
+ </Border.Effect>
+ </Border>
<Border x:Name="CardBorder" Background="#FFF9C4" BorderBrush="Transparent" Style="{StaticResource CardBorderStyle}">
<Grid>
@@ -233,6 +243,7 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
+ <ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Title: TextBlock by default, TextBox on double-click -->
@@ -267,36 +278,43 @@
Foreground="#88333333"
Margin="0,0,8,0"
Opacity="0"/>
+
+ <Button x:Name="ClickThroughBtn" Grid.Column="2" Style="{StaticResource HeaderButtonStyle}"
+ ToolTip="Enable Click-Through" Click="ClickThroughMenu_Click" Margin="0,0,2,0">
+ <Path Data="M21,3H7C5.89,3,5,3.89,5,5v4H3v12c0,1.1,0.89,2,2,2h12v-2H5V11h14v2h2V5C21,3.89,20.1,3,21,3z M19,9H7V5h12V9z M14,14v8l2.25-2.25l2.5,4.25l1.5-0.75l-2.5-4.25l3.5,0L14,14z"
+ Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}"
+ Stretch="Uniform" Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+ </Button>
- <Button x:Name="LockNoteBtn" Grid.Column="2" Style="{StaticResource HeaderButtonStyle}"
+ <Button x:Name="LockNoteBtn" Grid.Column="3" Style="{StaticResource HeaderButtonStyle}"
ToolTip="Lock Note" Click="LockNoteButton_Click" Margin="0,0,2,0">
<Path x:Name="LockIconPath" Data="M 19 9 L 5 9 C 3.9 9 3 9.9 3 11 L 3 20 C 3 21.1 3.9 22 5 22 L 19 22 C 20.1 22 21 21.1 21 20 L 21 11 C 21 9.9 20.1 9 19 9 Z M 10 9 L 10 6 C 10 2.7 7.3 0 4 0 C 0.7 0 -2 2.7 -2 6 L -2 15 C -2 16.1 -0.9 17 0 17 C 0.9 17 2 16.1 2 15 L 2 6 C 2 4.9 2.9 4 4 4 C 5.1 4 6 4.9 6 6 L 6 9 Z M 12 17 A 1.5 1.5 0 0 0 12.75 14.33 L 12.75 12 A 0.75 0.75 0 0 0 11.25 12 L 11.25 14.33 A 1.5 1.5 0 0 0 12 17 Z"
Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}"
Stretch="Uniform" Width="13" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button>
- <Button x:Name="NewNoteBtn" Grid.Column="3" Style="{StaticResource HeaderButtonStyle}"
+ <Button x:Name="NewNoteBtn" Grid.Column="4" Style="{StaticResource HeaderButtonStyle}"
ToolTip="New Note" Click="NewNoteButton_Click" Margin="0,0,2,0">
<Path Data="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H10v-2H6V4h7v5h5v3h2V8l-6-6zM18 15v3h-3v2h3v3h2v-3h3v-2h-3v-3h-2z"
Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}"
Stretch="Uniform" Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button>
- <Button x:Name="SearchNoteBtn" Grid.Column="4" Style="{StaticResource HeaderButtonStyle}"
+ <Button x:Name="SearchNoteBtn" Grid.Column="5" Style="{StaticResource HeaderButtonStyle}"
ToolTip="Search Notes" Click="SearchNoteButton_Click" Margin="0,0,2,0">
<Path Data="M14 2H6c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H11v-2H6V4h7v5h5v4h2V8l-6-6zM15.5 15c-1.93 0-3.5 1.57-3.5 3.5s1.57 3.5 3.5 3.5c.71 0 1.37-.23 1.9-.61l2.69 2.69 1.41-1.41-2.69-2.69c.38-.53.61-1.19.61-1.9 0-1.93-1.57-3.5-3.5-3.5zm0 5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z"
Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}"
Stretch="Uniform" Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button>
- <Button x:Name="DeleteNoteBtn" Grid.Column="5" Style="{StaticResource HeaderButtonStyle}"
+ <Button x:Name="DeleteNoteBtn" Grid.Column="6" Style="{StaticResource HeaderButtonStyle}"
ToolTip="Delete Note" Click="DeleteNoteButton_Click" Margin="0,0,2,0">
<Path Data="M 9 3 L 9 4 L 4 4 L 4 6 L 5 6 L 5 20 C 5 21.104569 5.8954305 22 7 22 L 17 22 C 18.104569 22 19 21.104569 19 20 L 19 6 L 20 6 L 20 4 L 15 4 L 15 3 C 15 1.8954305 14.104569 1 13 1 L 11 1 C 9.8954305 1 9 1.8954305 9 3 z M 11 3 L 13 3 L 13 4 L 11 4 L 11 3 z M 7 6 L 17 6 L 17 20 L 7 20 L 7 6 z M 9 8 L 11 8 L 11 18 L 9 18 L 9 8 z M 13 8 L 15 8 L 15 18 L 13 18 L 13 8 z"
Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType=Button}}"
Stretch="Uniform" Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button>
- <Button x:Name="CloseNoteBtn" Grid.Column="6" Content="✕" Style="{StaticResource HeaderButtonStyle}"
+ <Button x:Name="CloseNoteBtn" Grid.Column="7" Content="✕" Style="{StaticResource HeaderButtonStyle}"
ToolTip="Close Note" Click="CloseNoteButton_Click" Margin="0,0,6,0"/>
</Grid>
@@ -313,6 +331,7 @@
Foreground="#333333"
FontFamily="Inter, Roboto, Segoe UI Variable, Segoe UI"
Cursor="Arrow"
+ PreviewMouseWheel="ContentRichTextBox_PreviewMouseWheel"
PreviewMouseUp="ContentRichTextBox_PreviewMouseUp"
SelectionChanged="ContentRichTextBox_SelectionChanged"
TextChanged="ContentRichTextBox_TextChanged"
diff --git a/Views/NoteWindow.xaml.cs b/Views/NoteWindow.xaml.cs
index 500835d..796a922 100644
--- a/Views/NoteWindow.xaml.cs
+++ b/Views/NoteWindow.xaml.cs
@@ -5,6 +5,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
+using System.Windows.Interop;
using System.Windows.Media;
using DesktopNotes.Models;
@@ -98,6 +99,75 @@ namespace DesktopNotes.Views
NoteModel = note;
}
+ // ---- Win32 Click-Through ----
+
+ public const int WS_EX_TRANSPARENT = 0x00000020;
+ public const int GWL_EXSTYLE = -20;
+
+ [System.Runtime.InteropServices.DllImport("user32.dll")]
+ public static extern int GetWindowLong(IntPtr hwnd, int index);
+
+ [System.Runtime.InteropServices.DllImport("user32.dll")]
+ public static extern int SetWindowLong(IntPtr hwnd, int index, int newStyle);
+
+ private PinWindow? _pinWindow;
+ /// <summary>
+ /// When true, the WndProc Z-order guard is temporarily disabled to allow
+ /// intentional Z-order changes (e.g., re-attaching to desktop after click-through).
+ /// </summary>
+ private bool _suppressZOrderGuard = false;
+
+ protected override void OnSourceInitialized(EventArgs e)
+ {
+ base.OnSourceInitialized(e);
+ var hwnd = new WindowInteropHelper(this).Handle;
+ HwndSource.FromHwnd(hwnd)?.AddHook(WndProc);
+ }
+
+ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
+ {
+ if (msg == 0x0046) // WM_WINDOWPOSCHANGING
+ {
+ // Only guard Z-order when note is in desktop-attached mode and not mid-transition
+ if (!_suppressZOrderGuard && !NoteModel.IsAlwaysOnTop && !NoteModel.IsClickThrough)
+ {
+ var wp = System.Runtime.InteropServices.Marshal.PtrToStructure<DesktopNotes.Interop.NativeMethods.WINDOWPOS>(lParam);
+
+ // If Z-order is being changed (SWP_NOZORDER not set)
+ if ((wp.flags & 0x0004U) == 0)
+ {
+ // Block the Z-order change so note stays behind normal apps
+ wp.flags |= 0x0004U; // SWP_NOZORDER
+ wp.flags |= 0x0200U; // SWP_NOOWNERZORDER
+
+ System.Runtime.InteropServices.Marshal.StructureToPtr(wp, lParam, false);
+ }
+ }
+ }
+ return IntPtr.Zero;
+ }
+
+ internal void SetDesktopZOrder(IntPtr hwndInsertAfter)
+ {
+ _suppressZOrderGuard = true;
+ try
+ {
+ var hwnd = new WindowInteropHelper(this).Handle;
+ if (hwnd != IntPtr.Zero)
+ {
+ DesktopNotes.Interop.NativeMethods.SetWindowPos(
+ hwnd, hwndInsertAfter,
+ 0, 0, 0, 0,
+ 0x0213 // SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER
+ );
+ }
+ }
+ finally
+ {
+ _suppressZOrderGuard = false;
+ }
+ }
+
private void Window_Loaded(object sender, RoutedEventArgs e)
{
@@ -108,6 +178,9 @@ namespace DesktopNotes.Views
TitleBlock.Text = NoteModel.Title;
Topmost = NoteModel.IsAlwaysOnTop;
+ LocationChanged += NoteWindow_LocationChanged;
+ SizeChanged += NoteWindow_SizeChanged;
+
if (TryFindResource("NoteContextMenu") is ContextMenu cm)
{
foreach (var item in cm.Items)
@@ -139,6 +212,7 @@ namespace DesktopNotes.Views
ApplyBackgroundColor(NoteModel.BackgroundColor);
UpdateLockUI();
+ ApplyClickThroughState(); // restore persisted click-through state
_isInitializing = false;
}
@@ -538,6 +612,49 @@ namespace DesktopNotes.Views
CheckFormatPopup();
}
+ private void ContentRichTextBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
+ {
+ if (Keyboard.Modifiers == ModifierKeys.Control)
+ {
+ // Let the RichTextBox handle zoom if Ctrl is pressed
+ return;
+ }
+
+ if (sender is System.Windows.Controls.RichTextBox rtb)
+ {
+ var scrollViewer = GetDescendantByType<ScrollViewer>(rtb);
+ if (scrollViewer != null)
+ {
+ e.Handled = true;
+ // Windows default scroll delta is typically 120.
+ // Slow it down to ~30% of normal physical scrolling speed for a smoother, more controlled feel in a small window.
+ double scrollMultiplier = 0.3;
+ scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - (e.Delta * scrollMultiplier));
+ }
+ }
+ }
+
+ private static T? GetDescendantByType<T>(DependencyObject depObj) where T : DependencyObject
+ {
+ if (depObj == null) return null;
+
+ for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(depObj); i++)
+ {
+ var child = System.Windows.Media.VisualTreeHelper.GetChild(depObj, i);
+ if (child is T result)
+ {
+ return result;
+ }
+
+ T? childItem = GetDescendantByType<T>(child);
+ if (childItem != null)
+ {
+ return childItem;
+ }
+ }
+ return null;
+ }
+
private void CheckFormatPopup()
{
if (NoteModel.IsLocked)
@@ -766,6 +883,26 @@ namespace DesktopNotes.Views
}
}
+ private void NoteWindow_LocationChanged(object? sender, EventArgs e)
+ {
+ UpdatePinWindowPosition();
+ }
+
+ private void NoteWindow_SizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ UpdatePinWindowPosition();
+ }
+
+ private void UpdatePinWindowPosition()
+ {
+ if (_pinWindow != null && ClickThroughBtn.IsVisible)
+ {
+ var pt = ClickThroughBtn.TranslatePoint(new System.Windows.Point(0, 0), this);
+ _pinWindow.Left = this.Left + pt.X;
+ _pinWindow.Top = this.Top + pt.Y;
+ }
+ }
+
// --- Opacity ---
private void OpacityMenu_Click(object sender, RoutedEventArgs e)
@@ -784,18 +921,158 @@ namespace DesktopNotes.Views
}
}
+ // --- Click-Through ---
+
+ /// <summary>
+ /// Synchronises the UI (handle button visibility, context menu label, Topmost, desktop
+ /// detach) to the current value of <see cref="NoteModel.IsClickThrough"/>.
+ /// Call after toggling <see cref="NoteModel.IsClickThrough"/> and on startup.
+ /// Public so <see cref="NoteManagerWindow"/> can reach it as a fallback.
+ /// </summary>
+ public void ApplyClickThroughState()
+ {
+ MenuItem? clickThroughMenuItem = null;
+ if (TryFindResource("NoteContextMenu") is ContextMenu cm)
+ {
+ foreach (var item in cm.Items)
+ {
+ if (item is MenuItem mi && (mi.Header?.ToString() == "Enable Click-Through" || mi.Header?.ToString() == "Disable Click-Through"))
+ {
+ clickThroughMenuItem = mi;
+ break;
+ }
+ }
+ }
+
+ var hwnd = new WindowInteropHelper(this).Handle;
+ if (hwnd == IntPtr.Zero) return;
+
+ int style = GetWindowLong(hwnd, GWL_EXSTYLE);
+
+ if (NoteModel.IsClickThrough)
+ {
+ // Force always-on-top visually so the note stays visible over other apps,
+ // without modifying the persisted NoteModel.IsAlwaysOnTop value.
+ Topmost = true;
+
+ // Safely add WS_EX_TRANSPARENT without stripping WS_EX_LAYERED
+ SetWindowLong(hwnd, GWL_EXSTYLE, style | WS_EX_TRANSPARENT);
+
+ if (_pinWindow == null)
+ {
+ _pinWindow = new PinWindow(() =>
+ {
+ NoteModel.IsClickThrough = false;
+ ApplyClickThroughState();
+ NoteModel.UpdatedAt = DateTime.Now;
+ NoteChanged?.Invoke(this, EventArgs.Empty);
+ ShowSavedIndicator();
+ });
+ _pinWindow.Owner = this;
+
+ // Position exactly over ClickThroughBtn
+ var pt = ClickThroughBtn.TranslatePoint(new System.Windows.Point(0, 0), this);
+ _pinWindow.Left = this.Left + pt.X;
+ _pinWindow.Top = this.Top + pt.Y;
+ _pinWindow.Width = ClickThroughBtn.ActualWidth > 0 ? ClickThroughBtn.ActualWidth : 28;
+ _pinWindow.Height = ClickThroughBtn.ActualHeight > 0 ? ClickThroughBtn.ActualHeight : 28;
+
+ _pinWindow.Show();
+ }
+
+ if (clickThroughMenuItem != null)
+ {
+ clickThroughMenuItem.Header = "Disable Click-Through";
+ }
+ AlwaysOnTopChanged?.Invoke(this, EventArgs.Empty); // detach from desktop layer
+ }
+ else
+ {
+ // Temporarily disable the Z-order guard so all the transitions
+ // (Topmost change, owner re-attachment, SetWindowPos) go through.
+ _suppressZOrderGuard = true;
+ try
+ {
+ // Remove WS_EX_TRANSPARENT
+ SetWindowLong(hwnd, GWL_EXSTYLE, style & ~WS_EX_TRANSPARENT);
+
+ // Restore Topmost to whatever the user originally had
+ Topmost = NoteModel.IsAlwaysOnTop;
+
+ if (_pinWindow != null)
+ {
+ _pinWindow.Close();
+ _pinWindow = null;
+ }
+
+ if (clickThroughMenuItem != null)
+ {
+ clickThroughMenuItem.Header = "Enable Click-Through";
+ }
+
+ // Fire event so App.xaml.cs re-attaches to desktop (sets owner + HWND_BOTTOM)
+ AlwaysOnTopChanged?.Invoke(this, EventArgs.Empty);
+ }
+ finally
+ {
+ _suppressZOrderGuard = false;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Toggles click-through on/off from the context menu item.
+ /// </summary>
+ private void ClickThroughMenu_Click(object sender, RoutedEventArgs e)
+ {
+ NoteModel.IsClickThrough = !NoteModel.IsClickThrough;
+ ApplyClickThroughState();
+ NoteModel.UpdatedAt = DateTime.Now;
+ NoteChanged?.Invoke(this, EventArgs.Empty);
+ ShowSavedIndicator();
+ }
+
// --- Always on Top ---
private void AlwaysOnTopMenu_Click(object sender, RoutedEventArgs e)
{
if (sender is MenuItem menuItem)
{
- NoteModel.IsAlwaysOnTop = menuItem.IsChecked;
- Topmost = NoteModel.IsAlwaysOnTop;
- NoteModel.UpdatedAt = DateTime.Now;
- AlwaysOnTopChanged?.Invoke(this, EventArgs.Empty);
- NoteChanged?.Invoke(this, EventArgs.Empty);
- ShowSavedIndicator();
+ _suppressZOrderGuard = true;
+ try
+ {
+ NoteModel.IsAlwaysOnTop = menuItem.IsChecked;
+ Topmost = NoteModel.IsAlwaysOnTop;
+ NoteModel.UpdatedAt = DateTime.Now;
+ AlwaysOnTopChanged?.Invoke(this, EventArgs.Empty);
+ NoteChanged?.Invoke(this, EventArgs.Empty);
+ ShowSavedIndicator();
+ }
+ finally
+ {
+ _suppressZOrderGuard = false;
+ }
+ }
+ }
+
+ // --- Context Menu Checkmarks ---
+
+ private void ContextMenu_Opened(object sender, RoutedEventArgs e)
+ {
+ if (sender is ContextMenu menu)
+ {
+ // Find OpacityMenuItem
+ var opacityMenuItem = menu.Items.OfType<MenuItem>().FirstOrDefault(m => m.Name == "OpacityMenuItem");
+ if (opacityMenuItem != null)
+ {
+ foreach (var item in opacityMenuItem.Items.OfType<MenuItem>())
+ {
+ if (item.Tag is string opacityStr && double.TryParse(opacityStr, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out double opacityVal))
+ {
+ item.IsChecked = Math.Abs(opacityVal - NoteModel.Opacity) < 0.01;
+ }
+ }
+ }
}
}
diff --git a/Views/SearchWindow.xaml b/Views/SearchWindow.xaml
index 05c16df..66a5b88 100644
--- a/Views/SearchWindow.xaml
+++ b/Views/SearchWindow.xaml
@@ -4,6 +4,10 @@
Title="Perma Notes — Search"
Height="400" Width="450"
WindowStartupLocation="CenterScreen"
+ UseLayoutRounding="True"
+ SnapsToDevicePixels="True"
+ TextOptions.TextFormattingMode="Display"
+ TextOptions.TextRenderingMode="ClearType"
Background="#F5F5F5"
ShowInTaskbar="True"
Loaded="Window_Loaded">
diff --git a/Views/SettingsWindow.xaml b/Views/SettingsWindow.xaml
index d426873..316eda3 100644
--- a/Views/SettingsWindow.xaml
+++ b/Views/SettingsWindow.xaml
@@ -6,6 +6,10 @@
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
ShowInTaskbar="True"
+ UseLayoutRounding="True"
+ SnapsToDevicePixels="True"
+ TextOptions.TextFormattingMode="Display"
+ TextOptions.TextRenderingMode="ClearType"
Background="#F5F5F5">
<Grid Margin="20">