BonzaiThePenguin/Loading

Possible workarounds for bug regarding NSMenus

Opened this issue · 0 comments

I read your impressive readme on bugs regarding NSMenus and I would like to share my knowledge with you, regarding the bug:

  • NSStatusItem's menu will be drawn in the wrong position if you follow the recommended behavior of using [NSMenuDelegate menuNeedsUpdate:] OR menu:updateItem:atIndex:shouldCancel:. The only workaround I was able to find was swizzling [NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] and updating the menu there.

Here are two proposed alternatives, workarounds, to avoid having to swizzle the method:

  • Populate the menu with at least one menu item which will have the longest length (longest title plus image plus indentation if any) among all menu items to be added
  • Call [NSMenuDelegate menuNeedsUpdate:] right after app initialization is complete, once only, important is that the menu is pre-populated before the user actually tries to display the menu

The goal in both cases is to pre-populate the menu, making sure it is not empty, and that it contains the menu item which has the longest possible length, this apparently gives the system a hint as to where to draw the menu and it will draw the menu in the right position if you do this. Leaving the menu empty is not the best option.