Skip to content

Add: Desktop-icons-toggle#2968

Closed
Cinabutts wants to merge 10 commits intoramensoftware:mainfrom
Cinabutts:desktop-icons-toggle
Closed

Add: Desktop-icons-toggle#2968
Cinabutts wants to merge 10 commits intoramensoftware:mainfrom
Cinabutts:desktop-icons-toggle

Conversation

@Cinabutts
Copy link

@Cinabutts Cinabutts commented Jan 7, 2026

Major Changes:

  1. Window Subclassing System Overhaul (Comments 1, 10)

    • 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, 6)

    • 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, 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 7, 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
    • After settings changes, re-discovers shell/ListView handles and refreshes visibility state before re-establishing subclasses (hotkeys keep working)
  5. Code Cleanup (Comments 5, 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
    • 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

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
@Cinabutts Cinabutts marked this pull request as ready for review January 7, 2026 06:25
Copilot AI review requested due to automatic review settings January 7, 2026 06:25
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Cinabutts Cinabutts closed this Jan 7, 2026
@Cinabutts Cinabutts reopened this Jan 7, 2026
**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
@Cinabutts
Copy link
Author

@m417z Let me know what ya think

@Cinabutts Cinabutts requested a review from m417z January 8, 2026 04:05
**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
@Cinabutts Cinabutts requested a review from m417z January 9, 2026 08:02
@roosmsg
Copy link

roosmsg commented Jan 11, 2026

#2914

Cinabutts and others added 2 commits January 12, 2026 02:50
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.
@m417z
Copy link
Member

m417z commented Jan 12, 2026

Yeah, it's a known limitation where you always have to click the taskbar or desktop to "activate" the Hotkey or set it live?(don't know how else to put that lol)
I went through multiple iterations trying to work this out and the end result was typically not up to par basically(got messy, clunky, and didn't even work), It's just a limitation for now but if you know of any working examples of low-level keyboard hooking that some other mods have used i'm all ears.

I've looked through a couple of em though or really skimmed through and had the ai look into em lol but as said idk for now. Would be happy to learn/improve though.

Out of the three approaches: Handling the Explorer window proc (the current version of this PR), low level hooks, and RegisterHotKey, I like the third option the most.

  • Handling the Explorer window proc requires Explorer to be focused.
  • Low level hooks are unnecessarily intrusive and impact system performance, since any key press event needs gets processed by the mod synchronously.
  • RegisterHotKey has the efficiency and no limitations.

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:

Screenshot

image

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.

@m1lhaus
Copy link
Contributor

m1lhaus commented Jan 14, 2026

@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 😀

@m417z
Copy link
Member

m417z commented Jan 14, 2026

@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.

@Cinabutts
Copy link
Author

Cinabutts commented Jan 15, 2026

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
But yeah i'll close this whenever that's released, Lmk if you'd be willing to change the settings to toggles just so I know. Clearly I don't expect you to, I didn't even expect a custom mod to begin with lol, So regardless truly, Thank you. These conversations are incredibly beneficial and I can't thank y'all enough for your hard work/dedication.
Actually when you think about it - using toggles for the modifier keys(or atleast standard ones Ctrl Shift Alt) prevents possible incorrect combinations too, idk if that's been thought out fully or if that's even a true problem to worry about but just my 2 cents.

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.

Out of the three approaches: Handling the Explorer window proc (the current version of this PR), low level hooks, and RegisterHotKey, I like the third option the most.


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.
image

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.

image

I'm still not sure the best route to go here but I found an extension that allows me to click Shift+Alt+A to bring me to the Audible tab And I was trying to work out if I should just incorporate an ahk script that'd simply click Shift+Alt+A and i'd run that after opening the audible window, Or there's a better way altogether?
And if I do go down the route of making it run an ahk script whenever I click the widgets Text/Bg I was already planning on making the widget use those Actions y'all have set up before.
But if I do that id have to ensure the action if it's set to "Open Audible Tab" runs after opening the Audible Window(Which in itself could be an action? or that's probably just over-complicating things?).

Any thought's or ideas would be incredibly helpful.

@Cinabutts
Copy link
Author

Scratch that comment above actually lol
It took all night but I finally got a working version if you wanna check it out and give me your thoughts im all ears!
image

image

Taskbar Music Lounge 4.7.0

@m417z
Copy link
Member

m417z commented Jan 15, 2026

Released: https://windhawk.net/mods/keyboard-shortcut-actions

Like if you could show me the line or point me to the function/method/object or whatever it is, I'd appreciate that.

Out of the three approaches: Handling the Explorer window proc (the current version of this PR), low level hooks, and RegisterHotKey, I like the third option the most.

The function that registers the hotkeys is here:

void RegisterHotkeys(HWND hWnd) {
for (size_t i = 0; i < g_settings.hotkeyActions.size(); i++) {
auto& action = g_settings.hotkeyActions[i];
if (action.hotkeyString.empty() ||
action.actionType == HotkeyActionType::Nothing) {
continue;
}
if (!FromStringHotKey(action.hotkeyString, &action.modifiers,
&action.vk)) {
Wh_Log(L"Failed to parse hotkey: %s", action.hotkeyString.c_str());
continue;
}
action.hotkeyId = kHotkeyIdBase + static_cast<int>(i);
if (RegisterHotKey(hWnd, action.hotkeyId, action.modifiers,
action.vk)) {
action.registered = true;
Wh_Log(L"Registered hotkey %s (id=%d) for action %s",
action.hotkeyString.c_str(), action.hotkeyId,
ActionTypeToString(action.actionType));
} else {
action.registered = false;
Wh_Log(L"Failed to register hotkey: %s (error=%d)",
action.hotkeyString.c_str(), GetLastError());
}
}
}

Regarding Taskbar Music Lounge, the next version is pending review here: #2856

You might want to contact the author about possible improvements.

@Cinabutts
Copy link
Author

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
image

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..

@m417z
Copy link
Member

m417z commented Jan 24, 2026

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.

@Hashah2311
Copy link
Contributor

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.

@m417z
Copy link
Member

m417z commented Jan 24, 2026

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.

@Cinabutts
Copy link
Author

Cinabutts commented Jan 25, 2026

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.
As for my own personal knowledge, I have coded in Unity as a hobby probably back in 2019 so i know a fair amount(from what I can remember) of C/C++ and check over the code after every change ensuring it didn't do something stupid but that's where I'm lacking, I've not really touched Microsofts API, like I have in regards to Autohotkey bats py scripts etc but my point is here, I don't have 100% confidence in running this lol.

So the way I see it is 2 options,

  1. If you're willing to take over after I make some finishing touches on it, That'd be best or if you know someone that wouldn't mind, I'm all ears.
  2. Or just be sure to babysit me when I make the final commits, tell me what i fucked up on, what I should've done instead or just point me in the direction etc when need be which I'll of course try to ensure rarely happens. This way I'd still be able to learn and experiment but it's just when actual problems hit idk how capable I'd be at resolving them tbr. I'd certainly give it my best shot though.

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.

@m417z
Copy link
Member

m417z commented Jan 25, 2026

it's up to @m417z

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.

@Cinabutts
Copy link
Author

Hey @m417z Thanks for the reassurance and kind words, I'll submit the mod here shortly then.

@m417z m417z closed this Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants