diff --git a/kcmkwin/kwinscreenedges/CMakeLists.txt b/kcmkwin/kwinscreenedges/CMakeLists.txt --- a/kcmkwin/kwinscreenedges/CMakeLists.txt +++ b/kcmkwin/kwinscreenedges/CMakeLists.txt @@ -19,6 +19,7 @@ KF5::ConfigWidgets KF5::I18n KF5::Service + KF5::Package KF5::Plasma kwin4_effect_builtins ) diff --git a/kcmkwin/kwinscreenedges/main.h b/kcmkwin/kwinscreenedges/main.h --- a/kcmkwin/kwinscreenedges/main.h +++ b/kcmkwin/kwinscreenedges/main.h @@ -62,6 +62,7 @@ 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 @@ Cylinder, Sphere, TabBox, - TabBoxAlternative + TabBoxAlternative, + EffectCount }; bool effectEnabled(const BuiltInEffect& effect, const KConfigGroup& cfg) const; diff --git a/kcmkwin/kwinscreenedges/main.cpp b/kcmkwin/kwinscreenedges/main.cpp --- a/kcmkwin/kwinscreenedges/main.cpp +++ b/kcmkwin/kwinscreenedges/main.cpp @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #include K_PLUGIN_FACTORY(KWinScreenEdgesConfigFactory, registerPlugin();) @@ -205,6 +208,22 @@ 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 @@ 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 @@ 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/scripting/documentation-global.xml b/scripting/documentation-global.xml --- 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 --- a/scripting/kwinscript.desktop +++ b/scripting/kwinscript.desktop @@ -62,3 +62,6 @@ [PropertyDef::X-KWin-Exclude-Listing] Type=bool + +[PropertyDef::X-KWin-Border-Activate] +Type=bool