/*************************************************************************** * Copyright (C) 2015 Marco Martin * * * * This program 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. * * * * This program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "taskpanel.h" #include #include #include #include #include #include #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() { } void TaskPanel::executeScript(const QString &script) { //Plasma::Package p = QDBusMessage message = QDBusMessage::createMethodCall(s_kwinService, "/Scripting", QString(), "loadScript"); QList arguments; arguments << QVariant(package().filePath("scripts", script + ".js")); message.setArguments(arguments); QDBusPendingReply asyncCall = QDBusConnection::sessionBus().asyncCall(message); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCall, this); QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(loadScriptFinishedSlot(QDBusPendingCallWatcher*))); } void TaskPanel::loadScriptFinishedSlot(QDBusPendingCallWatcher *watcher) { QDBusMessage reply = watcher->reply(); if (reply.type() == QDBusMessage::ErrorMessage) { qWarning() << reply.errorMessage(); } else { const int id = reply.arguments().first().toInt(); QDBusConnection::sessionBus().connect(s_kwinService, "/" + QString::number(id), QString(), "print", this, SLOT(print(QString))); QDBusConnection::sessionBus().connect(s_kwinService, "/" + QString::number(id), QString(), "printError", this, SLOT(print(QString))); QDBusMessage message = QDBusMessage::createMethodCall(s_kwinService, "/" + QString::number(id), QString(), "run"); //fire blindly the call for now QDBusConnection::sessionBus().asyncCall(message); } } 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"