Conversation
Description: Toggle desktop icon visibility with a customizable hotkey (default Ctrl+Alt+D). Includes support for configurable modifiers and key. Tested on Windows 11 24h2 (64-bit). Icons automatically restore when the mod is disabled. Lightweight and user-friendly. This mod was cobbled together out of multiple hours of work with AI and a moderate level of understanding. There is also a AHK script I created to coincide meant to link to this mods hotkey which will be up in my Win11 repo soon, This is so that you can call it from the other mod taskbar-empty-space-clicks ie Middle click = calls ahk which triggers the hotkey associated with this mod.
**Major Changes:** 1. **Window Subclassing System Overhaul (Comments ramensoftware#1, ramensoftware#10)** - Replaced `SetWindowLongPtrW` with `WindhawkUtils::SetWindowSubclassFromAnyThread` for all window subclassing - Removed fallback ListView subclassing (it was unnecessary since SHELLDLL_DefView handles input properly) - Added proper cleanup with `RemoveWindowSubclassFromAnyThread` in WM_NCDESTROY handlers - Updated function signatures to use `DefSubclassProc` instead of `CallWindowProcW` 2. **Process Isolation (Comments ramensoftware#4, ramensoftware#6)** - Added `IsWindowInCurrentProcess()` helper function - Now verifies ListView and ShellView belong to current explorer.exe process - Prevents mod from affecting other explorer processes 3. **Settings API Fixes (Comments ramensoftware#2, ramensoftware#3)** - Fixed `Wh_GetIntSetting` calls to use single argument (removed incorrect TRUE parameter) - Added `Wh_FreeStringSetting` to properly free string memory - Changed settings structure to nested `modifierKeys` object (matches Windhawk patterns) 4. **Initialization Improvements (Comments ramensoftware#7, ramensoftware#8)** - Removed `Sleep(2000)` hack from `Wh_ModAfterInit` - Removed unnecessary `bInitialized` flag - Added `EnsureValidListView()` helper for dynamic ListView validation - ListView now re-discovered on-demand if window becomes invalid 5. **Code Cleanup (Comments ramensoftware#5, ramensoftware#9)** - Removed redundant `RestoreIconsToVisible` call from `Wh_ModBeforeUninit` (already in Wh_ModUninit) - Added null checks and proper error handling throughout - Added `ToUpperCase()` helper for case-insensitive key matching **Additional Improvements:** - Added `<commctrl.h>` and `<windhawk_utils.h>` includes - Added `--optimize=0 --debug` compiler options - Enhanced documentation in readme with modifier key details - Better logging and error messages throughout
There was a problem hiding this comment.
Pull request overview
This PR adds a new Windhawk mod that allows users to toggle desktop icon visibility using a configurable hotkey (default: Ctrl+Alt+D). The mod is a complete rewrite addressing feedback from a previous review, with major improvements to window subclassing, process isolation, settings API usage, and initialization logic.
Key Changes
- Implements proper window subclassing using WindhawkUtils API with automatic cleanup
- Adds process isolation to prevent the mod from affecting other explorer.exe instances
- Implements configurable hotkey support with nested settings structure
- Includes robust window discovery with dynamic re-validation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
**Major Changes:** 1. **Window Subclassing System Overhaul (Comments [1](ramensoftware#2267 (comment)), [10](ramensoftware#2267 (comment) - Replaced `SetWindowLongPtrW` with `WindhawkUtils::SetWindowSubclassFromAnyThread` for all window subclassing - Updated subclass callbacks to use the standard `DWORD_PTR` refData parameter (matches `SetWindowSubclass`/WindhawkUtils expectations) - Removed fallback ListView subclassing (SHELLDLL_DefView handles input properly) - Added proper cleanup with `RemoveWindowSubclassFromAnyThread` in WM_NCDESTROY handlers - Updated function signatures to use `DefSubclassProc` instead of `CallWindowProcW` 2. **Process Isolation (Comments [4](ramensoftware#2267 (comment)), [6](ramensoftware#2267 (comment) - Added `IsWindowInCurrentProcess()` helper function - Now verifies ListView and ShellView belong to current explorer.exe process - Added a process check for `SHELLDLL_DefView` under Progman; if not current-process, falls back to WorkerW search - Prevents the mod from affecting other explorer processes 3. **Settings API Fixes (Comments [2](ramensoftware#2267 (comment)), [3](ramensoftware#2267 (comment) - Fixed `Wh_GetIntSetting` calls to use single argument (removed incorrect TRUE parameter) - Added `Wh_FreeStringSetting` to properly free string memory - Changed settings structure to nested `modifierKeys` object (matches Windhawk patterns) 4. **Initialization Improvements (Comments [7](ramensoftware#2267 (comment)), [8](ramensoftware#2267 (comment) - Removed `Sleep(2000)` hack from `Wh_ModAfterInit` - Removed unnecessary `bInitialized` flag - Added `EnsureValidListView()` helper for dynamic ListView validation - ListView now re-discovered on-demand if window becomes invalid - After settings changes, re-discovers shell/ListView handles and refreshes visibility state before re-establishing subclasses (hotkeys keep working) 5. **Code Cleanup (Comments [5](ramensoftware#2267 (comment)), [9](ramensoftware#2267 (comment) - Removed redundant `RestoreIconsToVisible` call from `Wh_ModBeforeUninit` (already in Wh_ModUninit) - Added null checks and proper error handling throughout - Added `ToUpperCase()` helper for case-insensitive key matching - WM_CHAR handling now requires Ctrl when configured and respects Alt, preventing false positives from control codes **Additional Improvements:** - Added `<commctrl.h>` and `<windhawk_utils.h>` includes - Added `--optimize=0 --debug` compiler options - Enhanced documentation in readme with modifier key details - Better logging and error messages throughout
|
@m417z Let me know what ya think |
Removed `--optimize=0 --debug`
**Major rewrite:** - Replaced window subclassing and RegisterHotKey with function hooking using `Wh_SetFunctionHook` - Now hooks `TranslateMessage` for reliable keyboard detection - Fixed InvalidateRect to target specific windows instead of entire screen - Replaced desktop refresh with `RedrawWindow` on SHELLDLL_DefView for targeted updates - Switched to `GetModuleHandleW` for user32.dll - Added proper error handling for hook initialization - Removed unused code and empty stub functions
Implemented registry-based persistence (inspired by @roosmsg's discussion at ramensoftware#2914 (comment)) for desktop icon visibility, ensuring state is retained across restarts. Added a 'Hide icons on startup' setting to automatically hide icons when the mod loads or Explorer restarts. Simplified hotkey logic by removing bShouldHandleHotkey flag, added process ownership checks to prevent multi-process conflicts (hotkey active after clicking taskbar or desktop), cleaned up verbose comments and markers, added phase-based logging prefixes ([INIT], [HOOK], [TOGGLE], [SETTINGS], [WARNING]/[ERROR]/[CRITICAL]) for improved log readability, refactored window discovery, and updated documentation and settings for clarity.
Out of the three approaches: Handling the Explorer window proc (the current version of this PR), low level hooks, and
Regarding actions, having a mod just for toggling desktop icons is quite specific. I took the great Click on empty taskbar space mod by @m1lhaus and adapted it to keyboard shortcuts: Code. Try it and let me know how it works for you. @m1lhaus What do you think about having such a mod published? And do you have a preference for the ownership? Most of the code is yours, but I don't mind maintaining it, whatever works best for you. There's some code duplication with the "Click on empty taskbar space" mod, and I thought about just adding hotkey functionality to the original mod, but I'm afraid users that are looking for hotkeys won't find it. |
|
@m417z honestly, I don't see the point in having this mod in the first place. Most of the actions are keyboard based already anyway, and those that aren't - well, I think Autohotkey is a proper tool to use. It does truly global keyboard shortcuts, and I saw scripts controlling Virtual Desktops, so there must be a way to do e.g., show/hide Desktop icons. I am sure Copilot would be able to generate it. So I am not interested in maintaining it since I am not a fan of recreating existing tools. 😐 Feel free to take whatever you need from my mod. It would be here without you anyway 😀 |
|
@m1lhaus I think it's mostly about convenience. Somebody who's already using Windhawk might want some basic hotkey customization (like the PR author here) without looking for, installing, and learning to use another app. I'll publish it once I hear from @Cinabutts, thanks. |
|
Hey first off thank you to the both of you and I am very sorry for the lengthy reply. I mainly started this whole mod as a learning experience and figure out all the proper methods and learn the Windows/Windhawk api and ironically i've actually already learned enough Autohotkey(did this as a hobby for years) lol but appreciate the idea. @m417z If you're willing to maintain it yeah I think it's a great mod and does exactly what mine was going for anyway. Though I prefer my mods settings in 1.3.6 like how you set the modifier key with toggles and just type the Character key. Idk, either way works though I guess lol Oh and before I forget what exactly were you saying you preferred so i know for future reference? Like if you could show me the line or point me to the function/method/object or whatever it is, I'd appreciate that.
Also, Off topic but I am also still working on another mod/fork of the "Taskbar-Music-Lounge" mod you can see in my Testing branch Here and was just wanting your advice. I finally got the new feature implemented where when you click the widget Background or Text it brings you to the audio source program ie Firefox, But I would like for it to bring me to the Audible Tab.
I'm still not sure the best route to go here but I found an extension that allows me to click Any thought's or ideas would be incredibly helpful. |
Added Shift Modifier Key.
|
Released: https://windhawk.net/mods/keyboard-shortcut-actions
The function that registers the hotkeys is here: windhawk-mods/mods/keyboard-shortcut-actions.wh.cpp Lines 683 to 712 in c0d6291 Regarding Taskbar Music Lounge, the next version is pending review here: #2856 You might want to contact the author about possible improvements. |
|
Hey @m417z I've reached out to him a fair bit, Last I heard he was "busy with academics" and that was a month back, so still unsure of the official state of my fork but I've worked on it for quite a while and just wanted your 2 cents whenever you've got time. https://github.com/Cinabutts/windhawk-mods/blob/Testing/mods/taskbar-music-lounge-fork.wh.cpp Also sorry for replying on here rather than closing it but as you know this is a fork I'm working on so I don't think I could/should do a PR. Still awaiting @Hashah2311's reply.. |
|
Looks fine from a quick glance. I didn't review the code. I'm also not sure what's the status of @Hashah2311. Have you tried the email address on the profile page? If Hashah2311 disappears, we can submit a forked version under your ownership, but I'd rather wait a bit more for a reply. |
|
Hello, sorry for my absence. I checked out @Cinabutts version and it is fabulous! I don't think I would be able to maintain the project much anymore so it would be best if we merged the @Cinabutts version and maybe transfer the ownership of the mod. I am open to any arrangements so @m417z please let me know. Sorry again for my absence. |
|
There's no ownership transfer for mods in Windhawk. @Cinabutts can publish a successor mod. Optionally, you can publish an update to the mod's readme that links to the successor mod to inform users. |
Hey look who arrived @Hashah2311 lol, Thanks again for creating the mod in the first place I can't tell you how grateful I am for this, As for my forks future though I'm okay with submitting it as an official mod but it's up to @m417z as I'd like to reiterate my process; I use VScode's AI(just upgraded, but it's slow af half the time. Got Opus 4.5 now though.) and practically have had it build the whole thing, I do a bunch of testing before making a final commit, I have google gemini look over it addressing certain stuff like what's missing from the mod based on official sources like the Windhawk Wiki and other official mods and in vscode i also cross-reference other relative mods. So the way I see it is 2 options,
It's up to you @m417z, I'd just be happy to have participated in it's creation, but again would love to submit my "first mod" so I'm a bit torn, I also don't want to be a nauseous to y'all, I'm just here to learn. |
Well, it's mostly up to you, @Cinabutts. Each mod has an owner who's responsible and accountable for it. It's OK for the mod to not be perfect, and it's OK to use AI for help, but if you submit it as the author, it becomes under your ownership. If you're willing to do that, go for it. The other options are to find another owner (and since Hashah2311 isn't available, I don't think there's a better person than you at this point) or give up on publishing it. |
|
Hey @m417z Thanks for the reassurance and kind words, I'll submit the mod here shortly then. |






Major Changes:
Window Subclassing System Overhaul (Comments 1, 10)
SetWindowLongPtrWwithWindhawkUtils::SetWindowSubclassFromAnyThreadfor all window subclassingDWORD_PTRrefData parameter (matchesSetWindowSubclass/WindhawkUtils expectations)RemoveWindowSubclassFromAnyThreadin WM_NCDESTROY handlersDefSubclassProcinstead ofCallWindowProcWProcess Isolation (Comments 4, 6)
IsWindowInCurrentProcess()helper functionSHELLDLL_DefViewunder Progman; if not current-process, falls back to WorkerW searchSettings API Fixes (Comments 2, 3)
Wh_GetIntSettingcalls to use single argument (removed incorrect TRUE parameter)Wh_FreeStringSettingto properly free string memorymodifierKeysobject (matches Windhawk patterns)Initialization Improvements (Comments 7, 8)
Sleep(2000)hack fromWh_ModAfterInitbInitializedflagEnsureValidListView()helper for dynamic ListView validationCode Cleanup (Comments 5, 9)
RestoreIconsToVisiblecall fromWh_ModBeforeUninit(already in Wh_ModUninit)ToUpperCase()helper for case-insensitive key matchingAdditional Improvements:
<commctrl.h>and<windhawk_utils.h>includes--optimize=0 --debugcompiler options