From 881a5daee8bdcf6cdc0e8f6a7ca99ebbeab1f569 Mon Sep 17 00:00:00 2001 From: Michael Maltsev <4129781+m417z@users.noreply.github.com> Date: Sat, 16 Dec 2023 12:04:01 +0200 Subject: [PATCH] Windows 11 Taskbar Styler v1.2.1 (#428) * Fixed a possible crash and style applying bugs when settings are changed. * Added link to the Windows 11 taskbar styling guide. --- mods/windows-11-taskbar-styler.wh.cpp | 34 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/mods/windows-11-taskbar-styler.wh.cpp b/mods/windows-11-taskbar-styler.wh.cpp index a766b075d..16b1d3468 100644 --- a/mods/windows-11-taskbar-styler.wh.cpp +++ b/mods/windows-11-taskbar-styler.wh.cpp @@ -2,7 +2,7 @@ // @id windows-11-taskbar-styler // @name Windows 11 Taskbar Styler // @description An advanced mod to override style attributes of the taskbar control elements -// @version 1.2 +// @version 1.2.1 // @author m417z // @github https://github.com/m417z // @twitter https://twitter.com/m417z @@ -41,6 +41,10 @@ SystemTrayResources.xbf](https://gist.github.com/m417z/ad0ab39351aca905f1d186b1f The [UWPSpy](https://ramensoftware.com/uwpspy) tool can be used to inspect the taskbar's control elements in real time, and experiment with various styles. +For a collection of commonly requested taskbar styling customizations, check out +[The Windows 11 taskbar styling +guide](https://github.com/ramensoftware/windows-11-taskbar-styling-guide/blob/main/README.md). + ## Control styles Each entry has a target control and a list of styles. @@ -112,7 +116,8 @@ A couple of practical examples: ### Hide the network notification icon * Target: `systemtray:OmniButton#ControlCenterButton > Grid > ContentPresenter > - ItemsPresenter > StackPanel > ContentPresenter[1]` + ItemsPresenter > StackPanel > ContentPresenter[1] > systemtray:IconView > Grid + > Grid` * Style: `Visibility=Collapsed` **Note**: To hide the volume notification icon instead, use `[2]` instead of @@ -2236,7 +2241,7 @@ void ProcessResourceVariablesFromSettings() { } void UninitializeSettingsAndTap() { - for (auto& [k, v] : g_elementsCustomizationState) { + for (const auto& [k, v] : g_elementsCustomizationState) { auto oldElement = v.element.get(); if (oldElement) { auto oldElementDo = oldElement.as(); @@ -2267,12 +2272,16 @@ void UninitializeSettingsAndTap() { g_elementsCustomizationRulesLoaded = false; g_elementsCustomizationRules.clear(); + + g_targetThreadId = 0; } void InitializeSettingsAndTap() { - UninitializeSettingsAndTap(); - - g_targetThreadId = GetCurrentThreadId(); + DWORD kNoThreadId = 0; + if (!g_targetThreadId.compare_exchange_strong(kNoThreadId, + GetCurrentThreadId())) { + return; + } HRESULT hr = InjectWindhawkTAP(); if (FAILED(hr)) { @@ -2423,11 +2432,20 @@ void Wh_ModUninit() { void Wh_ModSettingsChanged() { Wh_Log(L">"); + if (g_visualTreeWatcher) { + g_visualTreeWatcher->UnadviseVisualTreeChange(); + g_visualTreeWatcher = nullptr; + } + HWND hTaskbarUiWnd = GetTaskbarUiWnd(); if (hTaskbarUiWnd) { - Wh_Log(L"Initializing - Found DesktopWindowContentBridge window"); + Wh_Log(L"Reinitializing - Found DesktopWindowContentBridge window"); RunFromWindowThread( - hTaskbarUiWnd, [](PVOID) WINAPI { InitializeSettingsAndTap(); }, + hTaskbarUiWnd, + [](PVOID) WINAPI { + UninitializeSettingsAndTap(); + InitializeSettingsAndTap(); + }, nullptr); } }