Add desktop-icons-toggle mod#2267
Conversation
m417z
left a comment
There was a problem hiding this comment.
Thanks for the submission. I appreciate the effort, but unfortunately AI code like this tends to be lower quality, and is difficult to review and fix since nobody understands why it's implemented that way.
I left some comments form an initial pass over the code. I'd be happy to merge the mod, as I think it can be helpful for other users, but I'm reluctant to merge low-quality code which seems to be working but is wrong and can cause problems in subtle ways.
mods/desktop-icons-toggle.wh.cpp
Outdated
| g_state.hShellViewWindow, | ||
| GWLP_WNDPROC, | ||
| (LONG_PTR)CustomShellViewWndProc | ||
| ); |
There was a problem hiding this comment.
Using SetWindowLongPtrW can cause problems if multiple mods subclass the same window. Please use WindhawkUtils::SetWindowSubclassFromAnyThread. See wiki for details: https://github.com/ramensoftware/windhawk/wiki/Development-tips.
| // Load settings from Windhawk | ||
| g_state.bUseCtrl = (BOOL)Wh_GetIntSetting(L"UseCtrl", TRUE); | ||
| g_state.bUseAlt = (BOOL)Wh_GetIntSetting(L"UseAlt", TRUE); | ||
| PCWSTR hotkeyCharStr = Wh_GetStringSetting(L"HotkeyChar"); |
There was a problem hiding this comment.
Use Wh_FreeStringSetting to free the memory.
mods/desktop-icons-toggle.wh.cpp
Outdated
| // Load settings from Windhawk configuration | ||
| void LoadSettings() { | ||
| // Load settings from Windhawk | ||
| g_state.bUseCtrl = (BOOL)Wh_GetIntSetting(L"UseCtrl", TRUE); |
There was a problem hiding this comment.
The TRUE is incorrect, it should be just a single argument - the name of the setting.
| LoadSettings(); | ||
|
|
||
| // Find desktop ListView | ||
| g_state.hDesktopListView = FindDesktopListView(); |
There was a problem hiding this comment.
This mod is injected into all explorer.exe instances. Add a check that hDesktopListView that you found belongs to the current process by using GetCurrentProcessId and GetWindowThreadProcessId.
mods/desktop-icons-toggle.wh.cpp
Outdated
| void ToggleDesktopIcons() { | ||
| Wh_Log(L"ToggleDesktopIcons called"); | ||
|
|
||
| if (!g_state.hDesktopListView) { |
There was a problem hiding this comment.
How is it possible for hDesktopListView to be null here?
mods/desktop-icons-toggle.wh.cpp
Outdated
| HWND hListView = FindWindowExW(hShellView, nullptr, L"SysListView32", L"FolderView"); | ||
| if (hListView) { | ||
| Wh_Log(L"Found desktop ListView: %p", hListView); | ||
| return hListView; |
There was a problem hiding this comment.
This mod is injected into all explorer.exe instances. Add a check that hDesktopListView that you found belongs to the current process by using GetCurrentProcessId and GetWindowThreadProcessId.
mods/desktop-icons-toggle.wh.cpp
Outdated
|
|
||
| // Try to find ListView again if not found initially | ||
| if (!g_state.hDesktopListView) { | ||
| Sleep(2000); // Give explorer more time to fully load |
There was a problem hiding this comment.
That won't work, it will just delay explorer loading on boot, as it blocks the process launch. You can either use a new thread, or hook a function such as CreateWindowExW to detect when it's created.
mods/desktop-icons-toggle.wh.cpp
Outdated
|
|
||
| if (!g_state.bInitialized) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
bInitialized isn't needed, it's always true here.
mods/desktop-icons-toggle.wh.cpp
Outdated
| // Called before uninitialization | ||
| void Wh_ModBeforeUninit() { | ||
| Wh_Log(L"Desktop Icons Toggle mod before uninit"); | ||
| RestoreIconsToVisible(); |
There was a problem hiding this comment.
It's already called in Wh_ModUninit.
mods/desktop-icons-toggle.wh.cpp
Outdated
| } | ||
| } | ||
|
|
||
| // Also subclass the ListView as a fallback |
Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new Windhawk mod that adds desktop icon visibility toggle functionality with customizable hotkey support (default Ctrl+Alt+D). The mod provides a lightweight solution for hiding/showing desktop icons on Windows 11 with automatic restoration when disabled.
Key Changes:
- Implementation of desktop icons toggle functionality with hotkey support
- Configurable modifier keys and primary key combinations
- Automatic icon restoration when mod is disabled
Reviewed Changes
Copilot reviewed 65 out of 261 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| mods/dark-theme-browser-colors-fix.wh.cpp | Removed existing mod file |
| mods/dark-menus.wh.cpp | Removed existing mod file |
| mods/custom-shutdown-dialog.wh.cpp | Removed existing mod file |
| mods/custom-desktop-watermark.wh.cpp | Removed existing mod file |
| mods/console-error-to-ding.wh.cpp | Removed existing mod file |
| mods/clientedge-in-apps.wh.cpp | Removed existing mod file |
| mods/classic-winver.wh.cpp | Removed existing mod file |
| mods/classic-uwp-fix.wh.cpp | Removed existing mod file |
| mods/classic-theme-transparency-fix.wh.cpp | Removed existing mod file |
| mods/classic-theme-explorer-search-fix.wh.cpp | Removed existing mod file |
| mods/classic-theme-explorer-lite.wh.cpp | Removed existing mod file |
| mods/classic-theme-enable.wh.cpp | Removed existing mod file |
| mods/classic-theme-enable-with-extended-compatibility.wh.cpp | Removed existing mod file |
| mods/classic-taskdlg-fix.wh.cpp | Removed existing mod file |
| mods/classic-taskbar-context-menu.wh.cpp | Removed existing mod file |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…yThread and address developer feedback Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
…re signatures Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
… pattern Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
Casting wParam to char is unsafe for Unicode characters. Use %lc format specifier with (wchar_t)wParam or %u with (unsigned)wParam instead. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Memory leak: Wh_FreeStringSetting is called unconditionally, but hotkeyCharStr could be NULL if Wh_GetStringSetting failed. The function should only be called when hotkeyCharStr is not NULL. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ages Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
removed "this is normal" line.
Fix Desktop Icons Toggle mod compilation errors and improve code quality
**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
**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
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.