1 /* 2 SPDX-FileCopyrightText: 2016 Smith AR <audoban@openmailbox.org> 3 SPDX-FileCopyrightText: 2016 Michail Vourlakos <mvourlakos@gmail.com> 4 5 SPDX-License-Identifier: GPL-2.0-or-later 6 */ 7 8 #ifndef LATTECORONA_H 9 #define LATTECORONA_H 10 11 // local 12 #include <coretypes.h> 13 #include "plasma/quick/configview.h" 14 #include "layouts/storage.h" 15 #include "view/panelshadows_p.h" 16 17 // Qt 18 #include <QObject> 19 #include <QTimer> 20 21 // Plasma 22 #include <Plasma/Corona> 23 24 // KDE 25 #include <KAboutApplicationDialog> 26 27 namespace KDeclarative { 28 class QmlObjectSharedEngine; 29 } 30 31 namespace Plasma { 32 class Corona; 33 class Containment; 34 class Types; 35 } 36 37 namespace PlasmaQuick { 38 class ConfigView; 39 } 40 41 namespace KActivities { 42 class Consumer; 43 } 44 45 namespace KWayland { 46 namespace Client { 47 class PlasmaShell; 48 } 49 } 50 51 namespace Latte { 52 class CentralLayout; 53 class ScreenPool; 54 class GlobalShortcuts; 55 class UniversalSettings; 56 class View; 57 class ViewSettingsFactory; 58 namespace Indicator{ 59 class Factory; 60 } 61 namespace Layout{ 62 class GenericLayout; 63 } 64 namespace Layouts{ 65 class Manager; 66 } 67 namespace PlasmaExtended{ 68 class ScreenGeometries; 69 class ScreenPool; 70 class Theme; 71 } 72 namespace Templates { 73 class Manager; 74 } 75 namespace WindowSystem{ 76 class AbstractWindowInterface; 77 } 78 } 79 80 namespace Latte { 81 82 class Corona : public Plasma::Corona 83 { 84 Q_OBJECT 85 Q_CLASSINFO("D-Bus Interface", "org.kde.LatteDock") 86 87 public: 88 Corona(bool defaultLayoutOnStartup = false, 89 QString layoutNameOnStartUp = QString(), 90 QString addViewTemplateName = QString(), 91 int userSetMemoryUsage = -1, 92 QObject *parent = nullptr); 93 virtual ~Corona(); 94 95 bool inQuit() const; 96 97 int numScreens() const override; 98 QRect screenGeometry(int id) const override; 99 QRegion availableScreenRegion(int id) const override; 100 QRect availableScreenRect(int id) const override; 101 102 //! This is a very generic function in order to return the availableScreenRect of specific screen 103 //! by calculating only the user specified visibility modes and edges. Empty QLists for both 104 //! arguments mean that all choices are accepted in calculations. ignoreExternalPanels means that 105 //! external panels should be not considered in the calculations 106 QRect availableScreenRectWithCriteria(int id, 107 QString activityid = QString(), 108 QList<Types::Visibility> ignoreModes = QList<Types::Visibility>(), 109 QList<Plasma::Types::Location> ignoreEdges = QList<Plasma::Types::Location>(), 110 bool ignoreExternalPanels = true, 111 bool desktopUse = false) const; 112 113 QRegion availableScreenRegionWithCriteria(int id, 114 QString activityid = QString(), 115 QList<Types::Visibility> ignoreModes = QList<Types::Visibility>(), 116 QList<Plasma::Types::Location> ignoreEdges = QList<Plasma::Types::Location>(), 117 bool ignoreExternalPanels = true, 118 bool desktopUse = false) const; 119 120 int screenForContainment(const Plasma::Containment *containment) const override; 121 122 KWayland::Client::PlasmaShell *waylandCoronaInterface() const; 123 124 KActivities::Consumer *activitiesConsumer() const; 125 GlobalShortcuts *globalShortcuts() const; 126 ScreenPool *screenPool() const; 127 UniversalSettings *universalSettings() const; 128 ViewSettingsFactory *viewSettingsFactory() const; 129 Layouts::Manager *layoutsManager() const; 130 Templates::Manager *templatesManager() const; 131 132 Indicator::Factory *indicatorFactory() const; 133 134 PlasmaExtended::ScreenPool *plasmaScreenPool() const; 135 PlasmaExtended::Theme *themeExtended() const; 136 137 WindowSystem::AbstractWindowInterface *wm() const; 138 139 PanelShadows *dialogShadows() const; 140 141 //! Needs to be called in order to import and load application properly after application 142 //! finished all its exit operations 143 void importFullConfiguration(const QString &file); 144 145 //! these functions are used from context menu through containmentactions 146 void quitApplication(); 147 void switchToLayout(QString layout); 148 void importLayoutFile(const QString &filepath, const QString &suggestedLayoutName = QString()); 149 void showSettingsWindow(int page); 150 151 QStringList contextMenuData(const uint &containmentId); 152 QStringList viewTemplatesData(); 153 154 public slots: 155 void aboutApplication(); 156 void activateLauncherMenu(); 157 void loadDefaultLayout() override; 158 159 void setAutostart(const bool &enabled); 160 161 void addView(const uint &containmentId, const QString &templateId); 162 void duplicateView(const uint &containmentId); 163 void exportViewTemplate(const uint &containmentId); 164 void moveViewToLayout(const uint &containmentId, const QString &layoutName); 165 void removeView(const uint &containmentId); 166 167 void setBackgroundFromBroadcast(QString activity, QString screenName, QString filename); 168 void setBroadcastedBackgroundsEnabled(QString activity, QString screenName, bool enabled); 169 void showAlternativesForApplet(Plasma::Applet *applet); 170 void toggleHiddenState(QString layoutName, QString viewName, QString screenName, int screenEdge); 171 172 //! values are separated with a "-" character 173 void windowColorScheme(QString windowIdAndScheme); 174 void updateDockItemBadge(QString identifier, QString value); 175 176 void unload(); 177 178 signals: 179 void configurationShown(PlasmaQuick::ConfigView *configView); 180 void viewLocationChanged(); 181 void raiseViewsTemporaryChanged(); 182 void availableScreenRectChangedFrom(Latte::View *origin); 183 void availableScreenRegionChangedFrom(Latte::View *origin); 184 void verticalUnityViewHasFocus(); 185 186 private slots: 187 void alternativesVisibilityChanged(bool visible); 188 void load(); 189 190 void onAboutToQuit(); 191 192 void addOutput(QScreen *screen); 193 void primaryOutputChanged(); 194 void screenRemoved(QScreen *screen); 195 void screenCountChanged(); 196 void syncLatteViewsToScreens(); 197 198 private: 199 void cleanConfig(); 200 void qmlRegisterTypes() const; 201 void setupWaylandIntegration(); 202 203 bool appletExists(uint containmentId, uint appletId) const; 204 bool containmentExists(uint id) const; 205 206 int primaryScreenId() const; 207 208 QStringList containmentsIds(); 209 QStringList appletsIds(); 210 211 Layout::GenericLayout *layout(QString name) const; 212 CentralLayout *centralLayout(QString name) const; 213 214 private: 215 216 bool m_activitiesStarting{true}; 217 bool m_defaultLayoutOnStartup{false}; //! this is used to enforce loading the default layout on startup 218 bool m_inStartup{true}; //! this is used in order to identify when application is still in startup phase 219 bool m_inQuit{false}; //! this is used in order to identify when application is in quit phase 220 bool m_quitTimedEnded{false}; //! this is used on destructor in order to delay it and slide-out the views 221 222 //!it can be used on startup to change memory usage from command line 223 int m_userSetMemoryUsage{ -1}; 224 225 QString m_layoutNameOnStartUp; 226 QString m_startupAddViewTemplateName; 227 QString m_importFullConfigurationFile; 228 229 QList<KDeclarative::QmlObjectSharedEngine *> m_alternativesObjects; 230 231 QTimer m_viewsScreenSyncTimer; 232 233 KActivities::Consumer *m_activitiesConsumer; 234 QPointer<KAboutApplicationDialog> aboutDialog; 235 236 ScreenPool *m_screenPool{nullptr}; 237 UniversalSettings *m_universalSettings{nullptr}; 238 ViewSettingsFactory *m_viewSettingsFactory{nullptr}; 239 GlobalShortcuts *m_globalShortcuts{nullptr}; 240 241 Indicator::Factory *m_indicatorFactory{nullptr}; 242 Layouts::Manager *m_layoutsManager{nullptr}; 243 Templates::Manager *m_templatesManager{nullptr}; 244 245 PlasmaExtended::ScreenGeometries *m_plasmaGeometries{nullptr}; 246 PlasmaExtended::ScreenPool *m_plasmaScreenPool{nullptr}; 247 PlasmaExtended::Theme *m_themeExtended{nullptr}; 248 249 WindowSystem::AbstractWindowInterface *m_wm{nullptr}; 250 251 PanelShadows *m_dialogShadows{nullptr}; 252 253 KWayland::Client::PlasmaShell *m_waylandCorona{nullptr}; 254 255 friend class GlobalShortcuts; 256 friend class Layouts::Manager; 257 friend class Layouts::Storage; 258 }; 259 260 } 261 262 #endif // LATTECORONA_H 263