From c67b6b058c92243690aa21d9be20c3ed091d3b7a Mon Sep 17 00:00:00 2001 From: Michael Maltsev <4129781+m417z@users.noreply.github.com> Date: Thu, 30 Nov 2023 00:11:39 +0200 Subject: [PATCH] Taskbar Labels for Windows 11 v1.2.1 * Added a new option: Minimum taskbar item width. * Fixed label texts and icons to refer to the window and not the app. The downside of the fix is that combining can no longer be enabled ("When taskbar is full" still works). This may be addressed in the future. * Fixed "Space between icon and label" calculation in some cases. * Fixed label disappearing when dragging. * Fixed settings applying in some cases. * Fixed for new builds with the labels feature turned off. --- mods/taskbar-labels.wh.cpp | 130 ++++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 37 deletions(-) diff --git a/mods/taskbar-labels.wh.cpp b/mods/taskbar-labels.wh.cpp index 00d4f168f..808565a5a 100644 --- a/mods/taskbar-labels.wh.cpp +++ b/mods/taskbar-labels.wh.cpp @@ -2,7 +2,7 @@ // @id taskbar-labels // @name Taskbar Labels for Windows 11 // @description Show and customize text labels for running programs on the taskbar (Windows 11 only) -// @version 1.2 +// @version 1.2.1 // @author m417z // @github https://github.com/m417z // @twitter https://twitter.com/m417z @@ -35,8 +35,7 @@ versions. **Newer Windows 11 versions:** A native taskbar labels implementation was added in newer Windows 11 versions. For these versions, the mod improves it by making all taskbar items have the same width (optional), adding ellipsis for long -labels, and providing other customization options. Note that you can still use -the taskbar properties to configure taskbar combining. +labels, and providing other customization options. Before: @@ -60,6 +59,11 @@ choose one of the following running indicator styles: $description: >- Set to 0 to use the Windows adaptive width, only for newer Windows versions with the built-in taskbar labels implementation +- minimumTaskbarItemWidth: 50 + $name: Minimum taskbar item width + $description: >- + The minimum width before the taskbar overflows, only for newer Windows + versions with the built-in taskbar labels implementation - runningIndicatorStyle: centerFixed $name: Running indicator style $options: @@ -138,6 +142,7 @@ enum class IndicatorStyle { struct { int taskbarItemWidth; + int minimumTaskbarItemWidth; IndicatorStyle runningIndicatorStyle; IndicatorStyle progressIndicatorStyle; int fontSize; @@ -793,17 +798,23 @@ void UpdateTaskListButtonWithLabelStyle( FindChildByName(iconPanelElement, L"LabelControl") .as(); if (labelControlElement) { - labelControlElement.HorizontalAlignment( - g_unloading ? HorizontalAlignment::Center - : HorizontalAlignment::Left); + auto horizontalAlignment = g_unloading ? HorizontalAlignment::Center + : HorizontalAlignment::Left; + if (labelControlElement.HorizontalAlignment() != horizontalAlignment) { + labelControlElement.HorizontalAlignment(horizontalAlignment); + } - labelControlElement.TextTrimming( - g_unloading ? TextTrimming::Clip : TextTrimming::CharacterEllipsis); + auto textTrimming = + g_unloading ? TextTrimming::Clip : TextTrimming::CharacterEllipsis; + if (labelControlElement.TextTrimming() != textTrimming) { + labelControlElement.TextTrimming(textTrimming); + } auto labelControlMargin = labelControlElement.Margin(); labelControlMargin.Left = g_unloading ? 0 : (iconElement.ActualWidth() - 24 + + g_settings.leftAndRightPaddingSize - 8 + g_settings.spaceBetweenIconAndLabel - 8); labelControlMargin.Right = g_unloading ? 0 : (g_settings.leftAndRightPaddingSize - 10); @@ -1179,43 +1190,64 @@ void WINAPI TaskListButton_Icon_Hook(void* pThis, LONG_PTR randomAccessStream) { } } -using ITaskbarAppItemViewModel_get_HasLabel_t = - HRESULT(WINAPI*)(void* pThis, bool* hasLabel); -ITaskbarAppItemViewModel_get_HasLabel_t - ITaskbarAppItemViewModel_get_HasLabel_Original; -HRESULT WINAPI ITaskbarAppItemViewModel_get_HasLabel_Hook(void* pThis, - bool* hasLabel) { +using TaskbarSettings_GroupingMode_t = DWORD(WINAPI*)(void* pThis); +TaskbarSettings_GroupingMode_t TaskbarSettings_GroupingMode_Original; +DWORD WINAPI TaskbarSettings_GroupingMode_Hook(void* pThis) { Wh_Log(L">"); - HRESULT ret = - ITaskbarAppItemViewModel_get_HasLabel_Original(pThis, hasLabel); - if (SUCCEEDED(ret) && !g_unloading) { - *hasLabel = true; + DWORD ret = TaskbarSettings_GroupingMode_Original(pThis); + + if (!g_unloading) { + // "Always" mode isn't supported, switch to "Never". + if (ret == 0) { + ret = 2; + } + } + + if (g_overrideGroupingMode) { + if (ret == 0) { + ret = 2; + } else { + ret = 0; + } } return ret; } -using TaskbarSettings_GroupingMode_t = DWORD(WINAPI*)(void* pThis); -TaskbarSettings_GroupingMode_t TaskbarSettings_GroupingMode_Original; -DWORD WINAPI TaskbarSettings_GroupingMode_Hook(void* pThis) { +using TaskListButton_MinScalableWidth_t = float(WINAPI*)(void* pThis); +TaskListButton_MinScalableWidth_t TaskListButton_MinScalableWidth_Original; +float WINAPI TaskListButton_MinScalableWidth_Hook(void* pThis) { Wh_Log(L">"); - DWORD ret = TaskbarSettings_GroupingMode_Original(pThis); + float ret = TaskListButton_MinScalableWidth_Original(pThis); - if (g_overrideGroupingMode) { - if (ret == 2) { - ret = 0; - } else { - ret = 2; + if (!g_unloading && g_hasNativeLabelsImplementation) { + // Allow to create many taskbar items before overflow appears. + int minimumTaskbarItemWidth = g_settings.minimumTaskbarItemWidth; + if (minimumTaskbarItemWidth < 44) { + minimumTaskbarItemWidth = 44; + } + + if (ret > minimumTaskbarItemWidth) { + ret = minimumTaskbarItemWidth; } } return ret; } +void* wil_Feature_GetImpl_Original; + +using WilFeatureTraits_Feature_29785186_IsEnabled_t = + bool(WINAPI*)(void* pThis); +WilFeatureTraits_Feature_29785186_IsEnabled_t + WilFeatureTraits_Feature_29785186_IsEnabled_Original; + void LoadSettings() { g_settings.taskbarItemWidth = Wh_GetIntSetting(L"taskbarItemWidth"); + g_settings.minimumTaskbarItemWidth = + Wh_GetIntSetting(L"minimumTaskbarItemWidth"); PCWSTR runningIndicatorStyle = Wh_GetStringSetting(L"runningIndicatorStyle"); @@ -1554,20 +1586,37 @@ bool HookTaskbarViewDllSymbols(HMODULE module) { }, { { - LR"(public: virtual int __cdecl winrt::impl::produce::get_HasLabel(bool *))", - LR"(public: virtual int __cdecl winrt::impl::produce::get_HasLabel(bool * __ptr64) __ptr64)", + LR"(public: __cdecl winrt::impl::consume_WindowsUdk_UI_Shell_ITaskbarSettings5::GroupingMode(void)const )", + LR"(public: __cdecl winrt::impl::consume_WindowsUdk_UI_Shell_ITaskbarSettings5::GroupingMode(void)const __ptr64)", }, - (void**)&ITaskbarAppItemViewModel_get_HasLabel_Original, - (void*)ITaskbarAppItemViewModel_get_HasLabel_Hook, + (void**)&TaskbarSettings_GroupingMode_Original, + (void*)TaskbarSettings_GroupingMode_Hook, true, }, { { - LR"(public: __cdecl winrt::impl::consume_WindowsUdk_UI_Shell_ITaskbarSettings5::GroupingMode(void)const )", - LR"(public: __cdecl winrt::impl::consume_WindowsUdk_UI_Shell_ITaskbarSettings5::GroupingMode(void)const __ptr64)", + LR"(public: float __cdecl winrt::Taskbar::implementation::TaskListButton::MinScalableWidth(void))", + LR"(public: float __cdecl winrt::Taskbar::implementation::TaskListButton::MinScalableWidth(void) __ptr64)", }, - (void**)&TaskbarSettings_GroupingMode_Original, - (void*)TaskbarSettings_GroupingMode_Hook, + (void**)&TaskListButton_MinScalableWidth_Original, + (void*)TaskListButton_MinScalableWidth_Hook, + true, + }, + { + { + LR"(class wil::details::FeatureImpl `private: static class wil::details::FeatureImpl & __cdecl wil::Feature::GetImpl(void)'::`2'::impl)", + }, + (void**)&wil_Feature_GetImpl_Original, + nullptr, + true, + }, + { + { + LR"(public: bool __cdecl wil::details::FeatureImpl::__private_IsEnabled(enum wil::ReportingKind))", + LR"(public: bool __cdecl wil::details::FeatureImpl::__private_IsEnabled(enum wil::ReportingKind) __ptr64)", + }, + (void**)&WilFeatureTraits_Feature_29785186_IsEnabled_Original, + nullptr, true, }, }; @@ -1657,8 +1706,15 @@ BOOL ModInitWithTaskbarView(HMODULE taskbarViewModule) { return FALSE; } - g_hasNativeLabelsImplementation = - !!ITaskbarAppItemViewModel_get_HasLabel_Original; + if (wil_Feature_GetImpl_Original && + WilFeatureTraits_Feature_29785186_IsEnabled_Original) { + g_hasNativeLabelsImplementation = + WilFeatureTraits_Feature_29785186_IsEnabled_Original( + wil_Feature_GetImpl_Original); + } else { + g_hasNativeLabelsImplementation = + !!TaskbarSettings_GroupingMode_Original; + } if (!g_hasNativeLabelsImplementation) { if (!HookTaskbarDllSymbols()) {