From 030dc268d72758b1a5f868438cb042d472296d79 Mon Sep 17 00:00:00 2001 From: Elsie Hupp <9206310+elsiehupp@users.noreply.github.com> Date: Sat, 6 Mar 2021 18:32:30 -0500 Subject: [PATCH] Dynamically show and hide menubar and dock icon Signed-off-by: Elsie Hupp <9206310+elsiehupp@users.noreply.github.com> --- cmake/modules/MacOSXBundleInfo.plist.in | 2 ++ src/gui/CMakeLists.txt | 2 ++ src/gui/cocoaprocesstype.h | 40 +++++++++++++++++++++++++ src/gui/cocoaprocesstype.mm | 32 ++++++++++++++++++++ src/gui/cocoaprocesstypeinterface.h | 40 +++++++++++++++++++++++++ src/gui/cocoaprocesstypeinterface.mm | 29 ++++++++++++++++++ src/gui/settingsdialog.cpp | 14 +++++++++ 7 files changed, 159 insertions(+) create mode 100644 src/gui/cocoaprocesstype.h create mode 100644 src/gui/cocoaprocesstype.mm create mode 100644 src/gui/cocoaprocesstypeinterface.h create mode 100644 src/gui/cocoaprocesstypeinterface.mm diff --git a/cmake/modules/MacOSXBundleInfo.plist.in b/cmake/modules/MacOSXBundleInfo.plist.in index 29731e7ea7818..04855b81398db 100644 --- a/cmake/modules/MacOSXBundleInfo.plist.in +++ b/cmake/modules/MacOSXBundleInfo.plist.in @@ -4,6 +4,8 @@ NSPrincipalClass NSApplication + LSUIElement + CFBundleDevelopmentRegion English CFBundleExecutable diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index c75440fe146ab..d21288fbbca65 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -147,6 +147,8 @@ endif() IF( APPLE ) list(APPEND client_SRCS cocoainitializer_mac.mm) + list(APPEND client_SRCS cocoaprocesstype.mm) + list(APPEND client_SRCS cocoaprocesstypeinterface.mm) list(APPEND client_SRCS socketapisocket_mac.mm) list(APPEND client_SRCS systray.mm) diff --git a/src/gui/cocoaprocesstype.h b/src/gui/cocoaprocesstype.h new file mode 100644 index 0000000000000..f86774ff35285 --- /dev/null +++ b/src/gui/cocoaprocesstype.h @@ -0,0 +1,40 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#import + +/** +* @brief CocoaProcessType provides methods for moving the application between +* the background and foreground. +* @ingroup gui +*/ + +#ifndef COCOAPROCESSTYPE_H +#define COCOAPROCESSTYPE_H + +@interface CocoaProcessType : NSApplication + +/** + * @brief CocoaProcessTypeToForeground() enables the macOS menubar and dock icon, which are necessary for a maximized window to be able to exit full screen. + * @ingroup gui + */ ++ (void)ToForeground; + +/** + * @brief CocoaProcessTypeToBackground() disables the macOS menubar and dock icon, so that the application will only be present as a menubar icon. + * @ingroup gui + */ ++ (void)ToBackground; + +@end + +#endif \ No newline at end of file diff --git a/src/gui/cocoaprocesstype.mm b/src/gui/cocoaprocesstype.mm new file mode 100644 index 0000000000000..c28a25e84fde1 --- /dev/null +++ b/src/gui/cocoaprocesstype.mm @@ -0,0 +1,32 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "cocoaprocesstype.h" +#include "common/utility.h" + +@implementation CocoaProcessType + ++ (void)ToForeground +{ + NSApplicationLoad(); + ProcessSerialNumber processSerialNumber = { 0, kCurrentProcess }; + TransformProcessType(&processSerialNumber, kProcessTransformToForegroundApplication); +} + ++ (void)ToBackground +{ + NSApplicationLoad(); + ProcessSerialNumber processSerialNumber = { 0, kCurrentProcess }; + TransformProcessType(&processSerialNumber, kProcessTransformToUIElementApplication); +} + +@end \ No newline at end of file diff --git a/src/gui/cocoaprocesstypeinterface.h b/src/gui/cocoaprocesstypeinterface.h new file mode 100644 index 0000000000000..1f692c54aab62 --- /dev/null +++ b/src/gui/cocoaprocesstypeinterface.h @@ -0,0 +1,40 @@ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +/** +* @brief CocoaProcessTypeInterface allows CocoaProcessType to be called C++ +* @ingroup gui +*/ + +namespace OCC { +namespace Mac { + +#ifndef COCOAPROCESSTYPEINTERFACE_H +#define COCOAPROCESSTYPEINTERFACE_H + + /** + * @brief CocoaProcessTypeToForeground() enables the macOS menubar and dock icon, which are necessary for a maximized window to be able to exit full screen. + * @ingroup gui + */ + void CocoaProcessTypeToForeground(); + + /** + * @brief CocoaProcessTypeToBackground() disables the macOS menubar and dock icon, so that the application will only be present as a menubar icon. + * @ingroup gui + */ + void CocoaProcessTypeToBackground(); + +#endif + +} // namespace Mac +} // namespace OCC \ No newline at end of file diff --git a/src/gui/cocoaprocesstypeinterface.mm b/src/gui/cocoaprocesstypeinterface.mm new file mode 100644 index 0000000000000..34ba82a06f3de --- /dev/null +++ b/src/gui/cocoaprocesstypeinterface.mm @@ -0,0 +1,29 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "cocoaprocesstypeinterface.h" +#include "cocoaprocesstype.h" + +namespace OCC { +namespace Mac { + + void CocoaProcessTypeToForeground() + { + [CocoaProcessType ToForeground]; + } + void CocoaProcessTypeToBackground() + { + [CocoaProcessType ToBackground]; + } + +} // namespace Mac +} // namespace OCC diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index 46bb9f6d9ae34..0d52864a1c561 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -14,6 +14,7 @@ #include "settingsdialog.h" #include "ui_settingsdialog.h" +#include "cocoaprocesstypeinterface.h" #include "folderman.h" #include "theme.h" @@ -86,6 +87,10 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) , _ui(new Ui::SettingsDialog) , _gui(gui) { + if (OCC::Utility::isMac()) { + Mac::CocoaProcessTypeToForeground(); + } + ConfigFile cfg; _ui->setupUi(this); @@ -170,6 +175,9 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) SettingsDialog::~SettingsDialog() { + if (OCC::Utility::isMac()) { + Mac::CocoaProcessTypeToBackground(); + } delete _ui; } @@ -184,6 +192,9 @@ void SettingsDialog::reject() ConfigFile cfg; cfg.saveGeometry(this); QDialog::reject(); + if (OCC::Utility::isMac()) { + Mac::CocoaProcessTypeToBackground(); + } } void SettingsDialog::accept() @@ -191,6 +202,9 @@ void SettingsDialog::accept() ConfigFile cfg; cfg.saveGeometry(this); QDialog::accept(); + if (OCC::Utility::isMac()) { + Mac::CocoaProcessTypeToBackground(); + } } void SettingsDialog::changeEvent(QEvent *e)