Skip to content

Commit

Permalink
Tray Icon: try to select the icon image with the correct size - other…
Browse files Browse the repository at this point in the history
…wise scale the largest one accordingly
  • Loading branch information
bwRavencl committed May 11, 2024
1 parent f66b72e commit cee7d05
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/de/bwravencl/controllerbuddy/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,18 @@ private void onControllersChanged(final List<ControllerInfo> presentControllers,
quitMenuItem.addActionListener(quitAction);
popupMenu.add(quitMenuItem);

trayIcon = new TrayIcon(frame.getIconImage());
final var trayIconSize = systemTray.getTrayIconSize();
final var trayIconImage = frame.getIconImages().stream()
.filter(iconImage -> iconImage.getWidth(null) == trayIconSize.width
&& iconImage.getWidth(null) == trayIconSize.height)
.findFirst()
.orElse(frame.getIconImages().stream()
.max(Comparator
.comparingInt(iconImage -> iconImage.getWidth(null) * iconImage.getHeight(null)))
.orElseThrow()
.getScaledInstance(trayIconSize.width, trayIconSize.height, Image.SCALE_SMOOTH));

trayIcon = new TrayIcon(trayIconImage);
trayIcon.addActionListener(showAction);
trayIcon.setPopupMenu(popupMenu);
try {
Expand Down

0 comments on commit cee7d05

Please sign in to comment.