Skip to content

Commit

Permalink
Fix drawing wxTaskBarIcon under macOS in high DPI
Browse files Browse the repository at this point in the history
Use a workaround to ensure the image is not distorted due to using a
wrong scale.

See #23042.

(cherry picked from commit 83e47a6)
  • Loading branch information
williamln authored and vadz committed Jan 26, 2023
1 parent f16387b commit af2f7f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes.txt
Expand Up @@ -300,6 +300,7 @@ wxOSX:
- Ensure that "Window" menu is inserted before "Help" (#22871).
- Fix compiling with Xcode 7.3 and macOS 11 SDK (crazbot, #22988).
- Always call wxTaskBarIcon::GetPopupMenu() (William Lindnilsson, #23008).
- Fix scaling wxTaskBarIcon in high DPI (William Lindnilsson, #23042).
- Add margins around wxListCtrl items to improve appearance (#23155).

wxQt:
Expand Down
9 changes: 8 additions & 1 deletion src/osx/cocoa/taskbar.mm
Expand Up @@ -391,7 +391,14 @@ - (wxTaskBarIconCustomStatusItemImpl*) implementation
m_icon = IconFromBundle(icon);
NSImage* nsimage = m_icon.GetNSImage();
[[m_statusItem button] setImageScaling: NSImageScaleProportionallyUpOrDown];
[[m_statusItem button] setImage: nsimage];

CGFloat statusBarThickness = [[NSStatusBar systemStatusBar] thickness];
NSSize statusBarSize = NSMakeSize(statusBarThickness, statusBarThickness);
NSImage* statusBarScaledImage = [NSImage imageWithSize:statusBarSize flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
[nsimage drawInRect:dstRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1];
return YES;
}];
[[m_statusItem button] setImage:statusBarScaledImage];

wxCFStringRef cfTooltip(tooltip);
[[m_statusItem button] setToolTip:cfTooltip.AsNSString()];
Expand Down

0 comments on commit af2f7f2

Please sign in to comment.