Skip to content

Conversation

@aybe
Copy link
Contributor

@aybe aybe commented Nov 7, 2025

For some reason which I couldn't figure out, when clicking some folders such as AMD, an overlay would be shown on the icon.

This looked terrible because folders icons would constantly change according where you browse to.

Before:

image

After:

image

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 7, 2025

Walkthrough

Adds a Windows-specific icon extraction path to ImFileDialog: introduces an internal Image struct and GetFileIconWin32 helper that uses SHGetImageList + ImageList_GetIcon, converts icons to a pixel buffer, and creates a texture. Keeps the existing non-Windows fallback.

Changes

Cohort / File(s) Summary
Windows Icon Extraction Optimization
third_party/ImFileDialog/ImFileDialog.cpp
Adds internal Image struct and GetFileIconWin32 helper using SHGetImageList and ImageList_GetIcon; converts HICON to pixel buffer and returns Image; replaces previous GetIconInfo/GetBitmapBits path in m_getIcon with the new helper when available; adds Windows headers (commctrl.h, commoncontrols.h) and link pragmas; preserves non-Windows fallback.

Sequence Diagram(s)

sequenceDiagram
  participant ImFD as ImFileDialog
  participant WinAPI as Windows API
  participant ImgConv as Icon → Pixels
  participant GPU as Texture Creator

  ImFD->>ImFD: m_getIcon(request)
  alt Windows path available
    ImFD->>WinAPI: GetFileIconWin32(SHGetImageList, ImageList_GetIcon)
    WinAPI-->>ImgConv: HICON
    ImgConv-->>ImFD: Image{Pixels, W,H,Channels}
    ImFD->>GPU: create texture from Image.Pixels
    GPU-->>ImFD: Texture handle
  else fallback
    ImFD->>ImFD: existing GetIconInfo / GetBitmapBits path
    ImFD->>GPU: create texture from fallback pixels
    GPU-->>ImFD: Texture handle
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Verify correctness and error handling of SHGetImageList / ImageList_GetIcon usage.
  • Inspect HICON → pixel buffer conversion for proper pixel format, stride, and channel ordering.
  • Check memory allocation/freeing for Image.Pixels and HICON / HBITMAP resources.
  • Confirm texture creation call uses expected pixel format and cleanup on failure.

Poem

🐰 I nibble code in moonlit light,
Icons shine pixels crisp and bright,
SHGetImageList, a gentle hop—
I fetch, convert, and never stop,
A tiny rabbit ships delight. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix spurious folder icon overlay' directly corresponds to the main change—replacing the icon extraction method to fix unwanted overlay artifacts on folder icons.
Description check ✅ Passed The description explains the issue (unwanted overlay on folder icons) and provides before/after screenshots demonstrating the fix, which relates to the changeset's goal of fixing the overlay problem.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
third_party/ImFileDialog/ImFileDialog.cpp (1)

49-99: Solid implementation with proper resource management.

The function correctly implements the fix by retrieving icons from the system image list, which should eliminate the overlay artifacts. Resource cleanup is properly handled with DeleteObject and DestroyIcon called regardless of the success path.

Optional: Overflow safety on line 79

The size calculation could theoretically overflow with very large dimensions:

if (const auto size = image.Width * image.Height * (ds.dsBm.bmBitsPixel / 8); size != 0)

While unlikely with icon sizes, defensive coding could use checked multiplication or validate dimensions first. This is a low-priority refinement.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47d83a2 and b05d2b1.

📒 Files selected for processing (1)
  • third_party/ImFileDialog/ImFileDialog.cpp (3 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeScene Code Health Review (main)
third_party/ImFileDialog/ImFileDialog.cpp

[warning] 49-99: ❌ New issue: Deep, Nested Complexity
GetFileIconWin32 has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.


[notice] 818-823: ✅ Getting better: Complex Method
FileDialog::m_getIcon decreases in cyclomatic complexity from 17 to 16, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: cross-arm64
  • GitHub Check: build-openbios
  • GitHub Check: build
  • GitHub Check: coverage
  • GitHub Check: asan
  • GitHub Check: toolchain
  • GitHub Check: macos-build-and-test-toolchain
🔇 Additional comments (3)
third_party/ImFileDialog/ImFileDialog.cpp (3)

40-46: LGTM: Clean structure design.

The Image structure appropriately encapsulates icon pixel data with automatic memory management via std::vector.


818-823: LGTM: Clean integration of the icon fix.

The modification correctly uses the new GetFileIconWin32 helper and properly handles the optional return value. This change should resolve the spurious folder icon overlay issue described in the PR.


20-21: The review comment is based on incorrect information.

The header commoncontrols.h is a standard Windows SDK header that exposes image-list COM interfaces (IImageList, IImageList2), ImageList_CoCreateInstance, and related structures. It is not redundant with commctrl.h—the two headers serve complementary purposes: commctrl.h provides the classic Common Controls API (traditional control functions, messages, InitCommonControlsEx, and window-class names), while commoncontrols.h is focused on COM-style common-controls interfaces.

Both headers are typically used together, with commoncontrols.h included when you need the COM interfaces alongside commctrl.h for traditional control APIs. The code is correct as-is and requires both headers.

Likely an incorrect or invalid review comment.

@aybe aybe force-pushed the fix-icon-overlay branch from b05d2b1 to 79de997 Compare November 7, 2025 05:13
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
third_party/ImFileDialog/ImFileDialog.cpp (1)

49-103: Consider validating bitmap format and documenting color channel ordering.

The function extracts bitmap bits directly without checking the format or performing color conversion. Windows bitmaps are typically in BGRA format, which might differ from what CreateTexture expects.

Consider adding:

  1. Validation that bmBitsPixel is 32 (expected for icons)
  2. Documentation or assertion about expected color format (BGRA vs RGBA)
  3. Comment explaining why we use SHGetImageList + ImageList_GetIcon instead of the icon from SHGetFileInfoW directly (to avoid overlay issues)

Example validation:

 				if (GetObject(info.hbmColor, sizeof(ds), &ds))
 				{
 					const auto bm = ds.dsBm;
+					// Ensure we have a 32-bit BGRA bitmap
+					if (bm.bmBitsPixel != 32)
+						return std::nullopt;
+					
 					const auto bw = bm.bmWidth;
 					const auto bh = bm.bmHeight;
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b05d2b1 and 79de997.

📒 Files selected for processing (1)
  • third_party/ImFileDialog/ImFileDialog.cpp (3 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeScene Code Health Review (main)
third_party/ImFileDialog/ImFileDialog.cpp

[warning] 49-103: ❌ New issue: Deep, Nested Complexity
GetFileIconWin32 has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.


[notice] 822-827: ✅ Getting better: Complex Method
FileDialog::m_getIcon decreases in cyclomatic complexity from 17 to 16, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: pcsx-redux (x86_64-linux)
  • GitHub Check: pcsx-redux (aarch64-linux)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: toolchain
  • GitHub Check: coverage
  • GitHub Check: build
  • GitHub Check: asan
  • GitHub Check: macos-build-and-test-toolchain
  • GitHub Check: cross-arm64
🔇 Additional comments (2)
third_party/ImFileDialog/ImFileDialog.cpp (2)

822-827: LGTM! Clean integration of the new icon extraction approach.

The integration properly handles the optional return value from GetFileIconWin32 and creates the texture with the extracted pixel data. This approach using SHGetImageList should resolve the spurious folder icon overlay issue.


20-24: The review comment is factually incorrect.

commoncontrols.h is a valid standard Windows SDK header that exposes COM-based common-controls interfaces, and both commctrl.h and commoncontrols.h ship in the Windows SDK. The assertion that <commoncontrols.h> is "not a standard Windows SDK header" is false.

While the practical question of whether this code actually requires both headers could merit investigation, the review comment's technical premise is incorrect.

Likely an incorrect or invalid review comment.

@nicolasnoble nicolasnoble merged commit 3c15540 into grumpycoders:main Nov 13, 2025
20 of 22 checks passed
@aybe aybe deleted the fix-icon-overlay branch November 13, 2025 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants