From 5f2ffad357c98013e59d6e2d5679fd2c051e0e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sat, 13 Jun 2015 00:18:24 +0200 Subject: [PATCH] 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. --- CMakeLists.txt | 4 ++ containments/taskpanel/CMakeLists.txt | 1 + .../package/contents/code/showdesktop.js | 2 - .../taskpanel/package/contents/ui/main.qml | 14 +++++- containments/taskpanel/taskpanel.cpp | 44 +++++++++++++++++++ containments/taskpanel/taskpanel.h | 20 +++++++++ 6 files changed, 81 insertions(+), 4 deletions(-) delete mode 100644 containments/taskpanel/package/contents/code/showdesktop.js diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f3fd935..70e0afc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 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) diff --git a/containments/taskpanel/CMakeLists.txt b/containments/taskpanel/CMakeLists.txt index 83cf80d5..0cf2b309 100644 --- a/containments/taskpanel/CMakeLists.txt +++ b/containments/taskpanel/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(plasma_containment_phone_taskpanel Qt5::Qml KF5::I18n KF5::Service + KF5::WaylandClient ) diff --git a/containments/taskpanel/package/contents/code/showdesktop.js b/containments/taskpanel/package/contents/code/showdesktop.js deleted file mode 100644 index d3530349..00000000 --- a/containments/taskpanel/package/contents/code/showdesktop.js +++ /dev/null @@ -1,2 +0,0 @@ - -workspace.slotToggleShowDesktop(); diff --git a/containments/taskpanel/package/contents/ui/main.qml b/containments/taskpanel/package/contents/ui/main.qml index 25e9c2db..506bab38 100644 --- a/containments/taskpanel/package/contents/ui/main.qml +++ b/containments/taskpanel/package/contents/ui/main.qml @@ -35,11 +35,21 @@ Rectangle { property Item toolBox PlasmaComponents.ToolButton { + id: showDesktopButton height: parent.height width: height anchors.horizontalCenter: parent.horizontalCenter 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 { @@ -49,4 +59,4 @@ Rectangle { iconSource: "window-close" onClicked: plasmoid.nativeInterface.executeScript("close"); } -} \ No newline at end of file +} diff --git a/containments/taskpanel/taskpanel.cpp b/containments/taskpanel/taskpanel.cpp index 729138bc..49dfecb9 100644 --- a/containments/taskpanel/taskpanel.cpp +++ b/containments/taskpanel/taskpanel.cpp @@ -26,12 +26,19 @@ #include +#include +#include +#include + static const QString s_kwinService = QStringLiteral("org.kde.KWin"); TaskPanel::TaskPanel(QObject *parent, const QVariantList &args) : Plasma::Containment(parent, args) + , m_showingDesktop(false) + , m_windowManagement(nullptr) { setHasConfigurationInterface(true); + initWayland(); } TaskPanel::~TaskPanel() @@ -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") #include "taskpanel.moc" diff --git a/containments/taskpanel/taskpanel.h b/containments/taskpanel/taskpanel.h index 259b1bf8..d384cb9d 100644 --- a/containments/taskpanel/taskpanel.h +++ b/containments/taskpanel/taskpanel.h @@ -24,9 +24,18 @@ #include +namespace KWayland +{ +namespace Client +{ +class PlasmaWindowManagement; +} +} + class TaskPanel : public Plasma::Containment { Q_OBJECT + Q_PROPERTY(bool showDesktop READ isShowingDesktop WRITE requestShowingDesktop NOTIFY showingDesktopChanged) public: TaskPanel( QObject *parent, const QVariantList &args ); @@ -34,7 +43,18 @@ public: Q_INVOKABLE void executeScript(const QString &script); + bool isShowingDesktop() const { + return m_showingDesktop; + } + void requestShowingDesktop(bool showingDesktop); + +Q_SIGNALS: + void showingDesktopChanged(bool); + private: + void initWayland(); + bool m_showingDesktop; + KWayland::Client::PlasmaWindowManagement *m_windowManagement; };