I am seeing what I believe to be an interesting bug on macOS 14.5 (23F79).

If you have an NSTableView with a context menu, opening that context menu via right click while the app is in the background and then clicking elsewhere in the table view to dismiss the context menu brings the window to the foreground (as expected). However the table view will not respond to any clicks until the app is moved to the background and brought back into the foreground.

I see this behavior in Apple Mail, the Finder, and in other apps including my own. To reproduce this:

  1. Check out this sample app using git clone https://github.com/jbrayton/ActivateBug.git. Observe that it creates a simple NSTableView with three rows. Run the app.

  2. Click the table view rows. Observe that they can be selected by clicking them as you would expect. Right-click in the table view and observe that you get a context menu.

  3. Open Safari. Keep the two windows next two each other on the same screen. Make Safari the active app.

  4. Right-click in the table view of the sample app.

  5. Dismiss the resulting context menu by clicking elsewhere in the table view.

  6. Try to select other rows by clicking them.

Expected result: I would expect clicking a table row to select it.

Actual result: Clicking in the table view has no effect.

Possibly related: If the NSApplicationDelegate has an applicationDidBecomeActive method, I would expect it to be called when bringing an app to the foreground following these steps. It is not.

This video demonstrates the issue with my sample app:

This video demonstrates the issue using Apple Mail:

I filed this as FB13806870.

I can think of a couple possible workarounds, but neither is great:

  1. Create a local NSEvent monitor for .rightMouseDown events that calls NSApplication.shared.activate(). But this method “doesn’t guarantee app activation”, so this will only work sometimes.

  2. Similarly create a local NSEvent monitor for .rightMouseDown events that simply ignores right clicks by returning nil when the app is in the background. But that would result in context menus simply being unavailable when the app is in the background.