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

macOS: Display Dock icon and use its context menu #2155

Closed
wants to merge 14 commits into from

Conversation

misch7
Copy link
Member

@misch7 misch7 commented Jul 4, 2020

Important:

#2197 needs to be merged first, then I can rebase this one.

macOS: Show the Dock icon when Settings or any other dialog is visible

This also allows the user to reach the window(s) using the Application Switcher (Command + Tab).

More:

  • Monitor the Dock for changes to the Keep in Dock option. This leaves the context menu intact while the icon is pinned to the Dock.
  • Register a native Click Handler to track clicks on the active Dock icon, treat them like clicks on the Tray icon.

Use the Systray context menu as the Dock menu

The native way on macOS for an app context menu is to add it to the Dock icon. A right-click on the Dock icon reveals the standard menu, e.g. featuring "Quit". This commit adds the "Open main dialog" and "Settings" actions to the Dock menu:

Screenshot 2020-07-04 at 02 06 24

The system then automatically shows the app menu bar too (with system's fixed standard menu actions):

Screenshot 2020-07-06 at 11 33 18

Other small improvements:

  • Add CFBundleName to MacOSXBundleInfo.plist to use our real app name (Finder and Menu bar)
    • nextcloud -> Nextcloud
  • Fix an animation issue with the Dock icon background transparency on app launch (caused by setWindowIcon)
  • LegalNotice dialog:
    • Ensure correct parenting in GeneralSettings (SettingsDialog)
    • Remove additional "Legal notice" label in UI widget (duplicate of windowTitle)
  • Fix memory leak in FolderWatcherPrivate::startWatching

Continuation of #2136.

@misch7 misch7 added design enhancement enhancement of a already implemented feature/code os: 🍎 macOS feature: ⚙️ settings Settings panel functionalities. feature: ☁️ system tray System tray icon and menu. labels Jul 4, 2020
@misch7 misch7 added this to the 2.7 🌟 UI improvements milestone Jul 4, 2020
@misch7 misch7 requested a review from jancborchardt July 4, 2020 04:00
@er-vin

This comment has been minimized.

@misch7

This comment has been minimized.

@jospoortvliet

This comment has been minimized.

@er-vin

This comment has been minimized.

@misch7

This comment has been minimized.

@misch7

This comment has been minimized.

@misch7 misch7 changed the title [WIP] macOS: Display Dock icon and use its context menu macOS: Display Dock icon and use its context menu Jul 6, 2020
@misch7 misch7 requested a review from er-vin July 6, 2020 10:51
@er-vin

This comment has been minimized.

@jospoortvliet

This comment has been minimized.

@misch7

This comment has been minimized.

@er-vin

This comment has been minimized.

@misch7

This comment has been minimized.

@er-vin

This comment has been minimized.

@misch7

This comment has been minimized.

@er-vin

This comment has been minimized.

@misch7

This comment has been minimized.

@er-vin

This comment has been minimized.

@jancborchardt

This comment has been minimized.

@misch7
Copy link
Member Author

misch7 commented Jul 8, 2020

Cool, that would be ideal. But then also we shouldn’t have that setting in our dialog, merely take over that preference. :)

That's the plan :)

Now I've found a way to make it work so, detecting the change from the OS.

Time to test it on an older macOS version and to integrate here 😼

… focus

Add a timer to delay between calls to ownCloudGui::raiseDialog, to not annoy
the users while they're switching to the Settings dialog.

Signed-off-by: Michael Schuster <[email protected]>
TheOneRing and others added 9 commits July 14, 2020 07:27
Adopt upstream commit c5678f3 (owncloud/client#7868)

Signed-off-by: Michael Schuster <[email protected]>
Use our fancy real app name. It is shown in different places, like the system's menu bar.

Examples:
- Menu:   nextcloud     -> Nextcloud
- Finder: nextcloud.app -> Nextcloud

Signed-off-by: Michael Schuster <[email protected]>
For macOS the icon is set in the MacOSXBundleInfo.plist file. Setting it later lead to Dock display
errors, shortly drawing an opaque background while the icon is bouncing at app launch.

Signed-off-by: Michael Schuster <[email protected]>
The native way on macOS for an app context menu is to add it to the Dock icon.

A right-click on the Dock icon reveals the standard menu, e.g. featuring "Quit".

This commit adds the "Open main dialog" and "Settings" actions to the Dock menu.

Signed-off-by: Michael Schuster <[email protected]>
The system displays the menu bar on top of the screen while the app's Dock icon
is visible and active.
Every app has a standard menu with its name right beside the Apple-menu. Users expect
the menu to have at least "Quit", "About" and "Preferences" in Mac apps.

LegalNotice is shown for "About", other minor fixes for LegalNotice:
- Ensure correct parenting in GeneralSettings (SettingsDialog)
- Remove additional "Legal notice" label in UI widget (duplicate of windowTitle)

Signed-off-by: Michael Schuster <[email protected]>
- Move the setActivationPolicy logic from SettingsDialog to ownCloudGui
- Modify ownCloudGui::slotDialogVisibilityChanged to show or hide the Dock Icon,
  depending on having any visible dialogs

Signed-off-by: Michael Schuster <[email protected]>
As there seems to be no officially documented way to query for the setting,
let's monitor the user's config file, written by the system when the user
toggles the option for a Dock Icon:

  ~/Library/Preferences/com.apple.dock.plist

Instead of reading and parsing it everytime our dialogs change, use
a FolderWatcher to monitor for changes and notify ownCloudGui by emitting
keepInDockChanged.

Signed-off-by: Michael Schuster <[email protected]>
Modify the DockWatcher singleton to track click events for the Dock Icon,
emit dockIconClicked and connect it to ownCloudGui::slotOpenMainDialog.

Signed-off-by: Michael Schuster <[email protected]>
@misch7
Copy link
Member Author

misch7 commented Jul 14, 2020

The changes are in :)

We now detect changes to the system's Dock config and get the Keep in Dock state this way, also we catch clicks on the active Dock icon and trigger the same action for clicks on the Tray icon.

@er-vin:
Let's get in #2197 first, then I can rebase stuff here ;)

@er-vin
Copy link
Member

er-vin commented Jul 14, 2020

Let's get in #2197 first, then I can rebase stuff here ;)

Is it really such a strong pre-requisite? Or can we live without all the dialogs being auto-raised? (slightly annoying I understand but that papercut has been there before can probably still wait a bit)

@misch7
Copy link
Member Author

misch7 commented Oct 22, 2020

Let's get in #2197 first, then I can rebase stuff here ;)

Is it really such a strong pre-requisite? Or can we live without all the dialogs being auto-raised? (slightly annoying I understand but that papercut has been there before can probably still wait a bit)

@er-vin :
Just tried to rebase it: Yes, we need the ownCloudGui::updateDialogVisibility handler from #2197, to meaningfully detect if there are open dialogs, to be able to add this code from 7b45bdf there:

#ifdef Q_OS_MAC
    // Dock icon visibility
    if (!_visibleDialogs.isEmpty()) {
        Mac::setActivationPolicy(Mac::ActivationPolicy::Regular);
    } else {
        Mac::setActivationPolicy(Mac::ActivationPolicy::Accessory);
    }
#endif

@er-vin er-vin modified the milestones: Desktop 3.1, Desktop 3.2 Dec 11, 2020
@er-vin er-vin removed this from the Desktop 3.2 milestone Jan 7, 2021
@elsiehupp
Copy link
Member

I hadn't noticed this pull request earlier. I actually figured out a way to show the dock icon and the application menu, and I incorporated that method into #2959 and #2974. Once one or the other of these pull requests are approved, all you need to do to call the methods is add #include "cocoaprocesstypeinterface.h" at the top of the file, then add CocoaProcessTypeToForeground(); when a window opens and CocoaProcessTypeToBackground(); when a window closes. The interface that I created could also potentially be generalized to use code involving the QWinTaskbarButton Class so as to create the same behavior on Windows. (I have not been able to figure out what would be involved on Linux, though.)

@elsiehupp
Copy link
Member

Hi @misch7—I don’t know if you’ve been following my progress on #3014, but I figured out a way to automatically show and hide the dock icon and the menubar when certain window-like dialogues are opened or closed.

While there is an argument for Nextcloud Desktop not having a dock icon most of the time, once #3014 is merged, it should be fairly straightforward to add conditionals and/or additional hooks that would be tied to a toggle in the user preferences so that the dock icon could be persistent rather than contextual.

(If you wanted the dock icon to be able to entirely replace the menubar icon, that would probably take quite a bit more doing and would need additional work to create corresponding functionality on Windows and Linux.)

Regardless, I’m definitely in favor of adding redundant functionality to the dock icon and menubar when they are in fact present. In particular the norm on macOS seems to be for basically every available action to be present in the menus, so that (a) the user can search through them in the “Help” menu, and (b) the menu items can display corresponding keyboard shortcuts.

Menubars seem to be distinctly unfashionable on Windows and Linux (at least on GNOME), so it would probably make the most sense for anything put into the menus to be fully redundant with a widget elsewhere in the interface. This way the menus could be strictly Mac-only, or they could be toggled on and off on Windows and/or Linux (where the norm seems to be hiding the menubar unless the user taps Alt).

I’d be happy to try and take a stab at the menubar and/or the persistent dock icon option myself, but if there’s any way I could help with your desired feature set, feel free to let me know!

@mgallien
Copy link
Collaborator

/rebase

@camilasan
Copy link
Member

I am closing since there was no progress with the discussion and the code.

@camilasan camilasan closed this Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage design enhancement enhancement of a already implemented feature/code feature: ☁️ system tray System tray icon and menu. feature: ⚙️ settings Settings panel functionalities. os: 🍎 macOS stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants