Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When Menubar-only, app windows are not foreground #2401

Open
elsiehupp opened this issue Aug 22, 2023 · 0 comments
Open

When Menubar-only, app windows are not foreground #2401

elsiehupp opened this issue Aug 22, 2023 · 0 comments

Comments

@elsiehupp
Copy link

Note: I have encountered this issue in a number of applications, and I will include a schematic fix for it. I am not enough of a Mac developer to be able to implement a Pull Request at the moment, though.

Device model, version and app version

  • Model Name: A1534 (MacBook Retina, 12-inch, 2017)
  • macOS Version: 13.2 (22D49)
  • App Version: 2023.460
  • Safari Version: Version 16.3 (18614.4.6.1.5)
  • Home Assistant Core Version: 2023.8.3

Describe the bug

When the Home Assistant application is set to Menubar only, windows spawned by the application do not behave like foreground windows.

To Reproduce

  1. In the Home Assistant application, from the Menubar, open the "Home Assistant" menu and select "Preferences".
  2. In the Preferences window, click "Show App In..." and select "Menu Bar".
  3. Press Cmd-Tab twice.
    • Note that the second Cmd-Tab does not return you to the Home Assistant application, because it no longer registers as a foreground application.

    • Also note that when you manually click on a Home Assistant window, it no longer consistently shows the Menubar menus associated with the Home Assistant application.

      The only way I can find to show the Home Assistant Menubar menus in this mode is to click on the Home Assistant window, three-finger swipe to another Space, then three-finger swipe back, but this behavior is probably a macOS bug, since Menubar-only applications are not supposed to have Menubar menus.

Expected Behavior

When the Home Assistant application is set to Menubar only, windows spawned by the application should behave like foreground windows.

Proposed Fix

Note: these code snippets are in Objective-C, but it shouldn't be too difficult to write the equivalent functions in Swift.

When the Home Assistant application is set to Menubar only, each time the application spawns a window it should run the following commands:

NSApplicationLoad();
ProcessSerialNumber processSerialNumber = { 0, kCurrentProcess };
TransformProcessType(&processSerialNumber, kProcessTransformToForegroundApplication);

Then, when all of the windows have been closed, the application should run the following commands:

NSApplicationLoad();
ProcessSerialNumber processSerialNumber = { 0, kCurrentProcess };
TransformProcessType(&processSerialNumber, kProcessTransformToUIElementApplication);

What these commands do is when the otherwise Menubar-only application spawns any windows, it quietly transforms from from a Menubar-only application to a Dock-and-Menubar application, and then when all the windows are closed, it quietly transforms back into a Menubar-only application.

The reason this behavior is important is that windows belonging to Menubar-only applications do not behave like normal application windows, which can cause problems like the windows not being available in Cmd-Tab and the application's Menubar menus not being consistently available (which, in this case, could make it difficult for the user to reopen the Preferences, essentially trapping them in Menubar-only mode).

While it might initially make sense for a Menubar-only application not to behave like a foreground application, once that application's UI goes beyond just a Menubar dropdown menu and starts involving persistent windows, the behavior of said windows can be jarringly inconsistent with user interface norms. For this reason, Menubar-only applications should quietly transform into foreground applications when any persistent windows are open on screen, rather than being strictly Menubar-only at all times.

Note that at my suggestion this behavior has been implemented in the application Tot, and I have an open Pull Request implementing it in Nextcloud Desktop. I have also proposed this behavior for Beeper (to allow it to run in the background), but running the above commands from an Electron application is non-trivial (and implementing it in Qt for Nextcloud Desktop was itself an overly complicated ordeal). Implementing this behavior in Home Assistant should be substantially more straightforward due to Home Assistant being a native application written in Swift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant