From 4bb12f3f010d41f1d443abde2212ea6418382676 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Fri, 7 Oct 2016 15:20:14 +0100 Subject: [PATCH] Allow configuring script's screen edges from the KCM Summary: Modify the kwinscreenedges KCM to also list scripts which support screen edge activation and read/write the appropriate value in the script's config. In order to only show relevant scripts an additional .desktop metadata field is added. Test Plan: Opened KCM set a hot corner for minimize all. Tested it unset it, and set on another corner Tested again Reviewers: #plasma, graesslin Reviewed By: #plasma, graesslin Subscribers: graesslin, plasma-devel, kwin Tags: #plasma Differential Revision: https://phabricator.kde.org/D2972 --- kcmkwin/kwinscreenedges/CMakeLists.txt | 1 + kcmkwin/kwinscreenedges/main.cpp | 36 ++++++++++++++++++++++++++ kcmkwin/kwinscreenedges/main.h | 4 ++- scripting/documentation-global.xml | 4 ++- scripting/kwinscript.desktop | 3 +++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/kcmkwin/kwinscreenedges/CMakeLists.txt b/kcmkwin/kwinscreenedges/CMakeLists.txt index 9921b66b2..ddd513ea4 100644 --- a/kcmkwin/kwinscreenedges/CMakeLists.txt +++ b/kcmkwin/kwinscreenedges/CMakeLists.txt @@ -19,6 +19,7 @@ target_link_libraries( kcm_kwinscreenedges ${X11_LIBRARIES} KF5::ConfigWidgets KF5::I18n KF5::Service + KF5::Package KF5::Plasma kwin4_effect_builtins ) diff --git a/kcmkwin/kwinscreenedges/main.cpp b/kcmkwin/kwinscreenedges/main.cpp index cf864bc22..975e2d515 100644 --- a/kcmkwin/kwinscreenedges/main.cpp +++ b/kcmkwin/kwinscreenedges/main.cpp @@ -27,6 +27,9 @@ along with this program. If not, see . #include #include #include +#include +#include +#include #include K_PLUGIN_FACTORY(KWinScreenEdgesConfigFactory, registerPlugin();) @@ -205,6 +208,22 @@ void KWinScreenEdgesConfig::monitorInit() monitorAddItem(i18n("Toggle window switching")); monitorAddItem(i18n("Toggle alternative window switching")); + const QString scriptFolder = QStringLiteral("kwin/scripts/"); + const auto scripts = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KWin/Script"), scriptFolder); + + KConfigGroup config(m_config, "Plugins"); + for (const KPluginMetaData &script: scripts) { + if (script.value(QStringLiteral("X-KWin-Border-Activate")) != QLatin1String("true")) { + continue; + } + + if (!config.readEntry(script.pluginId() + QStringLiteral("Enabled"), script.isEnabledByDefault())) { + continue; + } + m_scripts << script.pluginId(); + monitorAddItem(script.name()); + } + monitorShowEvent(); } @@ -303,6 +322,16 @@ void KWinScreenEdgesConfig::monitorLoad() foreach (int i, list) { monitorChangeEdge(ElectricBorder(i), int(TabBoxAlternative)); } + + for (int i=0; i < m_scripts.size(); i++) { + int index = EffectCount + i; + KConfigGroup scriptConfig(m_config, "Script-"+m_scripts[i]); + list.append(int(ElectricNone)); + list = scriptConfig.readEntry("BorderActivate", list); + for (int i: list) { + monitorChangeEdge(ElectricBorder(i), index); + } + } } void KWinScreenEdgesConfig::monitorSaveAction(int edge, const QString& configName) @@ -366,6 +395,13 @@ void KWinScreenEdgesConfig::monitorSave() monitorCheckEffectHasEdge(int(TabBox))); tabBoxConfig.writeEntry("BorderAlternativeActivate", monitorCheckEffectHasEdge(int(TabBoxAlternative))); + + for (int i=0; i < m_scripts.size(); i++) { + int index = EffectCount + i; + KConfigGroup scriptConfig(m_config, "Script-"+m_scripts[i]); + scriptConfig.writeEntry("BorderActivate", + monitorCheckEffectHasEdge(index)); + } } void KWinScreenEdgesConfig::monitorDefaults() diff --git a/kcmkwin/kwinscreenedges/main.h b/kcmkwin/kwinscreenedges/main.h index 16117eef5..4b7eb4fb5 100644 --- a/kcmkwin/kwinscreenedges/main.h +++ b/kcmkwin/kwinscreenedges/main.h @@ -62,6 +62,7 @@ private Q_SLOTS: private: KWinScreenEdgesConfigForm* m_ui; KSharedConfigPtr m_config; + QStringList m_scripts; //list of script IDs ordered in the list they are presented in the menu enum EffectActions { PresentWindowsAll = ELECTRIC_ACTION_COUNT, // Start at the end of built in actions @@ -72,7 +73,8 @@ private: Cylinder, Sphere, TabBox, - TabBoxAlternative + TabBoxAlternative, + EffectCount }; bool effectEnabled(const BuiltInEffect& effect, const KConfigGroup& cfg) const; diff --git a/scripting/documentation-global.xml b/scripting/documentation-global.xml index af4d9a0d5..4bef7b35d 100644 --- a/scripting/documentation-global.xml +++ b/scripting/documentation-global.xml @@ -55,7 +55,9 @@ (ElectricBorder border, QScriptValue callback) registerScreenEdge - Registers the callback for the screen edge. When the mouse gets pushed against the given edge the callback will be invoked. + Registers the callback for the screen edge. When the mouse gets pushed against the given edge the callback will be invoked. + Scripts can also add "X-KWin-Border-Activate" to their metadata file to have the effect listed in the screen edges KCM. This will write an entry BorderConfig= in the script configuration object with a list of ScreenEdges the user has selected. + Q_SCRIPTABLE bool diff --git a/scripting/kwinscript.desktop b/scripting/kwinscript.desktop index 0c20e8145..e0c0738b9 100644 --- a/scripting/kwinscript.desktop +++ b/scripting/kwinscript.desktop @@ -62,3 +62,6 @@ Type=QString [PropertyDef::X-KWin-Exclude-Listing] Type=bool + +[PropertyDef::X-KWin-Border-Activate] +Type=bool