File indexing completed on 2024-04-28 16:49:38

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 #include "quickwindowsystem.h"
0022 
0023 // local
0024 #include "../app/config-latte.h"
0025 
0026 // Qt
0027 #include <QDebug>
0028 #include <QProcess>
0029 
0030 // Plasma
0031 #include <plasma/version.h>
0032 
0033 // X11
0034 #include <KWindowSystem>
0035 
0036 namespace Latte {
0037 
0038 QuickWindowSystem::QuickWindowSystem(QObject *parent)
0039     : QObject(parent)
0040 {
0041     if (KWindowSystem::isPlatformWayland()) {
0042         //! TODO: Wayland compositing active
0043         m_compositing = true;
0044     } else {
0045         connect(KWindowSystem::self(), &KWindowSystem::compositingChanged
0046         , this, [&](bool enabled) {
0047             if (m_compositing == enabled)
0048                 return;
0049 
0050             m_compositing = enabled;
0051             emit compositingChanged();
0052         });
0053 
0054         m_compositing = KWindowSystem::compositingActive();
0055     }
0056 }
0057 
0058 QuickWindowSystem::~QuickWindowSystem()
0059 {
0060     qDebug() << staticMetaObject.className() << "destructed";
0061 }
0062 
0063 bool QuickWindowSystem::compositingActive() const
0064 {
0065     return m_compositing;
0066 }
0067 
0068 bool QuickWindowSystem::isPlatformWayland() const
0069 {
0070     return KWindowSystem::isPlatformWayland();
0071 }
0072 
0073 uint QuickWindowSystem::frameworksVersion() const
0074 {
0075     return Plasma::version();
0076 }
0077 
0078 uint QuickWindowSystem::plasmaDesktopVersion()
0079 {
0080     if (m_plasmaDesktopVersion == -1) {
0081         m_plasmaDesktopVersion = identifyPlasmaDesktopVersion();
0082     }
0083 
0084     return m_plasmaDesktopVersion;
0085 }
0086 
0087 uint QuickWindowSystem::makeVersion(uint major, uint minor, uint release) const
0088 {
0089     return (((major) << 16) | ((minor) << 8) | (release));
0090 }
0091 
0092 uint QuickWindowSystem::identifyPlasmaDesktopVersion()
0093 {
0094     //! Identify Plasma Desktop version
0095     QProcess process;
0096     process.start("plasmashell", QStringList() << "-v");
0097     process.waitForFinished();
0098     QString output(process.readAllStandardOutput());
0099 
0100     QStringList stringSplit = output.split(" ");
0101 
0102     if (stringSplit.count() >= 2) {
0103         qDebug() << " /////////////////////////";
0104         QString cleanVersionString = stringSplit[1].remove("\n");
0105         QStringList plasmaDesktopVersionParts = cleanVersionString.split(".");
0106 
0107         if (plasmaDesktopVersionParts.count() == 3) {
0108             uint maj = plasmaDesktopVersionParts[0].toUInt();
0109             uint min = plasmaDesktopVersionParts[1].toUInt();
0110             uint rel = plasmaDesktopVersionParts[2].toUInt();
0111 
0112             if (maj > 0) {
0113 
0114                 uint desktopVersion = makeVersion(maj, min, rel);
0115 
0116                 QString message("Plasma Desktop version:  " + QString::number(maj) + "."
0117                                 + QString::number(min) + "." + QString::number(rel)
0118                                 + " (" + QString::number(desktopVersion) + ")");
0119                 qDebug() << message;
0120                 qDebug() << " /////////////////////////";
0121 
0122                 return desktopVersion;
0123             }
0124         }
0125 
0126         qDebug() << " /////////////////////////";
0127     }
0128 
0129     return 0;
0130 }
0131 
0132 } //end of namespace