feat(systray): added systray explorer.exe hook mode#802
Merged
amnweb merged 1 commit intoamnweb:mainfrom Mar 21, 2026
Merged
Conversation
71d7f49 to
f0d2d72
Compare
925868c to
96b4133
Compare
- added systray `explorer.exe` hook mode and updated the docs - will inject a dll into explorer.exe process to monitor icon changes - the hook will automatically detach when yasb is closed (named mutex) - added `systray_hook.py` to handle injection and data processing - added `hook` folder to store the dll and source code - added cmake config to build the dll for both x64 and arm64 - modified build.py to copy the correct dll to the lib folder - compiled dlls (x64 and arm64) are included in the repo - dll cross injection is not supported and will revert to legacy mode - some systray refactoring
96b4133 to
f0d8e5f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With this PR the default mode of icon interception for systray will be hook mode (
use_hook: true)The old method (monitor)
The old method was to create a hidden win32 window with class name
Shell_TrayWndand keep it topmost on a timer to intercept all the messages coming from shell32 to explorer.exe process. After processing, those messages were forwarded to the original taskbar.This caused plenty of compatibility issues as some apps were discovering YASB systray monitor instead of the native taskbar window when using
FindWindowfunction.The new method (hook)
The new hook method takes a completely different approach. It injects a small dll into explorer.exe process and inserts itself in the message loop intercepting
WM_COPYDATAmessages and sending all the relevant data via named pipe to YASB. After the copy of the message is sent via pipe, the original message is safely forwarded back to the explorer machinery.Because hIcon (and other handles) is only guaranteed to be valid before it's consumed by the original process, all the icon processing is performed on the DLL side and already processed icon bytes are sent via pipe directly. Without that there will be race conditions where hIcon is invalidated before python has a chance to process it.
Failure handling
dllis missing for some reason (AV deleted it) the original monitor method will be used automatically.How to compile
CMake and Visual Studio (MSBuild) should be installed.
Running
build_dll.batshould place the binary directly where it should be for everything to work.Alternatively, Ninja+Clang can be used:
Changelog
explorer.exehook mode and updated the docssystray_hook.pyto handle injection and data processinghookfolder to store the dll and source code