diff --git a/shell/strutmanager.cpp b/shell/strutmanager.cpp index a86c39e97..38786fff1 100644 --- a/shell/strutmanager.cpp +++ b/shell/strutmanager.cpp @@ -1,84 +1,104 @@ +/* + * Copyright 2019 David Edmundson + * Copyright 2019 Tranter Madi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #include "strutmanager.h" #include "shellcorona.h" #include "screenpool.h" #include #include #include #include StrutManager::StrutManager(ShellCorona *plasmashellCorona) : QObject(plasmashellCorona), m_plasmashellCorona(plasmashellCorona), m_serviceWatcher(new QDBusServiceWatcher(this)) { qDBusRegisterMetaType>(); QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.registerObject("/StrutManager", this, QDBusConnection::ExportAllSlots); m_serviceWatcher->setConnection(dbus); connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, [=](const QString &service) { m_availableScreenRects.remove(service); m_availableScreenRegions.remove(service); m_serviceWatcher->removeWatchedService(service); emit m_plasmashellCorona->availableScreenRectChanged(); }); } QRect StrutManager::availableScreenRect(int id) const { QRect r = m_plasmashellCorona->_availableScreenRect(id); QHash service; foreach (service, m_availableScreenRects) { if (!service.value(id).isNull()) { r &= service[id]; } } return r; } QRegion StrutManager::availableScreenRegion(int id) const { QRegion r = m_plasmashellCorona->_availableScreenRegion(id); QHash service; foreach (service, m_availableScreenRegions) { if (!service.value(id).isNull()) { r &= service[id]; } } return r; } void StrutManager::setAvailableScreenRect(const QString &service, const QString &screenName, const QRect &rect) { int id = m_plasmashellCorona->screenPool()->id(screenName); if (id == -1 || m_availableScreenRects.value(service).value(id) == rect || !addWatchedService(service)) { return; } m_availableScreenRects[service][id] = rect; emit m_plasmashellCorona->availableScreenRectChanged(); } void StrutManager::setAvailableScreenRegion(const QString &service, const QString &screenName, const QList &rects) { int id = m_plasmashellCorona->screenPool()->id(screenName); QRegion region; foreach(QRect rect, rects) { region += rect; } if (id == -1 || m_availableScreenRegions.value(service).value(id) == region || !addWatchedService(service)) { return; } m_availableScreenRegions[service][id] = region; emit m_plasmashellCorona->availableScreenRegionChanged(); } bool StrutManager::addWatchedService(const QString &service) { if (!m_serviceWatcher->watchedServices().contains(service)) { if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(service)) { return false; } m_serviceWatcher->addWatchedService(service); } return true; } diff --git a/shell/strutmanager.h b/shell/strutmanager.h index 1318ab3ad..b25359ade 100644 --- a/shell/strutmanager.h +++ b/shell/strutmanager.h @@ -1,35 +1,55 @@ +/* + * Copyright 2019 David Edmundson + * Copyright 2019 Tranter Madi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #ifndef STRUTMANAGER_H #define STRUTMANAGER_H #include #include class QDBusServiceWatcher; class ShellCorona; class StrutManager : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface","org.kde.PlasmaShell.StrutManager") public: explicit StrutManager(ShellCorona *plasmashellCorona); QRect availableScreenRect(int id) const; QRegion availableScreenRegion(int id) const; public Q_SLOTS: void setAvailableScreenRect(const QString &service, const QString &screenName, const QRect &rect); void setAvailableScreenRegion(const QString &service, const QString &screenName, const QList &rects); private: ShellCorona *m_plasmashellCorona; QDBusServiceWatcher *m_serviceWatcher; bool addWatchedService(const QString &service); QHash > m_availableScreenRects; QHash > m_availableScreenRegions; }; #endif