File indexing completed on 2024-03-24 17:07:31

0001 /*
0002 *  Copyright 2016  Smith AR <audoban@openmailbox.org>
0003 *                  Michail Vourlakos <mvourlakos@gmail.com>
0004 *
0005 *  This file is part of Latte-Dock
0006 *
0007 *  Latte-Dock is free software; you can redistribute it and/or
0008 *  modify it under the terms of the GNU General Public License as
0009 *  published by the Free Software Foundation; either version 2 of
0010 *  the License, or (at your option) any later version.
0011 *
0012 *  Latte-Dock is distributed in the hope that it will be useful,
0013 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0014 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015 *  GNU General Public License for more details.
0016 *
0017 *  You should have received a copy of the GNU General Public License
0018 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0019 */
0020 
0021 #ifndef LATTECORONA_H
0022 #define LATTECORONA_H
0023 
0024 // local
0025 #include "plasma/quick/configview.h"
0026 #include "layout/storage.h"
0027 #include "view/panelshadows_p.h"
0028 #include "../liblatte2/types.h"
0029 
0030 // Qt
0031 #include <QObject>
0032 #include <QTimer>
0033 
0034 // Plasma
0035 #include <Plasma/Corona>
0036 
0037 // KDE
0038 #include <KAboutApplicationDialog>
0039 
0040 namespace KDeclarative {
0041 class QmlObjectSharedEngine;
0042 }
0043 
0044 namespace Plasma {
0045 class Corona;
0046 class Containment;
0047 class Types;
0048 }
0049 
0050 namespace PlasmaQuick {
0051 class ConfigView;
0052 }
0053 
0054 namespace KActivities {
0055 class Consumer;
0056 }
0057 
0058 namespace KWayland {
0059 namespace Client {
0060 class PlasmaShell;
0061 }
0062 }
0063 
0064 namespace Latte {
0065 class CentralLayout;
0066 class ScreenPool;
0067 class GlobalShortcuts;
0068 class UniversalSettings;
0069 class View;
0070 namespace Indicator{
0071 class Factory;
0072 }
0073 namespace Layout{
0074 class GenericLayout;
0075 class Storage;
0076 }
0077 namespace Layouts{
0078 class LaunchersSignals;
0079 class Manager;
0080 }
0081 namespace PlasmaExtended{
0082 class ScreenPool;
0083 class Theme;
0084 }
0085 namespace WindowSystem{
0086 class AbstractWindowInterface;
0087 }
0088 }
0089 
0090 namespace Latte {
0091 
0092 class Corona : public Plasma::Corona
0093 {
0094     Q_OBJECT
0095     Q_CLASSINFO("D-Bus Interface", "org.kde.LatteDock")
0096 
0097 public:
0098     Corona(bool defaultLayoutOnStartup = false,
0099                QString layoutNameOnStartUp = QString(),
0100                int userSetMemoryUsage = -1,
0101                QObject *parent = nullptr);
0102     virtual ~Corona();
0103 
0104     int numScreens() const override;
0105     QRect screenGeometry(int id) const override;
0106     QRegion availableScreenRegion(int id) const override;
0107     QRect availableScreenRect(int id) const override;
0108 
0109     //! This is a very generic function in order to return the availableScreenRect of specific screen
0110     //! by calculating only the user specified visibility modes and edges. Empty QLists for both
0111     //! arguments mean that all choices are accepted in calculations. includeExternalPanels means that
0112     //! external panels should be considered in the calculations
0113     QRect availableScreenRectWithCriteria(int id,
0114                                           QString forLayout = QString(),
0115                                           QList<Types::Visibility> modes = QList<Types::Visibility>(),
0116                                           QList<Plasma::Types::Location> edges = QList<Plasma::Types::Location>(),
0117                                           bool includeExternalPanels = false) const;
0118 
0119     QRegion availableScreenRegionWithCriteria(int id,
0120                                               QString forLayout = QString(),
0121                                               QList<Types::Visibility> modes = QList<Types::Visibility>(),
0122                                               QList<Plasma::Types::Location> edges = QList<Plasma::Types::Location>(),
0123                                               bool includeExternalPanels = false) const;
0124 
0125     int screenForContainment(const Plasma::Containment *containment) const override;
0126 
0127     void closeApplication();
0128 
0129     KActivities::Consumer *activityConsumer() const;
0130     KWayland::Client::PlasmaShell *waylandCoronaInterface() const;
0131 
0132     KActivities::Consumer *activitiesConsumer() const;
0133     GlobalShortcuts *globalShortcuts() const;
0134     ScreenPool *screenPool() const;
0135     UniversalSettings *universalSettings() const;
0136     Layouts::Manager *layoutsManager() const;   
0137 
0138     Indicator::Factory *indicatorFactory() const;
0139 
0140     PlasmaExtended::ScreenPool *plasmaScreenPool() const;
0141     PlasmaExtended::Theme *themeExtended() const;
0142 
0143     WindowSystem::AbstractWindowInterface *wm() const;
0144 
0145     PanelShadows *dialogShadows() const;
0146 
0147     //! these functions are used from context menu through containmentactions
0148     void switchToLayout(QString layout);
0149     void showSettingsWindow(int page);
0150     void setContextMenuView(int id);
0151     QStringList contextMenuData();
0152 
0153 public slots:
0154     void aboutApplication();
0155     void addViewForLayout(QString layoutName);
0156     void activateLauncherMenu();
0157     void loadDefaultLayout() override;
0158     void setBackgroundFromBroadcast(QString activity, QString screenName, QString filename);
0159     void setBroadcastedBackgroundsEnabled(QString activity, QString screenName, bool enabled);
0160     void showAlternativesForApplet(Plasma::Applet *applet);
0161     //! values are separated with a "-" character
0162     void windowColorScheme(QString windowIdAndScheme);
0163     void updateDockItemBadge(QString identifier, QString value);
0164 
0165     void unload();
0166 
0167 signals:
0168     void configurationShown(PlasmaQuick::ConfigView *configView);
0169     void viewLocationChanged();
0170     void raiseViewsTemporaryChanged();
0171     void availableScreenRectChangedFrom(Latte::View *origin);
0172     void availableScreenRegionChangedFrom(Latte::View *origin);
0173 
0174 private slots:
0175     void alternativesVisibilityChanged(bool visible);
0176     void load();
0177 
0178     void addOutput(QScreen *screen);
0179     void primaryOutputChanged();
0180     void screenRemoved(QScreen *screen);
0181     void screenCountChanged();
0182     void syncLatteViewsToScreens();
0183 
0184 private:
0185     void cleanConfig();
0186     void qmlRegisterTypes() const;
0187     void setupWaylandIntegration();
0188 
0189     bool appletExists(uint containmentId, uint appletId) const;
0190     bool containmentExists(uint id) const;
0191 
0192     int primaryScreenId() const;
0193 
0194     QStringList containmentsIds();
0195     QStringList appletsIds();
0196 
0197     CentralLayout *centralLayout(QString name) const;
0198 
0199 private:
0200 
0201     bool m_activitiesStarting{true};
0202     bool m_defaultLayoutOnStartup{false}; //! this is used to enforce loading the default layout on startup
0203     bool m_quitTimedEnded{false}; //! this is used on destructor in order to delay it and slide-out the views
0204 
0205     //!it can be used on startup to change memory usage from command line
0206     int m_userSetMemoryUsage{ -1};
0207 
0208     int m_contextMenuViewId{-1};
0209 
0210     QString m_layoutNameOnStartUp;
0211 
0212     QList<KDeclarative::QmlObjectSharedEngine *> m_alternativesObjects;
0213 
0214     KDeclarative::QmlObjectSharedEngine *m_backgroundTracer;
0215 
0216     QTimer m_viewsScreenSyncTimer;
0217 
0218     KActivities::Consumer *m_activityConsumer;
0219     QPointer<KAboutApplicationDialog> aboutDialog;
0220 
0221     ScreenPool *m_screenPool{nullptr};
0222     UniversalSettings *m_universalSettings{nullptr};
0223     GlobalShortcuts *m_globalShortcuts{nullptr};
0224 
0225     Indicator::Factory *m_indicatorFactory{nullptr};
0226     Layouts::Manager *m_layoutsManager{nullptr};
0227 
0228     PlasmaExtended::ScreenPool *m_plasmaScreenPool{nullptr};
0229     PlasmaExtended::Theme *m_themeExtended{nullptr};
0230 
0231     WindowSystem::AbstractWindowInterface *m_wm{nullptr};
0232 
0233     PanelShadows *m_dialogShadows{nullptr};
0234 
0235     KWayland::Client::PlasmaShell *m_waylandCorona{nullptr};
0236 
0237     friend class GlobalShortcuts;
0238     friend class Layout::Storage;
0239     friend class Layouts::LaunchersSignals;
0240     friend class Layouts::Manager;
0241 };
0242 
0243 }
0244 
0245 #endif // LATTECORONA_H