mirror of
https://github.com/KDE/latte-dock.git
synced 2025-03-10 04:58:16 +03:00
publish available screen geometries to Plasma
--Plasma 5.18 introduced a new dbus interface in order for external apps to be able to publish to Plasma how much they occupy from screen space. This is a much requested feature from users, Latte is now publishing both its availableScreenRect and availableScreenRegions and this is also Multiple Layouts aware at runtime. BUG:391073
This commit is contained in:
parent
0406a9a411
commit
d071e3be33
@ -34,6 +34,7 @@
|
||||
#include "layouts/launcherssignals.h"
|
||||
#include "shortcuts/globalshortcuts.h"
|
||||
#include "package/lattepackage.h"
|
||||
#include "plasma/extended/screengeometries.h"
|
||||
#include "plasma/extended/screenpool.h"
|
||||
#include "plasma/extended/theme.h"
|
||||
#include "settings/universalsettings.h"
|
||||
@ -97,6 +98,7 @@ Corona::Corona(bool defaultLayoutOnStartup, QString layoutNameOnStartUp, int use
|
||||
m_plasmaScreenPool(new PlasmaExtended::ScreenPool(this)),
|
||||
m_themeExtended(new PlasmaExtended::Theme(KSharedConfig::openConfig(), this)),
|
||||
m_layoutsManager(new Layouts::Manager(this)),
|
||||
m_plasmaGeometries(new PlasmaExtended::ScreenGeometries(this)),
|
||||
m_dialogShadows(new PanelShadows(this, QStringLiteral("dialogs/background")))
|
||||
{
|
||||
//! create the window manager
|
||||
@ -184,6 +186,7 @@ Corona::~Corona()
|
||||
|
||||
m_layoutsManager->unload();
|
||||
|
||||
m_plasmaGeometries->deleteLater();
|
||||
m_wm->deleteLater();
|
||||
m_dialogShadows->deleteLater();
|
||||
m_globalShortcuts->deleteLater();
|
||||
|
@ -79,6 +79,7 @@ class LaunchersSignals;
|
||||
class Manager;
|
||||
}
|
||||
namespace PlasmaExtended{
|
||||
class ScreenGeometries;
|
||||
class ScreenPool;
|
||||
class Theme;
|
||||
}
|
||||
@ -225,6 +226,7 @@ private:
|
||||
Indicator::Factory *m_indicatorFactory{nullptr};
|
||||
Layouts::Manager *m_layoutsManager{nullptr};
|
||||
|
||||
PlasmaExtended::ScreenGeometries *m_plasmaGeometries{nullptr};
|
||||
PlasmaExtended::ScreenPool *m_plasmaScreenPool{nullptr};
|
||||
PlasmaExtended::Theme *m_themeExtended{nullptr};
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
set(lattedock-app_SRCS
|
||||
${lattedock-app_SRCS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/screengeometries.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/screenpool.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/theme.cpp
|
||||
PARENT_SCOPE
|
||||
|
161
app/plasma/extended/screengeometries.cpp
Normal file
161
app/plasma/extended/screengeometries.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
|
||||
*
|
||||
* This file is part of Latte-Dock
|
||||
*
|
||||
* Latte-Dock is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* Latte-Dock 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 General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "screengeometries.h"
|
||||
|
||||
//!local
|
||||
#include "../../lattecorona.h"
|
||||
#include "../../screenpool.h"
|
||||
#include "../../view/view.h"
|
||||
#include "../../layout/genericlayout.h"
|
||||
#include "../../layouts/manager.h"
|
||||
|
||||
// Qt
|
||||
#include <QDebug>
|
||||
#include <QtDBus>
|
||||
|
||||
|
||||
#define LATTESERVICE "org.kde.lattedock"
|
||||
#define PLASMASERVICE "org.kde.plasmashell"
|
||||
#define PLASMASTRUTNAMESPACE "org.kde.PlasmaShell.StrutManager"
|
||||
|
||||
namespace Latte {
|
||||
namespace PlasmaExtended {
|
||||
|
||||
ScreenGeometries::ScreenGeometries(Latte::Corona *parent)
|
||||
: QObject(parent),
|
||||
m_corona(parent)
|
||||
{
|
||||
m_startupInitTimer.setInterval(5000);
|
||||
m_startupInitTimer.setSingleShot(true);
|
||||
connect(&m_startupInitTimer, &QTimer::timeout, this, &ScreenGeometries::init);
|
||||
|
||||
m_publishTimer.setInterval(1000);
|
||||
m_publishTimer.setSingleShot(true);
|
||||
connect(&m_publishTimer, &QTimer::timeout, this, &ScreenGeometries::updateGeometries);
|
||||
|
||||
m_startupInitTimer.start();
|
||||
}
|
||||
|
||||
ScreenGeometries::~ScreenGeometries()
|
||||
{
|
||||
qDebug() << "Plasma Extended Screen Geometries :: Deleted...";
|
||||
}
|
||||
|
||||
void ScreenGeometries::init()
|
||||
{
|
||||
QDBusInterface plasmaStrutsIface(PLASMASERVICE, "/StrutManager", PLASMASTRUTNAMESPACE, QDBusConnection::sessionBus());
|
||||
|
||||
|
||||
|
||||
if (plasmaStrutsIface.isValid()) {
|
||||
m_plasmaInterfaceAvailable = true;
|
||||
|
||||
qDebug() << " PLASMA STRUTS MANAGER :: is available...";
|
||||
|
||||
connect(m_corona, &Latte::Corona::availableScreenRectChangedFrom, this, &ScreenGeometries::availableScreenGeometryChangedFrom);
|
||||
connect(m_corona, &Latte::Corona::availableScreenRegionChangedFrom, this, &ScreenGeometries::availableScreenGeometryChangedFrom);
|
||||
|
||||
connect(m_corona->layoutsManager(), &Latte::Layouts::Manager::currentLayoutNameChanged, this, [&]() {
|
||||
m_publishTimer.start();
|
||||
});
|
||||
|
||||
m_publishTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
bool ScreenGeometries::screenIsActive(const QString &screenName) const
|
||||
{
|
||||
for (QScreen *screen : qGuiApp->screens()) {
|
||||
if (screen->name() == screenName) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScreenGeometries::updateGeometries()
|
||||
{
|
||||
if (!m_plasmaInterfaceAvailable) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusInterface plasmaStrutsIface(PLASMASERVICE, "/StrutManager", PLASMASTRUTNAMESPACE, QDBusConnection::sessionBus());
|
||||
|
||||
if (!plasmaStrutsIface.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QStringList availableScreenNames;
|
||||
|
||||
//! check for available geometries changes
|
||||
for (QScreen *screen : qGuiApp->screens()) {
|
||||
QString scrName = screen->name();
|
||||
int scrId = m_corona->screenPool()->id(screen->name());
|
||||
|
||||
if (m_corona->screenPool()->hasId(scrId)) {
|
||||
QRect availableRect = m_corona->availableScreenRectWithCriteria(scrId,
|
||||
QString(),
|
||||
m_acceptedModes,
|
||||
QList<Plasma::Types::Location>());
|
||||
|
||||
QRegion availableRegion = m_corona->availableScreenRegionWithCriteria(scrId,
|
||||
QString(),
|
||||
m_acceptedModes,
|
||||
QList<Plasma::Types::Location>());
|
||||
|
||||
if (!m_lastAvailableRect.contains(scrName) || m_lastAvailableRect[scrName] != availableRect) {
|
||||
m_lastAvailableRect[scrName] = availableRect;
|
||||
plasmaStrutsIface.call("setAvailableScreenRect", LATTESERVICE, scrName, availableRect);
|
||||
qDebug() << " PLASMA SCREEN GEOMETRIES AVAILABLE RECT :: " << screen->name() << " : " << availableRect;
|
||||
}
|
||||
|
||||
if (!m_lastAvailableRegion.contains(scrName) || m_lastAvailableRegion[scrName] != availableRegion) {
|
||||
m_lastAvailableRegion[scrName] = availableRegion;
|
||||
plasmaStrutsIface.call("setAvailableScreenRegion", LATTESERVICE, scrName, availableRegion);
|
||||
qDebug() << " PLASMA SCREEN GEOMETRIES AVAILABLE REGION :: " << screen->name() << " : " << availableRegion;
|
||||
}
|
||||
}
|
||||
|
||||
availableScreenNames << scrName;
|
||||
}
|
||||
|
||||
//! check for inactive screens that were published previously
|
||||
for (QString &lastScrName : m_lastScreenNames) {
|
||||
if (!screenIsActive(lastScrName)) {
|
||||
//! screen became inactive and its geometries could be unpublished
|
||||
plasmaStrutsIface.call("setAvailableScreenRect", LATTESERVICE, lastScrName, QRect());
|
||||
plasmaStrutsIface.call("setAvailableScreenRegion", LATTESERVICE, lastScrName, QRegion());
|
||||
}
|
||||
}
|
||||
|
||||
m_lastScreenNames = availableScreenNames;
|
||||
}
|
||||
|
||||
void ScreenGeometries::availableScreenGeometryChangedFrom(Latte::View *origin)
|
||||
{
|
||||
if (origin && origin->layout() && origin->layout()->isCurrent()) {
|
||||
m_publishTimer.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
83
app/plasma/extended/screengeometries.h
Normal file
83
app/plasma/extended/screengeometries.h
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2020 Michail Vourlakos <mvourlakos@gmail.com>
|
||||
*
|
||||
* This file is part of Latte-Dock
|
||||
*
|
||||
* Latte-Dock is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* Latte-Dock 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 General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PLASMASCREENGEOMETRIES_H
|
||||
#define PLASMASCREENGEOMETRIES_H
|
||||
|
||||
// Qt
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../../../liblatte2/types.h"
|
||||
|
||||
namespace Latte {
|
||||
class Corona;
|
||||
class View;
|
||||
}
|
||||
|
||||
namespace Latte {
|
||||
namespace PlasmaExtended {
|
||||
|
||||
class ScreenGeometries: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ScreenGeometries(Latte::Corona *parent);
|
||||
~ScreenGeometries() override;
|
||||
|
||||
private slots:
|
||||
void availableScreenGeometryChangedFrom(Latte::View *origin);
|
||||
|
||||
void init();
|
||||
void updateGeometries();
|
||||
|
||||
private slots:
|
||||
bool screenIsActive(const QString &screenName) const;
|
||||
|
||||
private:
|
||||
bool m_plasmaInterfaceAvailable{false};
|
||||
|
||||
//! this is needed in order to avoid too many costly calculations for available screen geometries
|
||||
QTimer m_publishTimer;
|
||||
|
||||
//! this is needed in order to check if Plasma>=5.18 is running
|
||||
QTimer m_startupInitTimer;
|
||||
|
||||
Latte::Corona *m_corona{nullptr};
|
||||
|
||||
QList<Latte::Types::Visibility> m_acceptedModes{Latte::Types::AlwaysVisible,
|
||||
Latte::Types::DodgeActive,
|
||||
Latte::Types::DodgeMaximized,
|
||||
Latte::Types::DodgeAllWindows,
|
||||
Latte::Types::WindowsGoBelow,
|
||||
Latte::Types::WindowsCanCover,
|
||||
Latte::Types::WindowsAlwaysCover};
|
||||
|
||||
QStringList m_lastScreenNames;
|
||||
|
||||
QHash<QString, QRect> m_lastAvailableRect;
|
||||
QHash<QString, QRegion> m_lastAvailableRegion;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user