Skip to content

Commit c81319b

Browse files
committed
fix(macos-tray): cap icon size to 18pt instead of full status bar thickness
1 parent 34dc9d1 commit c81319b

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

src/native/macos/tray.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public func tray_update(_ tray: UnsafeMutableRawPointer) {
328328
// Update icon
329329
if let iconPath = iconPathPtr.flatMap({ String(cString: $0) }),
330330
let image = NSImage(contentsOfFile: iconPath) {
331-
let height = NSStatusBar.system.thickness
331+
let height = min(NSStatusBar.system.thickness - 4, 18)
332332
let width = image.size.width * (height / image.size.height)
333333
image.size = NSSize(width: width, height: height)
334334
statusItem.button?.image = image
@@ -338,24 +338,19 @@ public func tray_update(_ tray: UnsafeMutableRawPointer) {
338338
statusItem.button?.toolTip = tooltipPtr.flatMap { String(cString: $0) }
339339

340340
// Menu and actions configuration
341-
// Important: never set statusItem.menu to keep highlight control
342341
statusItem.menu = nil
343342

344343
if let menuPtr = menuPtr {
345-
// Create and store the menu without assigning it to statusItem
346344
ctx.contextMenu = nativeMenu(from: menuPtr, statusItem: statusItem)
347345
} else {
348346
ctx.contextMenu = nil
349347
}
350348

351-
// Configure button actions
352349
if callbackPtr != nil || ctx.contextMenu != nil {
353-
// We have either a callback, a menu, or both
354350
statusItem.button?.target = ctx.clickHandler
355351
statusItem.button?.action = #selector(InstanceButtonClickHandler.handleClick(_:))
356352
statusItem.button?.sendAction(on: NSEvent.EventTypeMask.leftMouseUp.union(.rightMouseUp))
357353
} else {
358-
// Neither callback nor menu
359354
statusItem.button?.target = nil
360355
statusItem.button?.action = nil
361356
}
@@ -546,8 +541,7 @@ public func tray_set_icons_for_appearance(
546541
) {
547542
let doWork = {
548543
guard let tray = tray, let ctx = contexts[tray] else { return }
549-
let height = NSStatusBar.system.thickness
550-
544+
let height = min(NSStatusBar.system.thickness - 4, 18)
551545
if let path = lightIconPath.flatMap({ String(cString: $0) }),
552546
let img = NSImage(contentsOfFile: path) {
553547
let w = img.size.width * (height / img.size.height)
@@ -560,7 +554,6 @@ public func tray_set_icons_for_appearance(
560554
img.size = NSSize(width: w, height: height)
561555
ctx.darkImage = img
562556
}
563-
564557
// Apply the correct variant for the current appearance
565558
if let button = ctx.statusItem.button {
566559
let isDark = button.effectiveAppearance
@@ -570,7 +563,6 @@ public func tray_set_icons_for_appearance(
570563
}
571564
}
572565
}
573-
574566
if Thread.isMainThread { doWork() }
575567
else { DispatchQueue.main.async { doWork() } }
576568
}
@@ -680,4 +672,4 @@ public func tray_get_mouse_button_state(_ button: Int32) -> Int32 {
680672
let cgButton = CGMouseButton(rawValue: UInt32(button))!
681673
let state = CGEventSource.buttonState(.combinedSessionState, button: cgButton)
682674
return state ? 1 : 0
683-
}
675+
}

0 commit comments

Comments
 (0)