Status bar item action breaks keyWindow states and key inputs

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

Summary:

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.

---

Version/Build:
10.14.5 (18F131a)

Configuration:

Sample Code:
https://www.dropbox.com/s/cyheol2o0nutpa1/AppDelegate.m?dl=0

Repro Video:
https://www.dropbox.com/s/yy57kiwy5j8pn9c/status-bar-item-key-window-bug.mov?dl=0

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com 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!