Skip to content

Fix the selected background in Toolbar on Windows#3202

Merged
vogella merged 1 commit intoeclipse-platform:masterfrom
vogella:fix/toolbar-background-win
Apr 16, 2026
Merged

Fix the selected background in Toolbar on Windows#3202
vogella merged 1 commit intoeclipse-platform:masterfrom
vogella:fix/toolbar-background-win

Conversation

@vogella
Copy link
Copy Markdown
Contributor

@vogella vogella commented Apr 7, 2026

Take the same approach as Button.java, manually fill the background for checked items and tell Windows to skip its own background:

Now in dark mode, for each toolbar item:

  • Checked: fill with getDifferentColor() (20% lighter shade)
  • Hot (hovered): fill with getSlightlyDifferentColor() (10% lighter shade)
  • Normal: fill with the background color

Then TBCDRF_NOBACKGROUND prevents Windows from painting its own white highlight on top.

Fixes: #217

@vogella
Copy link
Copy Markdown
Contributor Author

vogella commented Apr 7, 2026

image

See ticket for more screenshots

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Test Results (win32)

   28 files     28 suites   4m 46s ⏱️
4 653 tests 4 580 ✅ 73 💤 0 ❌
1 187 runs  1 163 ✅ 24 💤 0 ❌

Results for commit 0479587.

♻️ This comment has been updated with latest results.

Take the same approach as Button.java, manually fill the background for
checked items and tell Windows to skip its own background:

Now in dark mode, for each toolbar item:

- Checked: fill with getDifferentColor() (20% lighter shade)
- Hot (hovered): fill with getSlightlyDifferentColor() (10% lighter
shade)
- Normal: fill with the background color

Then TBCDRF_NOBACKGROUND prevents Windows from painting its own white
highlight on top.

Fixes: eclipse-platform#217
@vogella vogella force-pushed the fix/toolbar-background-win branch from 0c4acae to 0479587 Compare April 8, 2026 07:24
@vogella
Copy link
Copy Markdown
Contributor Author

vogella commented Apr 13, 2026

Anyone interested in reviewing? Windows is not my turf so I would appretiate a second pair of eyes.

Copy link
Copy Markdown

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

Updates Win32 ToolBar custom-draw handling to better support Windows dark mode by manually painting checked/hovered item backgrounds and preventing the native toolbar control from drawing its own (light) highlight on top.

Changes:

  • Always opt into toolbar item custom-draw when Display.useDarkModeExplorerTheme is enabled.
  • In dark mode, manually fill the item background for CDIS_CHECKED and CDIS_HOT states using lighter variants of the toolbar background.
  • Return TBCDRF_NOBACKGROUND for those states to stop Windows from painting its default highlight.

Comment on lines 1697 to 1702
long result = OS.TBCDRF_USECDCOLORS;
nmcd.clrBtnFace = getBackgroundPixel (child);
int bgPixel = getBackgroundPixel (child);
nmcd.clrBtnFace = bgPixel;
nmcd.clrBtnHighlight = getDifferentColor (bgPixel);
nmcd.clrText = getForegroundPixel (child);
OS.MoveMemory (lParam, nmcd, NMTBCUSTOMDRAW.sizeof);
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

Because CDDS_PREPAINT now opts into item custom-draw whenever display.useDarkModeExplorerTheme is enabled, CDDS_ITEMPREPAINT will run even when the app hasn't set custom colors. Returning TBCDRF_USECDCOLORS and always setting nmcd.clrText via getForegroundPixel(child) can override the native dark-theme text color (similar to how Button.customForegroundDrawing() only changes text color when an explicit foreground is set). Consider only setting clrText (and/or returning TBCDRF_USECDCOLORS) when ToolBar/ToolItem has an explicit foreground/background override; for the dark-mode-only path you can just paint the hot/checked background and return TBCDRF_NOBACKGROUND to keep native text rendering.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the TBCDRF_USECDCOLORS + clrText pattern is pre-existing and out of scope for this fix

@vogella
Copy link
Copy Markdown
Contributor Author

vogella commented Apr 16, 2026

Screenshot from a SDK build under Windows

image

Light theme not affected

image

@vogella vogella merged commit 906845e into eclipse-platform:master Apr 16, 2026
22 checks passed
@vogella vogella deleted the fix/toolbar-background-win branch April 16, 2026 15:52
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.

Windows 11 - Selected Toolbar Icons look light (bad) in the dark theme

2 participants