-
-
Notifications
You must be signed in to change notification settings - Fork 581
Expand file tree
/
Copy pathtaskbar-vd-switcher.wh.cpp
More file actions
2684 lines (2370 loc) · 110 KB
/
Copy pathtaskbar-vd-switcher.wh.cpp
File metadata and controls
2684 lines (2370 loc) · 110 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
// ==WindhawkMod==
// @id taskbar-vd-switcher
// @name Taskbar Virtual Desktop Switcher
// @description Injects clickable buttons into the taskbar — one per virtual desktop — with configurable grid arrangement for direct switching.
// @version 1.7
// @author sb4ssman
// @github https://github.com/sb4ssman
// @include explorer.exe
// @architecture x86-64
// @compilerOptions -lole32 -loleaut32 -lruntimeobject -lversion -luuid
// ==/WindhawkMod==
// ==WindhawkModReadme==
/*
# Taskbar Virtual Desktop Switcher
A [Windhawk](https://windhawk.net) mod for Windows 11 that injects clickable buttons into the system tray — one per virtual desktop — for instant switching without opening Task View.

*Three desktops with the optional Task View master button as a lower sliver.*

*Default tray placement: three desktops in a row, desktop 1 active.*

*Compact tray placement with two desktops.*

*Four desktops with the optional Task View master button.*

*Taller taskbar: a dense grid with the master button as a lower sliver.*

*Start placement: switcher reserved to the left of Start.*

*Start placement with the Start button hidden.*

*Overlay mode can be nudged up with the vertical offset setting.*

*Overlay mode can also be nudged down.*

*Right-of-Start placement when the Start button is hidden.*
## Features
- Numbered, roman-numeral, dot, or custom-label buttons
- Smart grid layout with balanced, vertical-pack, horizontal-pack, and fixed override modes
- Highlights the active desktop immediately on switch
- Buttons appear/disappear as desktops are added or removed
- Five placement positions within the system tray, plus experimental Start-adjacent and Start-overlay positions
- Start placement modes: left of Start, over Start, and right of Start
- Configurable size, spacing, colors, opacity, and shine effect
- Per-state text color, font size, corner radius, bold, and border
- Tooltip on each button shows the desktop's display name
- Option to hide the bar entirely when only one desktop exists
- Experimental option to also show the switcher on secondary monitors' taskbars
## Settings
| Setting | Default | Description |
|---------|---------|-------------|
| Position | After clock | Where to place the switcher: system tray positions, left/right of Start, or over Start |
| Grid mode | Smart automatic | Smart, single row/column, fixed rows, fixed columns, or fixed grid |
| Smart layout | Balanced | Balanced, pack vertical, or pack horizontal |
| Fill order | Row-first | Row-first or column-first |
| Rows | 0 (auto) | Fixed rows, or max rows for smart mode when set |
| Columns | 0 (auto) | Fixed columns, or max columns for smart mode when set |
| Short group alignment | Center | Align a shorter last row/column to start, center, or end |
| Button width | 20 px | Width of each button |
| Button height | 22 px | Height of each button |
| Button spacing | 2 px | Gap between buttons in the grid |
| Label format | Numbers | Numbers · Roman numerals · Dots · Custom |
| Custom labels | *(empty)* | Comma-separated, e.g. `H,W,M` |
| Font size | 10 pt | Button label size |
| Active text color | *(native)* | Current desktop's label color |
| Inactive text color | *(native)* | Other desktops' label color |
| Active color | `accent` | Current desktop background; empty keeps the native surface |
| Inactive color | *(native)* | Other desktop backgrounds; empty keeps the native button surface |
| Hover background color | *(automatic)* | Forces one shared hover color; empty brightens each button's current background, native surfaces keep native hover |
| Click background color | *(automatic)* | Forces one shared pressed color; empty darkens each button's current background, native surfaces keep native pressed |
| Border color | *(native)* | Button border color |
| Border thickness | 0 px | Button border width |
| Corner radius | 4 px | Rounded corners (0 = square, 4 = Windows default) |
| Opacity | 100 | 0–100; lower values let the taskbar show through |
| Shine effect | Off | Gradient highlight on buttons with custom colors |
| Active bold | Off | Bold the current desktop's label |
| Padding left | 0 px | Extra space to the left of the button grid |
| Padding right | 2 px | Extra space to the right of the button grid |
| Hide when single | Off | Don't show the bar when only one desktop exists |
| Show on all taskbars | Off | Experimental: also inject into secondary monitors' taskbars (tray positions only; may need an Explorer restart after enabling) |
| Task View button | Off | Optional button that opens Task View for previewing, creating, or closing desktops |
| Task View button label | ⊞ | Text shown on the Task View button |
| Task View button position | After | Column before/after desktop buttons, or sliver row above/below |
| Task View button sliver height | 6 px | Height of the Task View button when used as a sliver row |
| Task View button column width | 14 px | Width of the Task View button when used as a side column |
All color settings accept `#RRGGBB` or `#AARRGGBB` hex (the alpha byte is
honored), the generics `accent`, `accentLight`, and `accentDark` for the
Windows accent shades, or `transparent` for a fully transparent surface —
nothing drawn, element still present and clickable. Leaving a color empty
keeps the native behavior described for that setting — including the Active
color, where empty means the current desktop's button keeps the plain native
surface with no highlight at all.
## Known limitations
- Multi-monitor support is experimental and off by default: secondary taskbars use the tray positions only (Start positions stay on the primary taskbar), and they are discovered as their tray icons load — after enabling the option, an Explorer restart (or toggling the mod off and on) may be needed before the buttons appear on other monitors
- Buttons may not appear until the mod injects on the first tray icon load; retry loop runs up to 5 times at 2-second intervals
## Credits and inspirations
This mod builds directly on patterns established by several community mods:
**[taskbar-empty-space-clicks](https://github.com/ramensoftware/windhawk-mods/blob/main/mods/taskbar-empty-space-clicks.wh.cpp)** — source of the `SwitchVirtualDesktop()` COM vtable pattern, build-specific IIDs for `IVirtualDesktopManagerInternal`, and the `IObjectArray` desktop enumeration approach.
**[taskbar-desktop-indicator](https://github.com/ramensoftware/windhawk-mods/blob/main/mods/taskbar-desktop-indicator.wh.cpp)** — reference for reading the current virtual desktop from the registry (session-scoped `VirtualDesktopIDs` + `CurrentVirtualDesktop` keys) and the notification cookie / `IVirtualDesktopNotificationService` registration pattern.
**[Vertical OmniButton archive](https://github.com/sb4ssman/Windhawk-Mod-Lab/blob/main/omnibutton-customizer/archive/vertical-omnibutton-v1.4.wh.cpp)** (this lab, by sb4ssman) — source of the `GetTaskbarXamlRoot` boilerplate, `RunFromWindowThread` dispatcher, `FindCurrentProcessTaskbarWnd`, and the `IconView::IconView` hook-and-retry injection pattern.
**[windows-11-taskbar-styler](https://github.com/ramensoftware/windhawk-mods/blob/main/mods/windows-11-taskbar-styler.wh.cpp)** — reference for the `SystemTrayFrameGrid` XAML tree structure and element names (`ShowDesktopStack`, `NotificationCenterButton`, `ControlCenterButton`, `NotifyIconStack`).
**[Windhawk](https://windhawk.net)** by [m417z](https://github.com/m417z) — the modding platform that makes all of this possible.
*/
// ==/WindhawkModReadme==
// ==WindhawkModSettings==
/*
- position: "afterClock"
$name: Position
$description: Where in the system tray to inject the VD buttons
$options:
- "afterClock": "After clock (before Show Desktop)"
- "beforeClock": "Before clock (after OmniButton)"
- "beforeOmni": "Before OmniButton (wifi/vol/bat)"
- "beforeIcons": "Before notification icons"
- "afterShowDesktop": "After Show Desktop strip"
- "nextToStart": "Left of Start button (experimental)"
- "overStart": "Over Start button (experimental)"
- "rightOfStart": "Right of Start button (experimental)"
- gridMode: autoSmart
$name: Grid mode
$description: >-
Choose how the button grid shape is selected. Auto smart picks a compact
balanced layout that fits the available taskbar height. Fixed modes use
the Rows and/or Columns settings below.
$options:
- autoSmart: Smart automatic
- singleRow: Single row
- singleColumn: Single column
- fixedRows: Fixed rows
- fixedColumns: Fixed columns
- fixedGrid: Fixed rows and columns
- smartLayout: balanced
$name: Smart layout
$description: >-
Used when Grid mode is Smart automatic. Balanced avoids awkward 3+1 layouts
when a cleaner 2x2 is possible. Vertical pack uses available height.
Horizontal pack prefers fewer rows.
$options:
- balanced: Balanced
- packVertical: Pack vertical
- packHorizontal: Pack horizontal
- fillOrder: rowFirst
$name: Fill order
$description: Whether desktop buttons fill across rows first or down columns first.
$options:
- rowFirst: Row-first (left to right, then down)
- columnFirst: Column-first (top to bottom, then right)
- buttonRows: 0
$name: Rows (0 = auto)
$description: >-
In Fixed rows and Fixed grid modes: sets the exact row count. In Smart
automatic mode: acts as a maximum cap (0 = uncapped). Ignored in Single
row and Single column modes.
- buttonColumns: 0
$name: Columns (0 = auto)
$description: >-
In Fixed columns and Fixed grid modes: sets the exact column count. In Smart
automatic mode: filters out layouts that would exceed this many columns (0 =
no limit). Ignored in Single row and Single column modes. In row-first fill,
3 columns with 4 desktops gives a 3+1 layout.
- shortGroupAlign: "center"
$name: Short column/row alignment
$description: >-
When the last column (column-first) or last row (row-first) has fewer
buttons than the others, where to place those buttons within the available space.
$options:
- "start": "Start (top for columns, left for rows)"
- "center": "Center"
- "end": "End (bottom for columns, right for rows)"
- buttonWidth: 20
$name: Button width (px)
- buttonHeight: 22
$name: Button height (px)
- buttonSpacing: 2
$name: Button spacing (px)
$description: Gap between buttons in the grid
- labelFormat: "number"
$name: Label format
$options:
- "number": "Numbers 1 2 3"
- "roman": "Roman numerals I II III"
- "dot": "Dots ● ○ ○"
- "custom": "Custom labels"
- customLabels: ""
$name: Custom labels (comma-separated, e.g. "H,W,M")
$description: Used when label format is Custom. Falls back to numbers if labels run out.
- fontSize: 10
$name: Font size (pt)
- activeTextColor: ""
$name: Active desktop text color
$description: Hex (#RRGGBB or #AARRGGBB), accent / accentLight / accentDark, or transparent. Empty uses the native text brush.
- inactiveTextColor: ""
$name: Inactive button text color
$description: Hex (#RRGGBB or #AARRGGBB), accent / accentLight / accentDark, or transparent. Empty uses the native text brush.
- activeColor: "accent"
$name: Active desktop color
$description: >-
Background for the current desktop's button. Enter a hex color (e.g.
"#4488FF"), accent / accentLight / accentDark for the Windows accent
shades, or transparent. Empty keeps the native button surface, matching
the other buttons.
- inactiveColor: ""
$name: Inactive button color
$description: >-
Background for the other desktops' buttons. Hex, accent / accentLight /
accentDark, or transparent. Empty keeps the native button surface.
- hoverBackgroundColor: ""
$name: Hover background color
$description: >-
Hex, accent / accentLight / accentDark, or transparent, to force one
shared hover color on all buttons. Empty brightens each button's current
background; buttons on the native surface keep the native hover behavior.
- pressedBackgroundColor: ""
$name: Click background color
$description: >-
Hex, accent / accentLight / accentDark, or transparent, to force one
shared pressed color on all buttons. Empty darkens each button's current
background; buttons on the native surface keep the native pressed
behavior.
- borderColor: ""
$name: Button border color
$description: Hex (#RRGGBB or #AARRGGBB), accent / accentLight / accentDark, or transparent. Empty uses the native border brush.
- borderThickness: 0
$name: Button border thickness (px)
- cornerRadius: 4
$name: Corner radius (px)
$description: Rounded corners on buttons (0 = square, 4 = Windows default)
- buttonOpacity: 100
$name: Button opacity (0–100)
$description: 100 = fully opaque; lower values let the taskbar show through
- shineEffect: false
$name: Shine effect
$description: Adds a subtle gradient highlight. Applies when a custom color is set.
- activeBold: false
$name: Bold active desktop label
- paddingLeft: 0
$name: Padding left (px)
$description: Extra space to the left of the button grid
- paddingRight: 2
$name: Padding right (px)
$description: Extra space to the right of the button grid
- gridVerticalOffset: 0
$name: Vertical offset (px)
$description: >-
Nudge the entire button grid up (negative) or down (positive) from its
centered position. 0 = auto-centered. Applies after automatic centering,
so it works in combination with all grid and sliver settings.
- hideWhenSingle: false
$name: Hide when only one desktop
$description: Don't show the button bar when there is only one virtual desktop
- multiMonitor: false
$name: Show on all taskbars (experimental)
$description: >-
Also injects the switcher into secondary monitors' taskbars, in the same
tray position. Tray positions only - the Start positions stay on the
primary taskbar. Secondary taskbars are discovered as their tray icons
load, so after enabling this you may need to restart Explorer (or toggle
the mod off and on) before the buttons appear on other monitors.
- showMasterButton: false
$name: Show Task View button
$description: >-
Adds a button that opens Task View (Win+Tab), where you can preview all
desktops and create or close them.
- masterButtonLabel: "⊞"
$name: Task View button label
$description: Text shown on the Task View button.
- masterButtonPosition: "after"
$name: Task View button position
$options:
- "before": "Column before desktop buttons"
- "after": "Column after desktop buttons"
- "bottom": "Sliver below desktop buttons"
- "top": "Sliver above desktop buttons"
- masterButtonHeight: 6
$name: Sliver height (px)
$description: >-
Row height of the Task View button when placed above or below the desktop buttons
(Top or Bottom positions). Larger values cause the sliver to peek further past
the taskbar edge. Not used in Before or After (column) positions.
- masterButtonWidth: 14
$name: Task View column width (px)
$description: >-
Column width of the Task View button when placed before or after the desktop
buttons (Before or After positions). Not used in Top or Bottom (sliver) positions.
- masterButtonSpacing: 0
$name: Sliver gap offset (px)
$description: >-
Only applies to Top or Bottom (sliver) positions. Extra space added between the
sliver button and the desktop buttons, beyond the normal button spacing. 0 =
no extra gap. Positive = sliver button retreats from desktop buttons (larger
gap, smaller sliver). Negative = sliver button advances toward or overlaps the
desktop buttons. Does not affect desktop button centering. To control how far
the sliver peeks past the taskbar edge, adjust Sliver height.
*/
// ==/WindhawkModSettings==
#undef GetCurrentTime
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.UI.Core.h>
#include <winrt/Windows.UI.Text.h>
#include <winrt/Windows.UI.ViewManagement.h>
#include <winrt/Windows.UI.Xaml.h>
#include <winrt/Windows.UI.Xaml.Automation.h>
#include <winrt/Windows.UI.Xaml.Controls.Primitives.h>
#include <winrt/Windows.UI.Xaml.Controls.h>
#include <winrt/Windows.UI.Xaml.Media.h>
#include <atomic>
#include <list>
#include <string>
#include <vector>
#include <sstream>
#include <thread>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <windhawk_utils.h>
#include <combaseapi.h>
#include <winver.h>
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Xaml::Automation;
using namespace winrt::Windows::UI::Xaml::Controls;
using namespace winrt::Windows::UI::Xaml::Media;
// ============================================================
// Settings
// ============================================================
struct ModSettings {
std::wstring position = L"afterClock";
int buttonWidth = 20;
int buttonHeight = 22;
int buttonSpacing = 2;
int buttonRows = 0;
int buttonColumns = 0;
std::wstring activeColor = L"accent";
std::wstring inactiveColor = L"";
std::wstring hoverBackgroundColor;
std::wstring pressedBackgroundColor;
int buttonOpacity = 100;
bool shineEffect = false;
std::wstring labelFormat = L"number";
std::wstring customLabels = L"";
std::wstring activeTextColor = L"";
std::wstring inactiveTextColor= L"";
int fontSize = 10;
int cornerRadius = 4;
bool activeBold = false;
int borderThickness = 0;
std::wstring borderColor = L"";
bool hideWhenSingle = false;
bool multiMonitor = false;
int paddingLeft = 0;
int paddingRight = 2;
std::wstring gridMode = L"autoSmart";
std::wstring smartLayout = L"balanced";
std::wstring fillOrder = L"rowFirst";
std::wstring shortGroupAlign = L"center";
bool showMasterButton = false;
std::wstring masterButtonLabel = L"⊞"; // ⊞
std::wstring masterButtonPosition = L"after";
int masterButtonHeight = 6;
int masterButtonWidth = 14;
int masterButtonSpacing = 0;
int gridVerticalOffset = 0;
};
ModSettings g_settings;
static void LoadSettings() {
auto Str = [](const wchar_t* k) {
PCWSTR p = Wh_GetStringSetting(k);
std::wstring r = p;
Wh_FreeStringSetting(p);
return r;
};
g_settings.position = Str(L"position");
g_settings.buttonWidth = Wh_GetIntSetting(L"buttonWidth");
g_settings.buttonHeight = Wh_GetIntSetting(L"buttonHeight");
g_settings.buttonSpacing = Wh_GetIntSetting(L"buttonSpacing");
g_settings.buttonRows = std::max(Wh_GetIntSetting(L"buttonRows"), 0);
g_settings.buttonColumns = std::max(Wh_GetIntSetting(L"buttonColumns"), 0);
g_settings.activeColor = Str(L"activeColor");
g_settings.inactiveColor = Str(L"inactiveColor");
g_settings.hoverBackgroundColor = Str(L"hoverBackgroundColor");
g_settings.pressedBackgroundColor = Str(L"pressedBackgroundColor");
g_settings.buttonOpacity = Wh_GetIntSetting(L"buttonOpacity");
g_settings.shineEffect = Wh_GetIntSetting(L"shineEffect") != 0;
g_settings.labelFormat = Str(L"labelFormat");
g_settings.customLabels = Str(L"customLabels");
g_settings.activeTextColor = Str(L"activeTextColor");
g_settings.inactiveTextColor = Str(L"inactiveTextColor");
g_settings.fontSize = Wh_GetIntSetting(L"fontSize");
g_settings.cornerRadius = Wh_GetIntSetting(L"cornerRadius");
g_settings.activeBold = Wh_GetIntSetting(L"activeBold") != 0;
g_settings.borderThickness = Wh_GetIntSetting(L"borderThickness");
g_settings.borderColor = Str(L"borderColor");
g_settings.hideWhenSingle = Wh_GetIntSetting(L"hideWhenSingle") != 0;
g_settings.multiMonitor = Wh_GetIntSetting(L"multiMonitor") != 0;
g_settings.paddingLeft = Wh_GetIntSetting(L"paddingLeft");
g_settings.paddingRight = Wh_GetIntSetting(L"paddingRight");
g_settings.gridMode = Str(L"gridMode");
g_settings.smartLayout = Str(L"smartLayout");
g_settings.fillOrder = Str(L"fillOrder");
g_settings.shortGroupAlign = Str(L"shortGroupAlign");
g_settings.showMasterButton = Wh_GetIntSetting(L"showMasterButton") != 0;
g_settings.masterButtonLabel = Str(L"masterButtonLabel");
g_settings.masterButtonPosition = Str(L"masterButtonPosition");
g_settings.masterButtonHeight = std::max(1, Wh_GetIntSetting(L"masterButtonHeight"));
g_settings.masterButtonWidth = std::max(1, Wh_GetIntSetting(L"masterButtonWidth"));
g_settings.masterButtonSpacing = Wh_GetIntSetting(L"masterButtonSpacing");
g_settings.gridVerticalOffset = Wh_GetIntSetting(L"gridVerticalOffset");
auto shownColor = [](std::wstring const& value) {
return value.empty() ? L"<empty/automatic>" : value.c_str();
};
Wh_Log(L"[Settings] colors active=%ls inactive=%ls hover=%ls pressed=%ls border=%ls",
shownColor(g_settings.activeColor),
shownColor(g_settings.inactiveColor),
shownColor(g_settings.hoverBackgroundColor),
shownColor(g_settings.pressedBackgroundColor),
shownColor(g_settings.borderColor));
}
// ============================================================
// Globals
// ============================================================
static std::atomic<bool> g_unloading{false};
static HWND g_taskbarWnd = nullptr;
static Grid g_buttonGrid = nullptr;
static FrameworkElement g_injectionParent = nullptr;
static int g_injectedColumn = -1;
static bool g_startOverlayMode = false;
static FrameworkElement g_startOverlayRoot = nullptr;
static FrameworkElement g_startOverlayStart = nullptr;
static winrt::event_token g_startOverlayLayoutToken{};
static FrameworkElement g_taskItemsPanel = nullptr;
static Thickness g_taskItemsPanelOriginalMargin{};
static double g_startButtonOriginalX = -1.0;
static std::atomic<int> g_currentDesktop{0};
static std::atomic<int> g_desktopCount{1};
static HANDLE g_notificationThread = nullptr;
static HANDLE g_notificationStopEvent = nullptr;
static DWORD g_notificationCookie = 0;
static HANDLE g_retryThread = nullptr;
static HANDLE g_retryStopEvent = nullptr;
static std::atomic<bool> g_systemTrayModuleHooked{false};
static std::atomic<int> g_activeSwitchThreads{0};
static std::list<FrameworkElement::Loaded_revoker> g_autoRevokerList;
// Forward declarations
static void ApplyAllSettings();
static void ApplyAllSettingsOnWindowThread();
static void RebuildButtonGrid();
static void RemoveButtonGrid();
static void StopNotificationThread();
static void StopRetryThread();
static void HandleLoadedModuleIfSystemTray(HMODULE hModule, LPCWSTR lpLibFileName);
// ============================================================
// Explorer / twinui build detection
// ============================================================
static WORD g_explorerBuild = 0;
static WORD g_explorerRevision = 0;
static WORD g_twinuiBuild = 0;
static void DetectExplorerBuild() {
wchar_t path[MAX_PATH];
GetModuleFileNameW(nullptr, path, MAX_PATH);
DWORD dummy;
DWORD sz = GetFileVersionInfoSizeW(path, &dummy);
if (!sz) return;
std::vector<BYTE> buf(sz);
if (!GetFileVersionInfoW(path, 0, sz, buf.data())) return;
VS_FIXEDFILEINFO* fi = nullptr; UINT fs = 0;
if (!VerQueryValueW(buf.data(), L"\\", (void**)&fi, &fs)) return;
g_explorerBuild = HIWORD(fi->dwFileVersionLS);
g_explorerRevision = LOWORD(fi->dwFileVersionLS);
Wh_Log(L"[Init] Explorer build %u rev %u", g_explorerBuild, g_explorerRevision);
}
static VS_FIXEDFILEINFO* GetModuleVersionInfo(HMODULE hModule, UINT* puPtrLen) {
void* pFixedFileInfo = nullptr;
UINT uPtrLen = 0;
HRSRC hResource = FindResource(hModule, MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION);
if (hResource) {
HGLOBAL hGlobal = LoadResource(hModule, hResource);
if (hGlobal) {
void* pData = LockResource(hGlobal);
if (pData) {
if (!VerQueryValue(pData, L"\\", &pFixedFileInfo, &uPtrLen) || uPtrLen == 0) {
pFixedFileInfo = nullptr;
uPtrLen = 0;
}
}
}
}
if (puPtrLen) *puPtrLen = uPtrLen;
return (VS_FIXEDFILEINFO*)pFixedFileInfo;
}
static bool LoadTwinuiBuild() {
if (g_twinuiBuild) return true;
HMODULE h = GetModuleHandleW(L"twinui.pcshell.dll");
if (!h) return false;
VS_FIXEDFILEINFO* fi = GetModuleVersionInfo(h, nullptr);
if (!fi) return false;
g_twinuiBuild = HIWORD(fi->dwFileVersionLS);
Wh_Log(L"[VD] twinui.pcshell.dll build %u", g_twinuiBuild);
return true;
}
// Order matters: SystemTray.dll is the new home (Win11 Insider 26200+);
// older builds have the symbols in Taskbar.View.dll.
static HMODULE GetSystemTrayModuleHandle() {
HMODULE module = GetModuleHandleW(L"SystemTray.dll");
if (!module) {
module = GetModuleHandleW(L"Taskbar.View.dll");
if (module) {
// Starting with Taskbar.View.dll 2604.x, the SystemTray types moved
// out into SystemTray.dll — don't hook this version.
VS_FIXEDFILEINFO* fi = GetModuleVersionInfo(module, nullptr);
WORD moduleMajor = fi ? HIWORD(fi->dwFileVersionMS) : 0;
if (!moduleMajor || moduleMajor >= 2604) {
Wh_Log(L"[Hooks] Skipping Taskbar.View.dll version %d", moduleMajor);
module = nullptr;
}
}
}
if (!module)
module = GetModuleHandleW(L"ExplorerExtensions.dll");
return module;
}
// ============================================================
// GetTaskbarXamlRoot boilerplate (from vertical-omnibutton)
// ============================================================
using RunFromWindowThreadProc_t = void (*)(void*);
static bool RunFromWindowThread(HWND hWnd, RunFromWindowThreadProc_t proc, void* procParam) {
static const UINT kMsg = RegisterWindowMessage(L"Windhawk_RunFromWindowThread_" WH_MOD_ID);
struct Param { RunFromWindowThreadProc_t proc; void* procParam; };
DWORD dwThreadId = GetWindowThreadProcessId(hWnd, nullptr);
if (!dwThreadId) return false;
if (dwThreadId == GetCurrentThreadId()) { proc(procParam); return true; }
HHOOK hook = SetWindowsHookEx(WH_CALLWNDPROC, [](int nCode, WPARAM wParam, LPARAM lParam) -> LRESULT {
if (nCode == HC_ACTION) {
const CWPSTRUCT* cwp = (const CWPSTRUCT*)lParam;
if (cwp->message == RegisterWindowMessageW(L"Windhawk_RunFromWindowThread_" WH_MOD_ID)) {
auto* p = (Param*)cwp->lParam;
p->proc(p->procParam);
}
}
return CallNextHookEx(nullptr, nCode, wParam, lParam);
}, nullptr, dwThreadId);
if (!hook) return false;
Param param{ proc, procParam };
SendMessage(hWnd, kMsg, 0, (LPARAM)¶m);
UnhookWindowsHookEx(hook);
return true;
}
static HWND FindCurrentProcessTaskbarWnd() {
HWND result = nullptr;
EnumWindows([](HWND hWnd, LPARAM lParam) -> BOOL {
DWORD pid; WCHAR cls[32];
if (GetWindowThreadProcessId(hWnd, &pid) && pid == GetCurrentProcessId() &&
GetClassName(hWnd, cls, ARRAYSIZE(cls)) && _wcsicmp(cls, L"Shell_TrayWnd") == 0) {
*reinterpret_cast<HWND*>(lParam) = hWnd; return FALSE;
}
return TRUE;
}, reinterpret_cast<LPARAM>(&result));
return result;
}
using CTaskBand_GetTaskbarHost_t = void* (WINAPI*)(void* pThis, void* taskbarHostSharedPtr);
CTaskBand_GetTaskbarHost_t CTaskBand_GetTaskbarHost_Original;
using TaskbarHost_FrameHeight_t = int (WINAPI*)(void* pThis);
TaskbarHost_FrameHeight_t TaskbarHost_FrameHeight_Original;
using std__Ref_count_base__Decref_t = void (WINAPI*)(void* pThis);
std__Ref_count_base__Decref_t std__Ref_count_base__Decref_Original;
static void* CTaskBand_ITaskListWndSite_vftable = nullptr;
static XamlRoot GetTaskbarXamlRoot(HWND hTaskbarWnd) {
// Guard: symbols must be resolved before any dereference.
if (!CTaskBand_GetTaskbarHost_Original || !TaskbarHost_FrameHeight_Original ||
!std__Ref_count_base__Decref_Original ||
!CTaskBand_ITaskListWndSite_vftable)
return nullptr;
HWND hTaskSwWnd = (HWND)GetProp(hTaskbarWnd, L"TaskbandHWND");
if (!hTaskSwWnd) return nullptr;
void* taskBand = (void*)GetWindowLongPtr(hTaskSwWnd, 0);
// Guard: taskBand is null during early startup before the taskband stores its this-pointer.
if (!taskBand) return nullptr;
void* taskBandForSite = taskBand;
for (int i = 0; *(void**)taskBandForSite != CTaskBand_ITaskListWndSite_vftable; i++) {
if (i == 20) return nullptr;
taskBandForSite = (void**)taskBandForSite + 1;
}
void* taskbarHostSharedPtr[2]{};
CTaskBand_GetTaskbarHost_Original(taskBandForSite, taskbarHostSharedPtr);
if (!taskbarHostSharedPtr[0] || !taskbarHostSharedPtr[1]) {
if (taskbarHostSharedPtr[1])
std__Ref_count_base__Decref_Original(taskbarHostSharedPtr[1]);
return nullptr;
}
size_t offset = 0x10;
#if defined(_M_X64)
{
// 48:83EC 28 | sub rsp,28
// 48:83C1 48 | add rcx,48
const BYTE* b = (const BYTE*)TaskbarHost_FrameHeight_Original;
if (b[0]==0x48 && b[1]==0x83 && b[2]==0xEC && b[4]==0x48 &&
b[5]==0x83 && b[6]==0xC1 && b[7]<=0x7F)
offset = b[7];
else
Wh_Log(L"Unsupported TaskbarHost::FrameHeight");
}
#elif defined(_M_ARM64)
{
// 7f2303d5 pacibsp
// fd7bbfa9 stp fp, lr, [sp, #-0x10]!
// fd030091 mov fp, sp
// 080c41f8 ldr x8, [x0, #0x10]!
const DWORD* p = (const DWORD*)TaskbarHost_FrameHeight_Original;
if (p[0] == 0xD503237F && (p[1] & 0xFFC07FFF) == 0xA9807BFD &&
p[2] == 0x910003FD && (p[3] & 0xFFF00FE0) == 0xF8400C00)
offset = (p[3] >> 12) & 0xFF;
else
Wh_Log(L"Unsupported TaskbarHost::FrameHeight");
}
#else
#error "Unsupported architecture"
#endif
auto* iunk = *(IUnknown**)((BYTE*)taskbarHostSharedPtr[0] + offset);
// Guard: iunk is null during early startup before the TaskbarElement is set at offset.
if (!iunk) {
std__Ref_count_base__Decref_Original(taskbarHostSharedPtr[1]);
return nullptr;
}
FrameworkElement taskbarElem = nullptr;
iunk->QueryInterface(winrt::guid_of<FrameworkElement>(), winrt::put_abi(taskbarElem));
auto result = taskbarElem ? taskbarElem.XamlRoot() : nullptr;
std__Ref_count_base__Decref_Original(taskbarHostSharedPtr[1]);
return result;
}
// ============================================================
// XAML helpers
// ============================================================
static FrameworkElement FindChildRecursive(FrameworkElement const& element,
std::function<bool(FrameworkElement)> const& cb, int maxDepth = 20)
{
int n = VisualTreeHelper::GetChildrenCount(element);
for (int i = 0; i < n && maxDepth > 0; i++) {
auto child = VisualTreeHelper::GetChild(element, i).try_as<FrameworkElement>();
if (!child) continue;
if (cb(child)) return child;
auto found = FindChildRecursive(child, cb, maxDepth - 1);
if (found) return found;
}
return nullptr;
}
// ============================================================
// VD COM notification infrastructure
// ============================================================
const CLSID CLSID_ImmersiveShell = {
0xc2f03a33,0x21f5,0x47fa,{0xb4,0xbb,0x15,0x63,0x62,0xa2,0xf2,0x39}
};
const GUID SID_VirtualDesktopNotificationService = {
0xa501fdec,0x4a09,0x464c,{0xae,0x4e,0x1b,0x9c,0x21,0xb8,0x49,0x18}
};
const GUID IID_IVirtualDesktopNotificationService_G = {
0x0cd45e71,0xd927,0x4f15,{0x8b,0x0a,0x8f,0xef,0x52,0x53,0x37,0xbf}
};
MIDL_INTERFACE("0CD45E71-D927-4F15-8B0A-8FEF525337BF")
IVirtualDesktopNotificationService_I : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE Register(IUnknown*, DWORD*) = 0;
virtual HRESULT STDMETHODCALLTYPE Unregister(DWORD) = 0;
};
struct NotifConfig {
int64_t iidPart1 = 0, iidPart2 = 0;
int methodCount = 0, createdIdx = -1, destroyedIdx = -1, currentChangedIdx = -1;
bool hasMonitors = false;
};
struct NotifObject {
void** vtable = nullptr;
LONG refCount = 1;
};
static NotifConfig GetNotifConfig() {
if (g_explorerBuild < 22000) return {};
if (g_explorerBuild < 22483 || (g_explorerBuild == 22621 && g_explorerRevision < 2215))
return { 5481970284372180562ll, -1679294552252794956ll, 13, 7, 9, 11, true };
if (g_explorerBuild < 22631 || (g_explorerBuild == 22631 && g_explorerRevision < 3085))
return { 5123538856297626140ll, 8491238173783613346ll, 14, 6, 8, 10, false };
return { 5308375338100058445ll, -2401892766147978065ll, 14, 6, 8, 10, false };
}
static bool IsOurNotifIface(REFIID riid) {
auto cfg = GetNotifConfig();
if (!cfg.methodCount) return false;
auto p = reinterpret_cast<const int64_t*>(&riid);
return p[0] == cfg.iidPart1 && p[1] == cfg.iidPart2;
}
static HRESULT STDMETHODCALLTYPE Notif_QI(NotifObject* p, REFIID riid, void** ppv) {
if (!ppv) return E_POINTER; *ppv = nullptr;
static const GUID IID_IUnknown_ = {0,0,0,{0xc0,0,0,0,0,0,0,0x46}};
if (InlineIsEqualGUID(riid, IID_IUnknown_) || IsOurNotifIface(riid)) {
*ppv = p; InterlockedIncrement(&p->refCount); return S_OK;
}
return E_NOINTERFACE;
}
static ULONG STDMETHODCALLTYPE Notif_AddRef(NotifObject* p) {
return (ULONG)InterlockedIncrement(&p->refCount);
}
static ULONG STDMETHODCALLTYPE Notif_Release(NotifObject* p) {
LONG r = InterlockedDecrement(&p->refCount);
if (r == 0) { delete[] p->vtable; delete p; }
return (ULONG)std::max(r, 0L);
}
static HRESULT STDMETHODCALLTYPE Notif_HandleUpdate() {
if (g_unloading || !g_taskbarWnd) return S_OK;
RunFromWindowThread(g_taskbarWnd, [](void*) {
if (!g_unloading) RebuildButtonGrid();
}, nullptr);
return S_OK;
}
static HRESULT STDMETHODCALLTYPE Notif_NoOp() { return S_OK; }
static HRESULT STDMETHODCALLTYPE Notif_CountChanged(NotifObject*) { return Notif_HandleUpdate(); }
static HRESULT STDMETHODCALLTYPE Notif_CurrentChanged(NotifObject*) { return Notif_HandleUpdate(); }
static HRESULT STDMETHODCALLTYPE Notif_CurrentChangedWithMonitors(NotifObject*, void*, void*, void*) {
return Notif_HandleUpdate();
}
static NotifObject* CreateNotifObject() {
auto cfg = GetNotifConfig();
if (cfg.methodCount == 0 || cfg.currentChangedIdx < 0) return nullptr;
auto* obj = new (std::nothrow) NotifObject();
if (!obj) return nullptr;
obj->vtable = new (std::nothrow) void*[cfg.methodCount];
if (!obj->vtable) { delete obj; return nullptr; }
for (int i = 0; i < cfg.methodCount; i++) obj->vtable[i] = (void*)&Notif_NoOp;
obj->vtable[0] = (void*)&Notif_QI;
obj->vtable[1] = (void*)&Notif_AddRef;
obj->vtable[2] = (void*)&Notif_Release;
if (cfg.createdIdx >= 0) obj->vtable[cfg.createdIdx] = (void*)&Notif_CountChanged;
if (cfg.destroyedIdx >= 0) obj->vtable[cfg.destroyedIdx] = (void*)&Notif_CountChanged;
obj->vtable[cfg.currentChangedIdx] = cfg.hasMonitors
? (void*)&Notif_CurrentChangedWithMonitors
: (void*)&Notif_CurrentChanged;
return obj;
}
static NotifObject* g_notifObject = nullptr;
static DWORD WINAPI NotificationThreadProc(void*) {
auto cfg = GetNotifConfig();
if (cfg.methodCount == 0) {
Wh_Log(L"[Notif] Unsupported build (explorer %u)", g_explorerBuild);
return 0;
}
if (FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) return 0;
IServiceProvider* svc = nullptr;
if (FAILED(CoCreateInstance(CLSID_ImmersiveShell, nullptr, CLSCTX_LOCAL_SERVER,
IID_IServiceProvider, (void**)&svc)) || !svc) {
CoUninitialize(); return 0;
}
IVirtualDesktopNotificationService_I* notifSvc = nullptr;
svc->QueryService(SID_VirtualDesktopNotificationService,
IID_IVirtualDesktopNotificationService_G, (void**)¬ifSvc);
svc->Release();
if (!notifSvc) { CoUninitialize(); return 0; }
g_notifObject = CreateNotifObject();
if (!g_notifObject) { notifSvc->Release(); CoUninitialize(); return 0; }
HRESULT hr = notifSvc->Register(reinterpret_cast<IUnknown*>(g_notifObject), &g_notificationCookie);
if (FAILED(hr)) {
Wh_Log(L"[Notif] Register failed: 0x%08X", hr);
Notif_Release(g_notifObject); g_notifObject = nullptr;
notifSvc->Release(); CoUninitialize(); return 0;
}
Wh_Log(L"[Notif] Registered, cookie=%lu", g_notificationCookie);
MSG msg;
while (!g_unloading) {
DWORD w = MsgWaitForMultipleObjects(1, &g_notificationStopEvent, FALSE, INFINITE, QS_ALLINPUT);
if (w == WAIT_OBJECT_0) break;
while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessageW(&msg); }
}
if (g_notificationCookie) { notifSvc->Unregister(g_notificationCookie); g_notificationCookie = 0; }
if (g_notifObject) { Notif_Release(g_notifObject); g_notifObject = nullptr; }
notifSvc->Release();
CoUninitialize();
return 0;
}
static void StartNotificationThread() {
if (g_notificationThread) return;
g_notificationStopEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
g_notificationThread = CreateThread(nullptr, 0, NotificationThreadProc, nullptr, 0, nullptr);
if (!g_notificationThread) {
CloseHandle(g_notificationStopEvent); g_notificationStopEvent = nullptr;
}
}
static void StopNotificationThread() {
if (g_notificationStopEvent) SetEvent(g_notificationStopEvent);
if (g_notificationThread) {
// Pump sent messages while waiting so that if Wh_ModUninit is called from
// the UI thread and the notification thread is mid-SendMessage, the sent
// message can be delivered and the notification thread can then exit.
// PeekMessage(PM_NOREMOVE) processes incoming sent messages without
// consuming posted messages from the queue.
DWORD result;
do {
result = MsgWaitForMultipleObjects(1, &g_notificationThread, FALSE, INFINITE, QS_SENDMESSAGE);
if (result == WAIT_OBJECT_0 + 1) {
MSG msg;
PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE);
}
} while (result == WAIT_OBJECT_0 + 1);
CloseHandle(g_notificationThread); g_notificationThread = nullptr;
}
if (g_notificationStopEvent) {
CloseHandle(g_notificationStopEvent); g_notificationStopEvent = nullptr;
}
}
static void StopRetryThread() {
if (g_retryStopEvent) SetEvent(g_retryStopEvent);
if (g_retryThread) {
DWORD result;
do {
result = MsgWaitForMultipleObjects(
1, &g_retryThread, FALSE, INFINITE, QS_SENDMESSAGE);
if (result == WAIT_OBJECT_0 + 1) {
MSG message;
PeekMessageW(&message, nullptr, 0, 0, PM_NOREMOVE);
}
} while (result == WAIT_OBJECT_0 + 1);
CloseHandle(g_retryThread); g_retryThread = nullptr;
}
if (g_retryStopEvent) {
CloseHandle(g_retryStopEvent); g_retryStopEvent = nullptr;
}
}
// ============================================================
// Desktop state — registry
// ============================================================
static std::vector<BYTE> ReadRegBinary(const wchar_t* path, const wchar_t* name) {
DWORD type = 0, size = 0;
if (RegGetValueW(HKEY_CURRENT_USER, path, name, RRF_RT_REG_BINARY, &type, nullptr, &size) != ERROR_SUCCESS || !size)
return {};
std::vector<BYTE> buf(size);
if (RegGetValueW(HKEY_CURRENT_USER, path, name, RRF_RT_REG_BINARY, &type, buf.data(), &size) != ERROR_SUCCESS)
return {};
buf.resize(size);
return buf;
}
static int ReadDesktopCount() {
DWORD sessionId = 0;
ProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
wchar_t sessionPath[256];
swprintf_s(sessionPath, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SessionInfo\\%lu\\VirtualDesktops", sessionId);
for (auto* path : { (const wchar_t*)sessionPath, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VirtualDesktops" }) {
auto buf = ReadRegBinary(path, L"VirtualDesktopIDs");
if (buf.size() >= 16) return (int)(buf.size() / 16);
}
return 1;
}
static int ReadCurrentDesktop() {
DWORD sessionId = 0;
ProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
wchar_t sessionPath[256];
swprintf_s(sessionPath, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SessionInfo\\%lu\\VirtualDesktops", sessionId);
std::vector<BYTE> ids;
for (auto* path : { (const wchar_t*)sessionPath, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VirtualDesktops" }) {
ids = ReadRegBinary(path, L"VirtualDesktopIDs");
if (ids.size() >= 16) break;
}
if (ids.empty()) return 0;
GUID currentGuid{};
bool gotCurrent = false;
for (auto* path : { (const wchar_t*)sessionPath, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VirtualDesktops" }) {
auto buf = ReadRegBinary(path, L"CurrentVirtualDesktop");
if (buf.size() >= 16) { memcpy(¤tGuid, buf.data(), 16); gotCurrent = true; break; }
// Try REG_SZ form
wchar_t strBuf[64]; DWORD sz = sizeof(strBuf), type;
if (RegGetValueW(HKEY_CURRENT_USER, path, L"CurrentVirtualDesktop",
RRF_RT_REG_SZ, &type, strBuf, &sz) == ERROR_SUCCESS &&
SUCCEEDED(CLSIDFromString(strBuf, ¤tGuid))) { gotCurrent = true; break; }
}
if (!gotCurrent) return 0;
int count = (int)(ids.size() / 16);
for (int i = 0; i < count; i++) {
GUID g; memcpy(&g, ids.data() + i * 16, 16);
if (memcmp(&g, ¤tGuid, 16) == 0) return i;
}
return 0;
}
// Read Windows display names for all desktops (registry Desktops\{GUID}\Name).
// Falls back to "Desktop N" when a desktop has no custom name.
static std::vector<std::wstring> ReadDesktopNames(int count) {
DWORD sessionId = 0;
ProcessIdToSessionId(GetCurrentProcessId(), &sessionId);
wchar_t sessionPath[256];