diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -36,6 +36,7 @@ standaloneappcorona osd.cpp coronatesthelper.cpp + othershellhelper.cpp debug.cpp screenpool.cpp softwarerendernotifier.cpp diff --git a/shell/othershellhelper.h b/shell/othershellhelper.h new file mode 100644 --- /dev/null +++ b/shell/othershellhelper.h @@ -0,0 +1,36 @@ +#ifndef OTHERSHELLHELPER_H +#define OTHERSHELLHELPER_H + +#include +#include + +class ShellCorona; + +class OtherShellHelper : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface","org.kde.plasmashell") + + public: + explicit OtherShellHelper(ShellCorona *plasmashellCorona); + QRegion availableScreenRegion(quint32 id) const; + + signals: + void availableScreenRectChanged(); + void availableScreenRegionChanged(); + Q_SCRIPTABLE void plasmashellViewsChanged(); + + public Q_SLOTS: + QRect availableScreenRect(int id, bool plasmashell=false) const; + QByteArray availableScreenRegion(int id, bool plasmashell=false) const; + void setAvailableScreenRect(int screenId, QRect rect); + void setAvailableScreenRegion(int screenId, QByteArray region); + void test(int screenId, int x, int y, int width, int height); + + private: + ShellCorona *m_plasmashellCorona; + QHash m_availableScreenRects; + QHash m_availableScreenRegions; +}; + +#endif diff --git a/shell/othershellhelper.cpp b/shell/othershellhelper.cpp new file mode 100644 --- /dev/null +++ b/shell/othershellhelper.cpp @@ -0,0 +1,60 @@ +#include "othershellhelper.h" +#include "shellcorona.h" + +#include +#include + +OtherShellHelper::OtherShellHelper(ShellCorona *plasmashellCorona) : QObject(qobject_cast(plasmashellCorona)), + m_plasmashellCorona(plasmashellCorona) +{ + QDBusConnection dbus = QDBusConnection::sessionBus(); + dbus.registerObject("/otherShellHelper", this, QDBusConnection::ExportAllSlots|QDBusConnection::ExportScriptableSignals); + + connect(m_plasmashellCorona, &ShellCorona::availableScreenRectChanged, this, &OtherShellHelper::plasmashellViewsChanged); + connect(m_plasmashellCorona, &ShellCorona::availableScreenRegionChanged, this, &OtherShellHelper::plasmashellViewsChanged); + + connect(this, &OtherShellHelper::availableScreenRectChanged, m_plasmashellCorona, &ShellCorona::availableScreenRectChanged); + connect(this, &OtherShellHelper::availableScreenRegionChanged, m_plasmashellCorona, &ShellCorona::availableScreenRegionChanged); +} + +QRect OtherShellHelper::availableScreenRect(int id, bool plasmashell) const +{ + return plasmashell? m_plasmashellCorona->availableScreenRect(static_cast(id)) : m_availableScreenRects[id]; +} + +QByteArray OtherShellHelper::availableScreenRegion(int id, bool plasmashell) const +{ + QByteArray ba; + QDataStream d(&ba, QIODevice::WriteOnly); + d << (plasmashell? m_plasmashellCorona->availableScreenRegion(static_cast(id)) : m_availableScreenRegions[id]); + + return ba; +} + +QRegion OtherShellHelper::availableScreenRegion(quint32 id) const { + return m_availableScreenRegions[id]; +} + +void OtherShellHelper::setAvailableScreenRect(int screenId, QRect rect) { + if (m_availableScreenRects[screenId] == rect) { + return; + } + m_availableScreenRects[screenId] = rect; + emit availableScreenRectChanged(); +} + +void OtherShellHelper::setAvailableScreenRegion(int screenId, QByteArray region) { + QRegion r; + QDataStream d(®ion, QIODevice::ReadOnly); + d >> r; + + if (m_availableScreenRegions[screenId] != r) { + m_availableScreenRegions[screenId] = r; + emit availableScreenRegionChanged(); + } + return; +} + +void OtherShellHelper::test(int screenId, int x, int y, int width, int height) { + setAvailableScreenRect(screenId, QRect(x, y, width, height)); +} diff --git a/shell/shellcorona.h b/shell/shellcorona.h --- a/shell/shellcorona.h +++ b/shell/shellcorona.h @@ -38,6 +38,7 @@ class QMenu; class QScreen; class ScreenPool; +class OtherShellHelper; namespace KActivities { @@ -89,6 +90,10 @@ Q_INVOKABLE QRegion availableScreenRegion(int id) const override; Q_INVOKABLE QRect availableScreenRect(int id) const override; + // expose to otherShellHelper + QRegion availableScreenRegion(quint32 id) const; + QRect availableScreenRect(quint32 id) const; + Q_INVOKABLE QStringList availableActivities() const; PanelView *panelView(Plasma::Containment *containment) const; @@ -256,6 +261,8 @@ KWayland::Client::PlasmaShell *m_waylandPlasmaShell; bool m_closingDown : 1; QString m_testModeLayout; + + OtherShellHelper *m_otherShellHelper; }; #endif // SHELLCORONA_H diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -21,6 +21,7 @@ */ #include "shellcorona.h" +#include "othershellhelper.h" #include @@ -107,7 +108,8 @@ m_addPanelsMenu(nullptr), m_interactiveConsole(nullptr), m_waylandPlasmaShell(nullptr), - m_closingDown(false) + m_closingDown(false), + m_otherShellHelper(new OtherShellHelper(this)) { setupWaylandIntegration(); qmlRegisterUncreatableType("org.kde.plasma.shell", 2, 0, "Desktop", QStringLiteral("It is not possible to create objects of type Desktop")); @@ -1042,6 +1044,13 @@ } QRegion ShellCorona::availableScreenRegion(int id) const +if (!m_otherShellHelper->availableScreenRegion(static_cast(id)).isNull()) { + return m_otherShellHelper->availableScreenRegion(static_cast(id)); +} +return availableScreenRegion(static_cast(id)); +} + +QRegion ShellCorona::availableScreenRegion(quint32 id) const { DesktopView* view = m_desktopViewforId.value(id); if (!view) { @@ -1062,6 +1071,14 @@ } QRect ShellCorona::availableScreenRect(int id) const +{ + if (!m_otherShellHelper->availableScreenRect(id).isNull()) { + return m_otherShellHelper->availableScreenRect(id); + } + return availableScreenRect(static_cast(id)); +} + +QRect ShellCorona::availableScreenRect(quint32 id) const { DesktopView *view = m_desktopViewforId.value(id); if (!view) {