Search code examples
objective-cmacoscocoansstatusitemnsstatusbar

Mac System Status Bar Focus


I've added a menu to my systemStatusBar by this code:

statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];

And then set its properties. The only different it has with other status items (Volume, DateTime, Wi-Fi, BatteryIndicator, ...) is that if I select it and press left or right direction buttons on keyboard I can't navigate to other Items and like wise if I select another status item and press direction keys it will not select my status item and instead it jumps to another statusItem. I was wondering is there a way to fix this issue or is it standard for non OS statusItems?


Solution

  • The menu bar you see is not a uniform object. The application menu items on the left part belong to the current application. All these MenuItems are children to a common NSMenu object.

    The status bar items on the outmost right belong to the system (Spotlight, Clock, TimeMachine etc.) and either also share a common parent NSMenu or just have some special privileges.

    Each custom status bar menu item belongs to its corresponding application and has its own stand alone NSMenu parent object. Each status menu is - as you know - inserted into a NSStatusItem which belongs to the NSStatusBar object. Both inherit directly from NSObject and (unlike NSMenu) lack interfaces to determine a status menu's parents or siblings. Each status bar item it absolutely isolated.

    So, you can easily navigate with the arrow keys within a NSMenu, where every item knows its children and parents. Yet, it is not possible to navigate from your status bar menu to any other menu.