Commit 5f2ffad3 authored by Martin Flöser's avatar Martin Flöser

Use PlasmaWindowManagement wayland interface to trigger showing desktop mode

Introduces new dependency on KWayland and uses it to try to resolve the
PlasmaWindowManagement interface. If available that's used to trigger
showing desktop state.
parent fd382d0b
...@@ -27,6 +27,10 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core Gui Widgets Qml Quick Te ...@@ -27,6 +27,10 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core Gui Widgets Qml Quick Te
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Plasma Service Declarative I18n) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Plasma Service Declarative I18n)
find_package(KF5 REQUIRED COMPONENTS PlasmaQuick DBusAddons Notifications) find_package(KF5 REQUIRED COMPONENTS PlasmaQuick DBusAddons Notifications)
find_package(KF5Wayland CONFIG)
set_package_properties(KF5Wayland PROPERTIES
TYPE REQUIRED
PURPOSE "Required for interacting with the compositor")
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
......
...@@ -13,6 +13,7 @@ target_link_libraries(plasma_containment_phone_taskpanel ...@@ -13,6 +13,7 @@ target_link_libraries(plasma_containment_phone_taskpanel
Qt5::Qml Qt5::Qml
KF5::I18n KF5::I18n
KF5::Service KF5::Service
KF5::WaylandClient
) )
......
...@@ -35,11 +35,21 @@ Rectangle { ...@@ -35,11 +35,21 @@ Rectangle {
property Item toolBox property Item toolBox
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
id: showDesktopButton
height: parent.height height: parent.height
width: height width: height
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
iconSource: "go-home" iconSource: "go-home"
onClicked: plasmoid.nativeInterface.executeScript("showdesktop"); checkable: true
onCheckedChanged: {
plasmoid.nativeInterface.showDesktop = checked;
}
Connections {
target: plasmoid.nativeInterface
onShowingDesktopChanged: {
showDesktopButton.checked = plasmoid.nativeInterface.showDesktop;
}
}
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
...@@ -49,4 +59,4 @@ Rectangle { ...@@ -49,4 +59,4 @@ Rectangle {
iconSource: "window-close" iconSource: "window-close"
onClicked: plasmoid.nativeInterface.executeScript("close"); onClicked: plasmoid.nativeInterface.executeScript("close");
} }
} }
\ No newline at end of file
...@@ -26,12 +26,19 @@ ...@@ -26,12 +26,19 @@
#include <Plasma/Package> #include <Plasma/Package>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/registry.h>
static const QString s_kwinService = QStringLiteral("org.kde.KWin"); static const QString s_kwinService = QStringLiteral("org.kde.KWin");
TaskPanel::TaskPanel(QObject *parent, const QVariantList &args) TaskPanel::TaskPanel(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args) : Plasma::Containment(parent, args)
, m_showingDesktop(false)
, m_windowManagement(nullptr)
{ {
setHasConfigurationInterface(true); setHasConfigurationInterface(true);
initWayland();
} }
TaskPanel::~TaskPanel() TaskPanel::~TaskPanel()
...@@ -61,6 +68,43 @@ void TaskPanel::executeScript(const QString &script) ...@@ -61,6 +68,43 @@ void TaskPanel::executeScript(const QString &script)
} }
} }
void TaskPanel::requestShowingDesktop(bool showingDesktop)
{
if (!m_windowManagement) {
return;
}
m_windowManagement->setShowingDesktop(showingDesktop);
}
void TaskPanel::initWayland()
{
if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
return;
}
using namespace KWayland::Client;
ConnectionThread *connection = ConnectionThread::fromApplication(this);
if (!connection) {
return;
}
Registry *registry = new Registry(this);
registry->create(connection);
connect(registry, &Registry::plasmaWindowManagementAnnounced, this,
[this, registry] (quint32 name, quint32 version) {
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this,
[this] (bool showing) {
if (showing == m_showingDesktop) {
return;
}
m_showingDesktop = showing;
emit showingDesktopChanged(m_showingDesktop);
}
);
}
);
registry->setup();
}
K_EXPORT_PLASMA_APPLET_WITH_JSON(taskpanel, TaskPanel, "metadata.json") K_EXPORT_PLASMA_APPLET_WITH_JSON(taskpanel, TaskPanel, "metadata.json")
#include "taskpanel.moc" #include "taskpanel.moc"
...@@ -24,9 +24,18 @@ ...@@ -24,9 +24,18 @@
#include <Plasma/Containment> #include <Plasma/Containment>
namespace KWayland
{
namespace Client
{
class PlasmaWindowManagement;
}
}
class TaskPanel : public Plasma::Containment class TaskPanel : public Plasma::Containment
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool showDesktop READ isShowingDesktop WRITE requestShowingDesktop NOTIFY showingDesktopChanged)
public: public:
TaskPanel( QObject *parent, const QVariantList &args ); TaskPanel( QObject *parent, const QVariantList &args );
...@@ -34,7 +43,18 @@ public: ...@@ -34,7 +43,18 @@ public:
Q_INVOKABLE void executeScript(const QString &script); Q_INVOKABLE void executeScript(const QString &script);
bool isShowingDesktop() const {
return m_showingDesktop;
}
void requestShowingDesktop(bool showingDesktop);
Q_SIGNALS:
void showingDesktopChanged(bool);
private: private:
void initWayland();
bool m_showingDesktop;
KWayland::Client::PlasmaWindowManagement *m_windowManagement;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment