diff --git a/runners/CMakeLists.txt b/runners/CMakeLists.txt index 2da20a123..0ff11c62a 100644 --- a/runners/CMakeLists.txt +++ b/runners/CMakeLists.txt @@ -1,2 +1,2 @@ add_subdirectory(plasma-desktop) - +add_subdirectory(kwin) diff --git a/runners/kwin/CMakeLists.txt b/runners/kwin/CMakeLists.txt new file mode 100644 index 000000000..fcf270763 --- /dev/null +++ b/runners/kwin/CMakeLists.txt @@ -0,0 +1,13 @@ +set(krunner_kwin_SRCS + kwin-runner.cpp +) + +add_library(krunner_kwin MODULE ${krunner_kwin_SRCS}) +target_link_libraries(krunner_kwin + Qt5::DBus + KF5::KIOCore + KF5::I18n + KF5::Runner) + +install(TARGETS krunner_kwin DESTINATION ${KDE_INSTALL_PLUGINDIR}) +install(FILES plasma-runner-kwin.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) diff --git a/runners/kwin/Messages.sh b/runners/kwin/Messages.sh new file mode 100755 index 000000000..731663092 --- /dev/null +++ b/runners/kwin/Messages.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash +$EXTRACTRC *.ui >> rc.cpp +$XGETTEXT *.cpp -o $podir/plasma_runner_kwin.pot +rm -f rc.cpp diff --git a/runners/kwin/kwin-runner.cpp b/runners/kwin/kwin-runner.cpp new file mode 100644 index 000000000..1fdade9a2 --- /dev/null +++ b/runners/kwin/kwin-runner.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2009 Aaron Seigo + * Copyright (C) 2016 Martin Gräßlin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library 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 "kwin-runner.h" + +#include +#include +#include + +#include + +#include + +K_EXPORT_PLASMA_RUNNER(kwin, KWinRunner) + +static const QString s_kwinService = QStringLiteral("org.kde.KWin"); +static const QString s_keyword = QStringLiteral("KWin"); + +KWinRunner::KWinRunner(QObject *parent, const QVariantList &args) + : Plasma::AbstractRunner(parent, args), + m_enabled(false) +{ + setObjectName(s_keyword); + setIgnoredTypes(Plasma::RunnerContext::FileSystem | + Plasma::RunnerContext::NetworkLocation | + Plasma::RunnerContext::Help); + QDBusServiceWatcher *watcher = new QDBusServiceWatcher(s_kwinService, QDBusConnection::sessionBus(), + QDBusServiceWatcher::WatchForOwnerChange, this); + connect(watcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &KWinRunner::checkAvailability); + checkAvailability(QString(), QString(), QString()); +} + +KWinRunner::~KWinRunner() +{ +} + +void KWinRunner::match(Plasma::RunnerContext &context) +{ + if (m_enabled && context.query().compare(s_keyword, Qt::CaseInsensitive) == 0) { + Plasma::QueryMatch match(this); + match.setId("kwin"); + match.setType(Plasma::QueryMatch::ExactMatch); + match.setIcon(QIcon::fromTheme("kwin")); + match.setText(i18n("Open KWin debug console")); + match.setRelevance(1.0); + context.addMatch(match); + } +} + +void KWinRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) +{ + Q_UNUSED(match) + + if (m_enabled && context.query().compare(s_keyword, Qt::CaseInsensitive) == 0) { + QDBusMessage message = QDBusMessage::createMethodCall(s_kwinService, QStringLiteral("/KWin"), s_kwinService, QStringLiteral("showDebugConsole")); + QDBusConnection::sessionBus().asyncCall(message); + } +} + +void KWinRunner::checkAvailability(const QString &name, const QString &oldOwner, const QString &newOwner) +{ + Q_UNUSED(oldOwner) + + bool enabled = false; + if (name.isEmpty()) { + enabled = QDBusConnection::sessionBus().interface()->isServiceRegistered(s_kwinService).value(); + } else { + enabled = !newOwner.isEmpty(); + } + + if (m_enabled != enabled) { + m_enabled = enabled; + + if (m_enabled) { + addSyntax(Plasma::RunnerSyntax(s_keyword, + i18n("Opens the KWin (Plasma Window Manager) debug console."))); + } else { + setSyntaxes(QList()); + } + } +} + +#include "kwin-runner.moc" diff --git a/runners/kwin/kwin-runner.h b/runners/kwin/kwin-runner.h new file mode 100644 index 000000000..9fd50abd5 --- /dev/null +++ b/runners/kwin/kwin-runner.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2009 Aaron Seigo + * Copyright (C) 2016 Martin Gräßlin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library 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. + */ + +#ifndef KWINRUNNER_H +#define KWINRUNNER_H + +#include + +class KWinRunner : public Plasma::AbstractRunner +{ + Q_OBJECT + + public: + explicit KWinRunner(QObject *parent, const QVariantList &args); + ~KWinRunner(); + + void match(Plasma::RunnerContext &context); + void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &action); + + private: + void checkAvailability(const QString &name, const QString &oldOwner, const QString &newOwner); + + private: + bool m_enabled; +}; + +#endif diff --git a/runners/kwin/plasma-runner-kwin.desktop b/runners/kwin/plasma-runner-kwin.desktop new file mode 100644 index 000000000..5d078e25d --- /dev/null +++ b/runners/kwin/plasma-runner-kwin.desktop @@ -0,0 +1,14 @@ +[Desktop Entry] +Name=KWin +Comment=Interact with the Plasma Compositor +X-KDE-ServiceTypes=Plasma/Runner +Type=Service +Icon=kwin +X-KDE-Library=krunner_kwin +X-Plasma-RunnerPhase=first +X-KDE-PluginInfo-Author=Plasma Team +X-KDE-PluginInfo-Email=plasma-devel@kde.org +X-KDE-PluginInfo-Name=kwin +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-License=LGPL +X-KDE-PluginInfo-EnabledByDefault=true