ramensoftware / windhawk-mods

The official collection of Windhawk mods
269 stars 52 forks source link

[Taskbar Disappearing Icon Fix for Windows 11] Still disappears after PC wakes up #903

Open usernamelectro opened 2 weeks ago

usernamelectro commented 2 weeks ago
          @usernamelectro @Marshall-Brooks I need more specific info to try to make a fix, including:

Please open an issue to provide your information and track the issue.

Originally posted by @yezhiyi9670 in https://github.com/ramensoftware/windhawk-mods/issues/827#issuecomment-2311594001

usernamelectro commented 2 weeks ago

System version:

Microsoft Windows 11 Version 23H2 (OS Build 22631.4037)

Detailed description:

Is the mod loaded successfully (check the Loaded Mods list)?

    Yes, the mod is loaded successfully.

Does the icon reappear if you click on it?

    Some icons reappear when I click on them, some stay invisible.
    Icons of those apps that are already running stay hidden, but newly started ones reveal themselves.

https://github.com/user-attachments/assets/a8f31a76-c4a9-4a43-a1b1-b2e6c441a3f8

Does the icon reappear a few seconds later even if you do nothing?

    No, it stays like that if I don't click it.

Is it related to virtual desktops?

    I think it is related because taskbar icons become invisible after I change between virtual desktops, and then put my PC to sleep.

How to reproduce (if you can find a way)?

    It is difficult to say because it seems that the problem appears randomly, every other shutdown/sleep, I cannot make a connection to any other software that is running etc.
Marshall-Brooks commented 2 weeks ago

System version: Windows 11 Enterprise 23H2 OS Build 22631.4037

Detailed description: Is the mod loaded successfully (check the Loaded Mods list)? Does the icon reappear if you click on it? Does the icon reappear a few seconds later even if you do nothing? Is it related to virtual desktops? How to reproduce (if you can find a way)?

Mod appears to be loaded successfully, although I didn't check when the issue occurred.

AFAIK, icon does not reappear if I click on it.

Icon does not reappear if I do nothing. Icon does reappear if I cycle the Taskbar Labels For Windows 11 mod.

Not sure if related to virtual desktops. I don't use virtual desktops, but the "Virtual Desktop Preserve Taskbar Order" mod also greatly reduces the frequency of the issue.

Difficult to reproduce. I see the issue only with multiple instances of Microsoft Access. I saw it more frequently with a version of Access database that hid the interface during loading, but even with that, it only happened perhaps 50% of the time.

Update: I may be able to reproduce. For some reason, I get the error pretty consistently if I have Access open and then open a different database using a batch file instead of directly opening it.

usernamelectro commented 2 weeks ago

For me the "Virtual Desktop Preserve Taskbar Order" doesn't reduce the frequency of the issue. sshot-2024-08-29- 20-24-20 It seems that the issue arises almost exclusively when I wake up the PC. Other than that, I didn't even used other virtual desktops today, not even starting any new app there.

Need to mention that the icon will reappear when I start the app that was previously closed, but will not reappear on a currently running app.

Marshall-Brooks commented 2 weeks ago

@usernamelectro - There might well be other ways, but I've found the easiest way to get the icons back is to toggle off and back on "Taskbar Labels For Windows 11". I have a lot of customizations in that mod, but I think you could load it in Windhawk and not change anything and toggling it should restore the icons. It's a pain to have to do it, but it's easier than closing and re-opening your running apps.

I never hibernate the PC, but I can re-create the issue, so hopefully between the four of us (you, me, @m417z , @yezhiyi9670 ) we'll be able to find a solution!

usernamelectro commented 2 weeks ago

@Marshall-Brooks I will try to toggle on/off the "Taskbar Labels For Windows 11" next time I see the issue, at least to save myself from re-opening my running apps. Thanks for this tip.

sshot-2024-08-29- 21-08-22

Fast startup is turned off, and I am putting my PC to sleep via that Sleep button through the Start Menu. Hybrid sleep is turned on.

sshot-2024-08-29- 21-09-04

sshot-2024-08-29- 21-07-57

yezhiyi9670 commented 2 weeks ago

I am actually using the Windows 11 24H2 pre-release now and have not seen icons disappearing on wakeup so far, but perhaps I can try to make a fix. Next time when it happens, please tell me:

usernamelectro commented 2 weeks ago

I am actually using the Windows 11 24H2 pre-release now and have not seen icons disappearing on wakeup so far, but perhaps I can try to make a fix. Next time when it happens, please tell me:

* Do the icons reappear if you switch to another virtual desktop and then back (with the fix mod on)?

I am afraid not, those icons are there to stay invisible even if I change to another virtual desktop.

https://github.com/user-attachments/assets/e5b7c751-d190-4a75-a6ed-2e36bb52ca93

@usernamelectro - There might well be other ways, but I've found the easiest way to get the icons back is to toggle off and back on "Taskbar Labels For Windows 11".

https://github.com/user-attachments/assets/e8068447-38ce-49bb-8cfc-94ad9ccd3f2a

It seems that even toggling on/off "Taskbar Labels For Window 11" doesn't reveal all icons.

m417z commented 2 weeks ago

@usernamelectro When that happens, does reordering the items help?

@yezhiyi9670 During the development of Vertical Taskbar for Windows 11, I discovered that sometimes, the iconsl Translation somehow ends up being 0,NaN,0, which causes the icons to disappear. I'm not sure why it happens and if it's related to the transformations the mod does, or perhaps it just makes it more likely, but the following fixed it for at least some cases:

https://github.com/ramensoftware/windhawk-mods/blob/387771ec375561f49fffc1429b8b185f54feb5e4/mods/taskbar-vertical.wh.cpp#L1202-L1204

Perhaps adding it to your mod will help as well. And I think it's worth applying the fix for all icons after the system wakes up, perhaps after some short delay. Hooking the taskbar's WndProc and handling WM_POWERBROADCAST should work. Let me know if you need help with implementing it.

usernamelectro commented 2 weeks ago

@usernamelectro When that happens, does reordering the items help?

@m417z It seems that reordering does nothing, the icons stay that way like they are frozen.

https://github.com/user-attachments/assets/0613de6f-0436-4e8e-a836-0c25e9de0884

m417z commented 2 weeks ago

It seems that reordering does nothing, the icons stay that way like they are frozen.

I was actually referring to the invisible items. Sometimes when icons disappear on my computer, dragging the items with the hidden icons around makes the icons come back. More specifically, when I click and hold the mouse on a hidden icon, this specific icon appears, but I need to do it for each hidden icon separately.

Also, I quickly added the Translation workaround that I talked about in my previous comment. Below is a test mod, let me know if it works any better. To try it, disable the existing mod, then click the bottom right button to create a new mod, replace the code with the test mod code, click "Compile Mod", then "Exit Editing Mode".

Text mod (click to expand)

```cpp // ==WindhawkMod== // @id taskbar-disappearing-icon-fix-win11-test // @name Taskbar Disappearing Icon Fix for Windows 11 (test) // @description Tries to fix disappearing icon in Windows 11 taskbar while switching virtual desktops. // @version 1.0 // @author yezhiyi9670 // @github https://github.com/yezhiyi9670 // @include explorer.exe // @architecture x86-64 // @compilerOptions -DWINVER=0x0605 -loleaut32 -lole32 -lruntimeobject -lwininet // ==/WindhawkMod== // Source code is published under The GNU General Public License v3.0. // // Framework based on taskbar-labels mod by @m417z // ==WindhawkModReadme== /* # Taskbar Disappearing Icon Fix for Windows 11 Tries to fix disappearing icon bug in Windows 11 taskbar while switching virtual desktops. Since I cannot reproduce this bug very reliably, this mod may not have fixed the bug entirely. Let me know if it still persists. Takeaway message: - It is observed that hiding (`Visibility: Collapsed`) the invisible icon and then making it visible after a while will fix it. - However, hiding the icon for a while results in flickering. - The mod tries to flicker the icon only when the system tries to change its display name, typically while switching virtual desktops, making the flicker hardly visible. */ // ==/WindhawkModReadme== // #==WindhawkModSettings== /* # Here you can define settings, in YAML format, that the mod users will be able # to configure. Metadata values such as $name and $description are optional. # Check out the documentation for more information: # https://github.com/ramensoftware/windhawk/wiki/Creating-a-new-mod#settings */ // #==/WindhawkModSettings== #undef GetCurrentTime #include // must come before knownfolders.h #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace winrt::Windows::UI::Xaml; using namespace winrt::Windows::Foundation::Numerics; // =========================================================== WCHAR g_taskbarViewDllPath[MAX_PATH]; std::atomic g_unloading = false; // =========================================================== HWND GetTaskbarWnd() { static HWND hTaskbarWnd; if (!hTaskbarWnd) { HWND hWnd = FindWindow(L"Shell_TrayWnd", nullptr); DWORD processId = 0; if (hWnd && GetWindowThreadProcessId(hWnd, &processId) && processId == GetCurrentProcessId()) { hTaskbarWnd = hWnd; } } return hTaskbarWnd; } bool GetTaskbarViewDllPath(WCHAR path[MAX_PATH]) { WCHAR szWindowsDirectory[MAX_PATH]; if (!GetWindowsDirectory(szWindowsDirectory, ARRAYSIZE(szWindowsDirectory))) { Wh_Log(L"GetWindowsDirectory failed"); return false; } // Windows 11 version 22H2. wcscpy_s(path, MAX_PATH, szWindowsDirectory); wcscat_s( path, MAX_PATH, LR"(\SystemApps\MicrosoftWindows.Client.Core_cw5n1h2txyewy\Taskbar.View.dll)"); if (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES) { return true; } // Windows 11 version 21H2. wcscpy_s(path, MAX_PATH, szWindowsDirectory); wcscat_s( path, MAX_PATH, LR"(\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\ExplorerExtensions.dll)"); if (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES) { return true; } return false; } // =========================================================== void RefreshTaskbar() { HWND hTaskbarWnd = GetTaskbarWnd(); if (!hTaskbarWnd) { return; } SendMessage(hTaskbarWnd, WM_SETTINGCHANGE, 0, 0); Sleep(400); SendMessage(hTaskbarWnd, WM_SETTINGCHANGE, 0, 0); } FrameworkElement FindChildByName(FrameworkElement element, PCWSTR name) { int childrenCount = Media::VisualTreeHelper::GetChildrenCount(element); for (int i = 0; i < childrenCount; i++) { auto child = Media::VisualTreeHelper::GetChild(element, i) .try_as(); if (!child) { Wh_Log(L"Failed to get child %d of %d", i + 1, childrenCount); continue; } if (child.Name() == name) { return child; } } return nullptr; } // =========================================================== void HideAndShowIcon(FrameworkElement taskListButtonElement) { if(g_unloading) { return; } auto iconPanelElement = FindChildByName(taskListButtonElement, L"IconPanel"); if (!iconPanelElement) { return; } auto iconElement = FindChildByName(iconPanelElement, L"Icon") .as(); if (iconElement) { // For some reason, translation is being set to a NaN. iconElement.Translation( winrt::Windows::Foundation::Numerics::float3::zero()); iconElement.Visibility(Visibility::Collapsed); iconElement.Dispatcher().TryRunAsync(winrt::Windows::UI::Core::CoreDispatcherPriority::Low, [iconElement](){ iconElement.Visibility(Visibility::Visible); }); } } using TaskListButton_Hook2_t = void(WINAPI*)(void* pThis, struct winrt::hstring w); TaskListButton_Hook2_t TaskListButton_Hook2_Original; void WINAPI TaskListButton_Hook2_Hook(void* pThis, struct winrt::hstring w) { TaskListButton_Hook2_Original(pThis, w); Wh_Log(L">Hook2"); void* taskListButtonIUnknownPtr = (void**)pThis + 3; winrt::Windows::Foundation::IUnknown taskListButtonIUnknown; winrt::copy_from_abi(taskListButtonIUnknown, taskListButtonIUnknownPtr); auto taskListButtonElement = taskListButtonIUnknown.as(); HideAndShowIcon(taskListButtonElement); } // =========================================================== bool HookTaskbarViewDllSymbols(HMODULE module) { // taskbar.view.dll, ExplorerExtensions.dll WindhawkUtils::SYMBOL_HOOK symbolHooks[] = { // { // { // LR"(private: void __cdecl winrt::Taskbar::implementation::TaskListButton::UpdateVisualStates(void))", // LR"(private: void __cdecl winrt::Taskbar::implementation::TaskListButton::UpdateVisualStates(void) __ptr64)", // }, // (void**)&TaskListButton_Hook2_Original, // (void*)TaskListButton_Hook2_Hook, // }, // { // { // LR"(public: void __cdecl winrt::Taskbar::implementation::TaskListButton::Icon(struct winrt::Windows::Storage::Streams::IRandomAccessStream))", // LR"(public: void __cdecl winrt::Taskbar::implementation::TaskListButton::Icon(struct winrt::Windows::Storage::Streams::IRandomAccessStream) __ptr64)", // }, // (void**)&TaskListButton_Hook2_Original, // (void*)TaskListButton_Hook2_Hook, // }, { { LR"(public: void __cdecl winrt::Taskbar::implementation::TaskListButton::DisplayName(struct winrt::hstring))", LR"(public: void __cdecl winrt::Taskbar::implementation::TaskListButton::DisplayName(struct winrt::hstring) __ptr64)", }, (void**)&TaskListButton_Hook2_Original, (void*)TaskListButton_Hook2_Hook, }, }; return WindhawkUtils::HookSymbols(module, symbolHooks, ARRAYSIZE(symbolHooks)); } BOOL ModInitWithTaskbarView(HMODULE taskbarViewModule) { if (!HookTaskbarViewDllSymbols(taskbarViewModule)) { return FALSE; } return TRUE; } // =========================================================== // The mod is being initialized, load settings, hook functions, and do other // initialization stuff if required. BOOL Wh_ModInit() { Wh_Log(L">"); if (!GetTaskbarViewDllPath(g_taskbarViewDllPath)) { Wh_Log(L"Taskbar view module not found"); return FALSE; } HMODULE taskbarViewModule = LoadLibraryEx(g_taskbarViewDllPath, nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); if (taskbarViewModule) { return ModInitWithTaskbarView(taskbarViewModule); } else { return FALSE; } return TRUE; } // The mod is being unloaded, free all allocated resources. void Wh_ModUninit() { Wh_Log(L">"); } void Wh_ModAfterInit() { Wh_Log(L">"); RefreshTaskbar(); } void Wh_ModBeforeUninit() { Wh_Log(L">"); g_unloading = true; RefreshTaskbar(); // This is required to give time for taskbar buttons of UWP apps to // update the layout. Sleep(400); } ```

yezhiyi9670 commented 2 weeks ago

I will add the Translation fix for now. However, I'm not sure if it will fix the problem entirely. (I did not observe the NaN Translation in 24H2.)

usernamelectro commented 2 weeks ago

I was actually referring to the invisible items. Sometimes when icons disappear on my computer, dragging the items with the hidden icons around makes the icons come back. More specifically, when I click and hold the mouse on a hidden icon, this specific icon appears, but I need to do it for each hidden icon separately.

This happened again after I loaded the Mod with fix, and goes like this:

https://github.com/user-attachments/assets/909811cc-7553-4bb5-bdcc-c469eef24e4f

I've tried reordering invisible icons, but the are not revealed nonetheless.

m417z commented 1 week ago

Looks like it didn't work. One of the following can help:

image

Marshall-Brooks commented 1 week ago

I had a icon disappear today and was going to try the UWPSpy on it, but I re-ordered the icons (right click and shift up from the pop-up list) and it re-appeared. So possibly @usernamelectro and myself have the same symptoms with different causes.

usernamelectro commented 15 hours ago

This morning was like this when I woke up the PC.

https://github.com/user-attachments/assets/1f3de97f-29b9-48b7-91e1-561dcfa90c3a

Only Windows Explorer icon was revealed after I changed to the 3rd virtual desktop.

Grab UWPSpy, inspect explorer.exe, focus on a hidden icon (you can focus over the element list, move your mouse over the hidden icon and press Ctrl+D) and make a screenshot. Something similar to the screenshot below, but make sure all properties are visible. Also, you can try to play with the properties and see if changing anything helps.

I've tried playing with some properties:

https://github.com/user-attachments/assets/5b7e66b9-3ff7-4455-b56a-f2354960a14b

m417z commented 2 hours ago

@usernamelectro Thanks. Next time, please do a similar test with the icon below, see screenshot. Also, try to hide and unhide it. You can do it by right-clicking on the item in the element tree.

image