Status bar item action breaks keyWindow states and key inputs

Number:rdar://50602064 Date Originated:May 8 2019
Status:Open Resolved:
Product:macOS + SDK Product Version:10.14.5
Classification:Bug Reproducible:Always


Clicking on a status bar item when the app is not currently active can get the keyWindow states into an inconsistent state:
1. window may receive `windowDidBecomeKey` despite not actually being the keyWindow
2. if the status bar item action foregrounds a different window, the previous key window will no longer receive key events (until the other window is closed).

Steps to Reproduce:
1. Open an app with active Window A that has a status bar item
2. Switch to another app
3. Click on the status bar item

Expected Results:
Window A should not receive `windowDidBecomeKey`

Actual Results:
Window A received `windowDidBecomeKey` while `isKeyWindow` is NO

Alternative steps to Reproduce:
Same as above, but if the status bar item handler call `makeKeyAndOrderFront` on a different Window B

Expected Results:
Window B should become the new key window, while Window A should be unaffected.

Actual Results:
Window B became new key window, but Window A will no longer receive key events even after the user activates Window A.


10.14.5 (18F131a)


Sample Code:

Repro Video:


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!