]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Show/Hide Menubar and Dock Icon
authorElsie Hupp <9206310+elsiehupp@users.noreply.github.com>
Sat, 8 May 2021 15:56:42 +0000 (11:56 -0400)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 17 Oct 2024 08:26:28 +0000 (16:26 +0800)
Signed-off-by: Elsie Hupp <9206310+elsiehupp@users.noreply.github.com>
src/gui/CMakeLists.txt
src/gui/foregroundbackground_cocoa.h [new file with mode: 0644]
src/gui/foregroundbackground_cocoa.mm [new file with mode: 0644]
src/gui/foregroundbackground_interface.h [new file with mode: 0644]
src/gui/foregroundbackground_mac.mm [new file with mode: 0644]
src/gui/owncloudgui.cpp
src/gui/wizard/owncloudwizard.cpp

index ce33b8fc0aa25245aa08815553b67984ec75592c..9660bfb7ee7f287e070f51bd3312a9ef28cf4306 100644 (file)
@@ -316,6 +316,10 @@ IF( APPLE )
             macOS/progressobserver.m)
     endif()
 
+    list(APPEND client_SRCS foregroundbackground_interface.h)
+    list(APPEND client_SRCS foregroundbackground_mac.mm)
+    list(APPEND client_SRCS foregroundbackground_cocoa.mm)
+
     if(SPARKLE_FOUND AND BUILD_UPDATER)
         # Define this, we need to check in updater.cpp
         add_definitions(-DHAVE_SPARKLE)
diff --git a/src/gui/foregroundbackground_cocoa.h b/src/gui/foregroundbackground_cocoa.h
new file mode 100644 (file)
index 0000000..c21dbb7
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) by Elsie Hupp <gpl at elsiehupp dot com>
+ *
+ * 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 <AppKit/NSApplication.h>
+
+/**
+* @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/foregroundbackground_cocoa.mm b/src/gui/foregroundbackground_cocoa.mm
new file mode 100644 (file)
index 0000000..be790d1
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) by Elsie Hupp <gpl at elsiehupp dot com>
+ *
+ * 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 "foregroundbackground_cocoa.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/foregroundbackground_interface.h b/src/gui/foregroundbackground_interface.h
new file mode 100644 (file)
index 0000000..7d2f1a9
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) by Elsie Hupp <gpl at elsiehupp dot com>
+ *
+ * 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 ForegroundBackgroundInterface allows ForegroundBackground to be implemented differently per platform
+* @ingroup gui
+*/
+
+#ifndef FOREGROUNDBACKGROUND_INTERFACE_H
+#define FOREGROUNDBACKGROUND_INTERFACE_H
+
+#include <QObject>
+#include <QEvent>
+
+namespace OCC {
+namespace Ui {
+
+class ForegroundBackground;
+
+}
+}
+
+class ForegroundBackground : public QObject
+{
+    Q_OBJECT
+
+public:
+
+   ForegroundBackground() = default;
+   ~ForegroundBackground() = default;
+
+    /**
+    * @brief EventFilter catches events that should trigger ForegroundBackground
+    * @ingroup gui
+    */
+    bool eventFilter(QObject *obj, QEvent *event) override;
+
+private:
+    /**
+    * @brief ToForeground() 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 ToBackground() disables the macOS menubar and dock icon, so that the application will only be present as a menubar icon.
+    * @ingroup gui
+    */
+    void ToBackground();
+};
+
+#endif
\ No newline at end of file
diff --git a/src/gui/foregroundbackground_mac.mm b/src/gui/foregroundbackground_mac.mm
new file mode 100644 (file)
index 0000000..af44acf
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) by Elsie Hupp <gpl at elsiehupp dot com>
+ *
+ * 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 "foregroundbackground_interface.h"
+#include "foregroundbackground_cocoa.h"
+
+bool ForegroundBackground::eventFilter(QObject * /*obj*/, QEvent *event)
+{
+    if (event->type() == QEvent::Show) {
+        ToForeground();
+        return true;
+    }
+    if (event->type() == QEvent::Close) {
+        ToBackground();
+        return true;
+    }
+    return false;
+}
+
+void ForegroundBackground::ToForeground()
+{
+    [CocoaProcessType ToForeground];
+}
+
+void ForegroundBackground::ToBackground()
+{
+    [CocoaProcessType ToBackground];
+}
index ff7a6fee010dd5b5413d08ce6804b2e93a53c913..60138a494943be967711871409d4b844b736de4e 100644 (file)
 #include <QQuickItem>
 #include <QQmlContext>
 
+#ifdef Q_OS_MAC
+#include "foregroundbackground_interface.h"
+#endif
+
 #ifdef BUILD_FILE_PROVIDER_MODULE
 #include "macOS/fileprovider.h"
 #include "macOS/fileproviderdomainmanager.h"
@@ -598,6 +602,10 @@ void ownCloudGui::slotShowSettings()
     if (_settingsDialog.isNull()) {
         _settingsDialog = new SettingsDialog(this);
         _settingsDialog->setAttribute(Qt::WA_DeleteOnClose, true);
+#ifdef Q_OS_MAC
+        auto *fgbg = new ForegroundBackground();
+        _settingsDialog->installEventFilter(fgbg);
+#endif
         _settingsDialog->show();
     }
     raiseDialog(_settingsDialog.data());
index 238286aa0accdc191a49ea191acc0a092b241be0..f09c52fcaf155cece2cab19d2bbb61279a14e73e 100644 (file)
 #include "theme.h"
 #include "owncloudgui.h"
 
+#ifdef Q_OS_MAC
+#include "foregroundbackground_interface.h"
+#endif
+
 #include "wizard/owncloudwizard.h"
 #include "wizard/welcomepage.h"
 #include "wizard/owncloudsetuppage.h"
@@ -56,6 +60,10 @@ OwncloudWizard::OwncloudWizard(QWidget *parent)
     , _webViewPage(nullptr)
 #endif // WITH_WEBENGINE
 {
+#ifdef Q_OS_MAC
+    auto *fgbg = new ForegroundBackground();
+    this->installEventFilter(fgbg);
+#endif
     setObjectName("owncloudWizard");
 
     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);