File indexing completed on 2024-11-10 10:57:07

0001 /*
0002     SPDX-FileCopyrightText: 2017 Smith AR <audoban@openmailbox.org>
0003     SPDX-FileCopyrightText: 2017 Michail Vourlakos <mvourlakos@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "centrallayout.h"
0009 
0010 // local
0011 #include <coretypes.h>
0012 #include "../apptypes.h"
0013 #include "../lattecorona.h"
0014 #include "../screenpool.h"
0015 #include "../layouts/importer.h"
0016 #include "../layouts/manager.h"
0017 #include "../layouts/synchronizer.h"
0018 #include "../settings/universalsettings.h"
0019 #include "../view/view.h"
0020 #include "../wm/tracker/schemes.h"
0021 
0022 // KDE
0023 #include <KConfigGroup>
0024 #include <KActivities/Consumer>
0025 
0026 
0027 namespace Latte {
0028 
0029 CentralLayout::CentralLayout(QObject *parent, QString layoutFile, QString assignedName)
0030     : Layout::GenericLayout(parent, layoutFile, assignedName)
0031 {
0032     if (m_loadedCorrectly) {
0033         loadConfig();
0034         init();
0035     }
0036 }
0037 
0038 CentralLayout::~CentralLayout()
0039 {
0040 }
0041 
0042 void CentralLayout::init()
0043 {
0044     connect(this, &GenericLayout::activitiesChanged, this, &CentralLayout::saveConfig);
0045     connect(this, &CentralLayout::disableBordersForMaximizedWindowsChanged, this, &CentralLayout::saveConfig);
0046     connect(this, &CentralLayout::showInMenuChanged, this, &CentralLayout::saveConfig);
0047 }
0048 
0049 bool CentralLayout::initCorona()
0050 {
0051     if (GenericLayout::initCorona()) {
0052         onSchemeFileChanged();
0053 
0054         connect(this, &CentralLayout::disableBordersForMaximizedWindowsChanged,
0055                 m_corona->layoutsManager()->synchronizer(), &Layouts::Synchronizer::updateKWinDisabledBorders);
0056 
0057         connect(this, &Layout::AbstractLayout::schemeFileChanged, this, &CentralLayout::onSchemeFileChanged);
0058         connect(m_corona->wm()->schemesTracker(), &WindowSystem::Tracker::Schemes::defaultSchemeChanged, this, &CentralLayout::onSchemeFileChanged);
0059         return true;
0060     }
0061 
0062     return false;
0063 }
0064 
0065 bool CentralLayout::disableBordersForMaximizedWindows() const
0066 {
0067     return m_disableBordersForMaximizedWindows;
0068 }
0069 
0070 void CentralLayout::setDisableBordersForMaximizedWindows(bool disable)
0071 {
0072     if (m_disableBordersForMaximizedWindows == disable) {
0073         return;
0074     }
0075 
0076     m_disableBordersForMaximizedWindows = disable;
0077 
0078     emit disableBordersForMaximizedWindowsChanged();
0079 }
0080 
0081 bool CentralLayout::showInMenu() const
0082 {
0083     return m_showInMenu;
0084 }
0085 
0086 void CentralLayout::setShowInMenu(bool show)
0087 {
0088     if (m_showInMenu == show) {
0089         return;
0090     }
0091 
0092     m_showInMenu = show;
0093     emit showInMenuChanged();
0094 }
0095 
0096 bool CentralLayout::isCurrent()
0097 {
0098    QStringList appliedactivities = appliedActivities();
0099 
0100     return (appliedactivities.contains(Data::Layout::ALLACTIVITIESID)
0101             || appliedactivities.contains(m_corona->activitiesConsumer()->currentActivity()));
0102 }
0103 
0104 bool CentralLayout::isOnAllActivities() const
0105 {
0106     return (m_activities.count() == 1 && m_activities[0] == Data::Layout::ALLACTIVITIESID);
0107 }
0108 
0109 bool CentralLayout::isForFreeActivities() const
0110 {
0111     return (m_activities.count() == 1 && m_activities[0] == Data::Layout::FREEACTIVITIESID);
0112 }
0113 
0114 Layout::Type CentralLayout::type() const
0115 {
0116     return Layout::Type::Central;
0117 }
0118 
0119 QStringList CentralLayout::activities() const
0120 {
0121     return m_activities;
0122 }
0123 
0124 void CentralLayout::setActivities(QStringList activities)
0125 {
0126     if (m_activities == activities) {
0127         return;
0128     }
0129 
0130     m_activities = activities;
0131 
0132     emit activitiesChanged();
0133 }
0134 
0135 Latte::WindowSystem::SchemeColors *CentralLayout::scheme() const
0136 {
0137     return m_scheme;
0138 }
0139 
0140 void CentralLayout::setScheme(Latte::WindowSystem::SchemeColors *_scheme)
0141 {
0142     if (m_scheme == _scheme) {
0143         return;
0144     }
0145 
0146     m_scheme = _scheme;
0147     emit schemeChanged();
0148 }
0149 
0150 Data::Layout CentralLayout::data() const
0151 {
0152     Data::Layout cdata;
0153 
0154     cdata.id = file();
0155     cdata.name = name();
0156     cdata.icon = icon();
0157     cdata.backgroundStyle = backgroundStyle();
0158     cdata.color = color();
0159     cdata.background = customBackground();
0160     cdata.textColor = customTextColor();
0161     cdata.isActive = (m_corona != nullptr);
0162     cdata.isLocked = !isWritable();
0163     cdata.isShownInMenu = showInMenu();
0164     cdata.hasDisabledBorders = disableBordersForMaximizedWindows();
0165     cdata.popUpMargin = popUpMargin();
0166     cdata.schemeFile = schemeFile();
0167     cdata.activities = activities();
0168     cdata.lastUsedActivity = lastUsedActivity();
0169 
0170     cdata.errors = errors().count();
0171     cdata.warnings = warnings().count();
0172 
0173     return cdata;
0174 }
0175 
0176 void CentralLayout::onSchemeFileChanged()
0177 {
0178     setScheme(m_corona->wm()->schemesTracker()->schemeForFile(schemeFile()));
0179 }
0180 
0181 void CentralLayout::loadConfig()
0182 {
0183     m_disableBordersForMaximizedWindows = m_layoutGroup.readEntry("disableBordersForMaximizedWindows", false);
0184     m_showInMenu = m_layoutGroup.readEntry("showInMenu", false);     
0185     m_activities = m_layoutGroup.readEntry("activities", QStringList());
0186 
0187     emit activitiesChanged();
0188 }
0189 
0190 void CentralLayout::saveConfig()
0191 {
0192     qDebug() << "CENTRAL layout is saving... for layout:" << m_layoutName;
0193     m_layoutGroup.writeEntry("showInMenu", m_showInMenu);
0194     m_layoutGroup.writeEntry("disableBordersForMaximizedWindows", m_disableBordersForMaximizedWindows);
0195     m_layoutGroup.writeEntry("activities", m_activities);
0196     m_layoutGroup.sync();
0197 }
0198 
0199 //! OVERRIDES
0200 
0201 const QStringList CentralLayout::appliedActivities()
0202 {
0203     if (!m_corona) {
0204         return {};
0205     }
0206 
0207     if (isOnAllActivities() || m_corona->layoutsManager()->memoryUsage() == MemoryUsage::SingleLayout) {
0208         return QStringList(Data::Layout::ALLACTIVITIESID);
0209     } else if (isForFreeActivities()) {
0210         return m_corona->layoutsManager()->synchronizer()->freeRunningActivities();
0211     } else {
0212         return m_corona->layoutsManager()->synchronizer()->validActivities(m_activities);
0213     }
0214 }
0215 
0216 Types::ViewType CentralLayout::latteViewType(uint containmentId) const
0217 {
0218     for (const auto view : m_latteViews) {
0219         if (view->containment() && view->containment()->id() == (uint)containmentId) {
0220             return view->type();
0221         }
0222     }
0223 
0224     return Types::DockView;
0225 }
0226 
0227 }