Skip to content

fix(windows): pre-multiply alpha when setting menu item icons to fix black background#290

Open
HarshalPatel1972 wants to merge 2 commits into
getlantern:masterfrom
HarshalPatel1972:fix/menu-icon-black-background
Open

fix(windows): pre-multiply alpha when setting menu item icons to fix black background#290
HarshalPatel1972 wants to merge 2 commits into
getlantern:masterfrom
HarshalPatel1972:fix/menu-icon-black-background

Conversation

@HarshalPatel1972

Copy link
Copy Markdown

Fixes #267

Problem

Menu item icons render with a black background on Windows 11 when the
icon has transparent pixels. The tray icon itself renders correctly,
and disabled menu items also render correctly — only enabled menu items
are affected.

The root cause is that Windows GDI expects pre-multiplied alpha for
HBITMAP objects used in menus. The previous code used
CreateCompatibleBitmap which doesn't handle alpha, causing transparent
pixels to render as black.

Fix

Replaced CreateCompatibleBitmap with CreateDIBSection and added
alpha pre-multiplication for each pixel before the bitmap is passed
to SetMenuItemInfo:

  • R = R * A / 255
  • G = G * A / 255
  • B = B * A / 255

This matches the format Windows expects for alpha-blended menu bitmaps.

Tested on

Windows 11 23H2

Copilot AI review requested due to automatic review settings March 22, 2026 16:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes Windows 11 menu item icons rendering with a black background by generating a 32-bit DIB-backed bitmap (alpha-capable) and pre-multiplying pixel RGB values by alpha before assigning the bitmap to menu items.

Changes:

  • Replaced CreateCompatibleBitmap with CreateDIBSection for menu item icon bitmaps (preserves alpha).
  • Added per-pixel alpha pre-multiplication on the DIB’s backing buffer prior to returning the HBITMAP.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread systray_windows.go Outdated
Comment thread systray_windows.go
Comment thread systray_windows.go Outdated
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.

Icons in menu items have a black background

2 participants