1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-20 10:04:01 +03:00
latte-dock/app/layouts/synchronizer.h

177 lines
5.1 KiB
C
Raw Permalink Normal View History

/*
2021-05-27 15:01:00 +00:00
SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef LAYOUTSSYNCHRONIZER_H
#define LAYOUTSSYNCHRONIZER_H
2020-08-29 20:42:15 +03:00
// local
#include "../apptypes.h"
2020-08-29 20:42:15 +03:00
#include "../data/layoutdata.h"
#include "../data/layoutstable.h"
// Qt
#include <QObject>
#include <QHash>
#include <QTimer>
#include <QStringList>
namespace Latte {
class CentralLayout;
class View;
namespace Layout{
class GenericLayout;
}
namespace Layouts {
class Manager;
}
}
namespace Plasma {
class Containment;
}
namespace KActivities {
class Controller;
}
namespace Latte {
namespace Layouts {
//! This is a Layouts map in the following structure:
//! ACTIVITY ID -> Layout Names for that activity
2020-08-25 18:07:24 +03:00
typedef QHash<QString, QStringList> AssignedLayoutsHash;
//! Layouts::Synchronizer is a very IMPORTANT class which is responsible
//! for all ACTIVE layouts, meaning layouts that have been loaded
//! in memory.
//!
//! The main task of Synchronizer is to load/unload layouts based
//! on "user preferences"/"activities settings"/"application current
//! phase" (e.g. startup/closing)
//!
class Synchronizer : public QObject {
Q_OBJECT
public:
Synchronizer(QObject *parent);
~Synchronizer() override;
void unloadLayouts();
void hideAllViews();
void pauseLayout(QString layoutName);
void syncActiveLayoutsToOriginalFiles();
void syncLatteViewsToScreens();
void syncMultipleLayoutsToActivities(QStringList preloadedLayouts = QStringList());
//! In that case single layout file must be removed after loading the new layout
void setIsSingleLayoutInDeprecatedRenaming(const bool &enabled);
bool latteViewExists(Latte::View *view) const;
bool layoutExists(QString layoutName) const;
//! switch to specified layout, default previousMemoryUsage means that it didn't change
bool switchToLayout(QString layoutName, MemoryUsage::LayoutsMemory newMemoryUsage = MemoryUsage::Current);
int centralLayoutPos(QString id) const;
QStringList centralLayoutsNames();
QStringList currentLayoutsNames() const;
QStringList layouts() const;
QStringList menuLayouts() const;
QStringList activities();
2020-08-27 16:11:19 +03:00
QStringList freeActivities();
QStringList runningActivities();
2020-08-27 16:11:19 +03:00
QStringList freeRunningActivities(); //! These are activities that haven't been assigned to specific layout
2020-08-30 21:28:22 +03:00
QStringList validActivities(const QStringList &layoutActivities);
int screenForContainment(Plasma::Containment *containment);
Latte::View *viewForContainment(Plasma::Containment *containment);
2020-08-25 19:30:33 +03:00
Latte::View *viewForContainment(uint id);
QList<CentralLayout *> currentLayouts() const;
QList<Latte::View *> currentViews() const;
QList<Latte::View *> currentViewsWithPlasmaShortcuts() const;
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 17:39:44 +02:00
QList<Latte::View *> currentOriginalViews() const;
2020-08-25 19:30:33 +03:00
QList<Latte::View *> sortedCurrentViews() const;
fix #96,FEATURE:AllScreens and AllSecondaryScreens --This is a HUGE FEATURE and so important for multi-screens users. It is introduced as one single commit because it reimplements plenty of infrastructure changes and it will be easier to identify newly introduced bugs. --Users can now choose for their docks and panels to belong at various screen groups. The first two screen groups introduced are AllScreens and AllSecondayScreens. In the future it might be possible to provide CustomScreensGroup that the user will be able to define specific screens in which a dock or panel should be always present. --Current solution specifies an Original dock or panel and clones/copies itself automatically to other screens. So docks and panels in other screens are just real docks and panels that reference themselves to original docks and panels. --Clones are destroyed during layout startup and are automaticaly recreated. It is suggested to export your layouts through the official Layouts Editor in order to share them because in that case clones are not included in the new generated layout file. If in any case you do not this and you share your layout with any previous versions then your clones will just appear as separate docks and panels that belong to specific screens. --Automatic syncing was introduced in order to keep up-to-date the configuration of Original docks and panels with their referenced Clones. --Automatic syncing currently works for all docks and panels settings, for all normal applets configurations and for all subcontaiments configuration such as systrays. --Automatic syncing does not work for applets inside subcontainments such as Group Plasmoid. In such case it is suggested to configure your applets inside your Group Plasmoid in the original dock or panel and afterwards to trigger a recreation for the relevant clones --Manual recreation of clones is easily possible by just choosing the dock or panel to be OnPrimary or OnSpecificScreen and rechoosing afterwards the AllScreensGroup or AllSecondaryScreensGroup
2021-12-11 17:39:44 +02:00
QList<Latte::View *> sortedCurrentOriginalViews() const;
QList<Latte::View *> viewsBasedOnActivityId(const QString &id) const;
CentralLayout *centralLayout(QString layoutname) const;
Layout::GenericLayout *layout(QString layoutname) const;
QList<CentralLayout *> centralLayoutsForActivity(const QString activityid) const;
KActivities::Controller *activitiesController() const;
2021-05-15 13:31:56 +03:00
Data::Layout data(const QString &storedLayoutName) const;
2020-08-29 20:42:15 +03:00
Data::LayoutsTable layoutsTable() const;
void setLayoutsTable(const Data::LayoutsTable &table);
public slots:
2020-08-29 20:42:15 +03:00
void initLayouts();
void updateKWinDisabledBorders();
void updateLayoutsTable();
signals:
void centralLayoutsChanged();
void layoutsChanged();
void runningActicitiesChanged();
void initializationFinished();
void currentLayoutIsSwitching(QString layoutName);
void newLayoutAdded(const Data::Layout &layout);
void layoutActivitiesChanged(const Data::Layout &layout);
private slots:
void onActivityRemoved(const QString &activityid);
void onLayoutAdded(const QString &layoutpath);
void unloadPreloadedLayouts();
void reloadAssignedLayouts();
void updateBorderlessMaximizedAfterTimer();
private:
void addLayout(CentralLayout *layout);
void unloadCentralLayout(CentralLayout *layout);
void unloadLayouts(const QStringList &layoutNames, const QStringList &preloadedLayouts);
bool initSingleMode(QString layoutName);
bool initMultipleMode(QString layoutName);
bool switchToLayoutInMultipleMode(QString layoutName);
bool switchToLayoutInSingleMode(QString layoutName);
bool switchToLayoutInMultipleModeBasedOnActivities(const QString &layoutName);
2020-08-25 18:07:24 +03:00
bool isAssigned(QString layoutName) const;
bool memoryInitialized() const;
QString layoutPath(QString layoutName);
private:
bool m_multipleModeInitialized{false};
bool m_isLoaded{false};
bool m_isSingleLayoutInDeprecatedRenaming{false};
QTimer m_updateBorderlessMaximized;
2020-08-29 20:42:15 +03:00
Data::LayoutsTable m_layouts;
QList<CentralLayout *> m_centralLayouts;
2020-08-29 20:42:15 +03:00
AssignedLayoutsHash m_assignedLayouts;
Layouts::Manager *m_manager;
KActivities::Controller *m_activitiesController;
};
}
}
#endif