Skip to content

Add desktop-icons-toggle mod#2267

Closed
Cinabutts wants to merge 23 commits intoramensoftware:mainfrom
Cinabutts:main
Closed

Add desktop-icons-toggle mod#2267
Cinabutts wants to merge 23 commits intoramensoftware:mainfrom
Cinabutts:main

Conversation

@Cinabutts
Copy link

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.

@Cinabutts Cinabutts marked this pull request as ready for review August 7, 2025 11:30
Copy link
Member

@m417z m417z left a comment

Choose a reason for hiding this comment

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

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.

g_state.hShellViewWindow,
GWLP_WNDPROC,
(LONG_PTR)CustomShellViewWndProc
);
Copy link
Member

Choose a reason for hiding this comment

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

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");
Copy link
Member

Choose a reason for hiding this comment

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

Use Wh_FreeStringSetting to free the memory.

// Load settings from Windhawk configuration
void LoadSettings() {
// Load settings from Windhawk
g_state.bUseCtrl = (BOOL)Wh_GetIntSetting(L"UseCtrl", TRUE);
Copy link
Member

Choose a reason for hiding this comment

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

The TRUE is incorrect, it should be just a single argument - the name of the setting.

LoadSettings();

// Find desktop ListView
g_state.hDesktopListView = FindDesktopListView();
Copy link
Member

Choose a reason for hiding this comment

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

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.

void ToggleDesktopIcons() {
Wh_Log(L"ToggleDesktopIcons called");

if (!g_state.hDesktopListView) {
Copy link
Member

Choose a reason for hiding this comment

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

How is it possible for hDesktopListView to be null here?

HWND hListView = FindWindowExW(hShellView, nullptr, L"SysListView32", L"FolderView");
if (hListView) {
Wh_Log(L"Found desktop ListView: %p", hListView);
return hListView;
Copy link
Member

Choose a reason for hiding this comment

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

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.


// Try to find ListView again if not found initially
if (!g_state.hDesktopListView) {
Sleep(2000); // Give explorer more time to fully load
Copy link
Member

Choose a reason for hiding this comment

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

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.


if (!g_state.bInitialized) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

bInitialized isn't needed, it's always true here.

// Called before uninitialization
void Wh_ModBeforeUninit() {
Wh_Log(L"Desktop Icons Toggle mod before uninit");
RestoreIconsToVisible();
Copy link
Member

Choose a reason for hiding this comment

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

It's already called in Wh_ModUninit.

}
}

// Also subclass the ListView as a fallback
Copy link
Member

Choose a reason for hiding this comment

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

Why is this fallback needed?

Copilot AI review requested due to automatic review settings August 21, 2025 23:27

This comment was marked as outdated.

Copilot AI and others added 3 commits September 3, 2025 09:11
Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
Co-authored-by: Cinabutts <31424969+Cinabutts@users.noreply.github.com>
@Cinabutts Cinabutts requested a review from Copilot September 3, 2025 09:29
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 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.

Copilot AI and others added 14 commits September 3, 2025 09:42
…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>
Fix Desktop Icons Toggle mod compilation errors and improve code quality
@Cinabutts Cinabutts requested a review from m417z September 3, 2025 12:31
@Cinabutts Cinabutts deleted the branch ramensoftware:main December 21, 2025 03:57
@Cinabutts Cinabutts closed this Dec 21, 2025
@Cinabutts Cinabutts deleted the main branch December 21, 2025 03:57
Cinabutts added a commit to Cinabutts/windhawk-mods that referenced this pull request 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 added a commit to Cinabutts/windhawk-mods that referenced this pull request 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
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.

3 participants