diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 13cde2ff9b86f..d0159a9166133 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -69,6 +69,7 @@ set(client_SRCS folderstatusview.cpp folderwatcher.cpp folderwizard.cpp + foregroundbackground_interface.h generalsettings.cpp legalnotice.cpp ignorelisteditor.cpp @@ -150,6 +151,8 @@ endif() IF( APPLE ) list(APPEND client_SRCS cocoainitializer_mac.mm) list(APPEND client_SRCS socketapisocket_mac.mm) + list(APPEND client_SRCS foregroundbackground_mac.mm) + list(APPEND client_SRCS foregroundbackground_cocoa.mm) list(APPEND client_SRCS systray.mm) if(SPARKLE_FOUND AND BUILD_UPDATER) @@ -164,6 +167,10 @@ IF( APPLE ) DESTINATION "${OWNCLOUD_OSX_BUNDLE}/Contents/Frameworks" USE_SOURCE_PERMISSIONS) endif() +ELSEIF( WIN32 ) + list(APPEND client_SRCS foregroundbackground_windows.cpp) +ELSE() + list(APPEND client_SRCS foregroundbackground_fallback.cpp) ENDIF() IF( NOT WIN32 AND NOT APPLE ) diff --git a/src/gui/foregroundbackground_cocoa.h b/src/gui/foregroundbackground_cocoa.h new file mode 100644 index 0000000000000..c21dbb75f6484 --- /dev/null +++ b/src/gui/foregroundbackground_cocoa.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) by Elsie Hupp + * + * 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/foregroundbackground_cocoa.mm b/src/gui/foregroundbackground_cocoa.mm new file mode 100644 index 0000000000000..be790d1b9b8c6 --- /dev/null +++ b/src/gui/foregroundbackground_cocoa.mm @@ -0,0 +1,34 @@ +/* + * Copyright (C) by Elsie Hupp + * + * 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_fallback.cpp b/src/gui/foregroundbackground_fallback.cpp new file mode 100644 index 0000000000000..0f3ae5fdc2abe --- /dev/null +++ b/src/gui/foregroundbackground_fallback.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) by Elsie Hupp + * + * 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" + +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() +{ + // To be implemented + return; +} + +void ForegroundBackground::ToBackground() +{ + // To be implemented + return; +} diff --git a/src/gui/foregroundbackground_interface.h b/src/gui/foregroundbackground_interface.h new file mode 100644 index 0000000000000..7d2f1a96f67a5 --- /dev/null +++ b/src/gui/foregroundbackground_interface.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) by Elsie Hupp + * + * 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 +#include + +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 index 0000000000000..af44acf92bbba --- /dev/null +++ b/src/gui/foregroundbackground_mac.mm @@ -0,0 +1,39 @@ +/* + * Copyright (C) by Elsie Hupp + * + * 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]; +} diff --git a/src/gui/foregroundbackground_windows.cpp b/src/gui/foregroundbackground_windows.cpp new file mode 100644 index 0000000000000..0f3ae5fdc2abe --- /dev/null +++ b/src/gui/foregroundbackground_windows.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) by Elsie Hupp + * + * 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" + +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() +{ + // To be implemented + return; +} + +void ForegroundBackground::ToBackground() +{ + // To be implemented + return; +} diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 2ea6d9052923e..494ceaaf188ab 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -16,6 +16,7 @@ #include "owncloudgui.h" #include "theme.h" #include "folderman.h" +#include "foregroundbackground_interface.h" #include "progressdispatcher.h" #include "owncloudsetupwizard.h" #include "sharedialog.h" @@ -526,6 +527,8 @@ void ownCloudGui::slotShowSettings() if (_settingsDialog.isNull()) { _settingsDialog = new SettingsDialog(this); _settingsDialog->setAttribute(Qt::WA_DeleteOnClose, true); + auto *fgbg = new ForegroundBackground(); + _settingsDialog->installEventFilter(fgbg); _settingsDialog->show(); } raiseDialog(_settingsDialog.data());