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.
This commit is contained in:
Martin Gräßlin 2015-06-13 00:18:24 +02:00
parent fd382d0b2b
commit 5f2ffad357
6 changed files with 81 additions and 4 deletions

View file

@ -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)

View file

@ -13,6 +13,7 @@ target_link_libraries(plasma_containment_phone_taskpanel
Qt5::Qml
KF5::I18n
KF5::Service
KF5::WaylandClient
)

View file

@ -1,2 +0,0 @@
workspace.slotToggleShowDesktop();

View file

@ -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");
}
}
}

View file

@ -26,12 +26,19 @@
#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");
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"

View file

@ -24,9 +24,18 @@
#include <Plasma/Containment>
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;
};