From 0e6221ce520226a1271f321a6c1d927ee3e52a16 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Thu, 24 Apr 2025 17:26:11 +0200 Subject: [PATCH] envmanager: Add overlay configs through XDG_CONFIG_DIRS We currently directly write our settings to ~/.config/kwinrc and ~/.config/ksmserver. Instead, create a separate config file with our settings (in ~/.config/plasma-mobile), and in startplasmamobile, add that path to XDG_CONFIG_DIRS. These options will be applied in the mobile session, unless the user explicitly sets the config option. --- bin/startplasmamobile.in | 3 ++ envmanager/config.h | 4 +-- envmanager/settings.cpp | 59 +++++++++++++++++++++++++++++----------- envmanager/settings.h | 10 +++++-- 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/bin/startplasmamobile.in b/bin/startplasmamobile.in index 3f9489bb..d7f465ac 100755 --- a/bin/startplasmamobile.in +++ b/bin/startplasmamobile.in @@ -16,6 +16,9 @@ export QT_QUICK_CONTROLS_MOBILE=true export PLASMA_INTEGRATION_USE_PORTAL=1 export PLASMA_PLATFORM=phone:handset +# Set ~/.config/plasma-mobile/... as location for default mobile configs (i.e. envmanager generated) +export XDG_CONFIG_DIRS="$HOME/.config/plasma-mobile:/etc/xdg:$XDG_CONFIG_DIRS" + # if coredumpd knows about the dumps, make sure drkonqi catches them if grep -q '/systemd-coredump' /proc/sys/kernel/core_pattern then diff --git a/envmanager/config.h b/envmanager/config.h index 0d410173..2f947513 100644 --- a/envmanager/config.h +++ b/envmanager/config.h @@ -32,7 +32,7 @@ const QMap> KDEGLOBALS_DEFAULT_SETTINGS = {{"Ge const QMap> KDEGLOBALS_SETTINGS = {{"KDE", {{"LookAndFeelPackage", "org.kde.breeze.mobile"}}}}; -// kwinrc +// plasma-mobile/kwinrc QMap> getKwinrcSettings(KSharedConfig::Ptr m_mobileConfig) { auto group = KConfigGroup{m_mobileConfig, QStringLiteral("General")}; @@ -72,5 +72,5 @@ QMap> getKwinrcSettings(KSharedConfig::Ptr m_mo const QList KWIN_EFFECTS = {"blur", "mobiletaskswitcher", "screenedge"}; const QList KWIN_SCRIPTS = {"convergentwindows"}; -//ksmserver +// plasma-mobile/ksmserver const QMap> KSMSERVER_SETTINGS = {{"General", {{"loginMode", "emptySession"}}}}; diff --git a/envmanager/settings.cpp b/envmanager/settings.cpp index 136617e8..f99e0934 100644 --- a/envmanager/settings.cpp +++ b/envmanager/settings.cpp @@ -18,14 +18,19 @@ using namespace Qt::Literals::StringLiterals; const QString CONFIG_FILE = u"plasmamobilerc"_s; const QString SAVED_CONFIG_GROUP = u"SavedConfig"_s; +// In bin/startplasmamobile, we add `~/.config/plasma-mobile` to XDG_CONFIG_DIRS to overlay our own configs +const QString MOBILE_KWINRC_FILE = u"plasma-mobile/kwinrc"_s; +const QString MOBILE_KSMSERVERRC_FILE = u"plasma-mobile/ksmserverrc"_s; + Settings::Settings(QObject *parent) : QObject{parent} , m_isMobilePlatform{KRuntimePlatform::runtimePlatform().contains(u"phone"_s)} , m_mobileConfig{KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig)} - , m_kwinrcConfig{KSharedConfig::openConfig(u"kwinrc"_s, KConfig::SimpleConfig)} + , m_kwinrcConfig{KSharedConfig::openConfig(MOBILE_KWINRC_FILE, KConfig::SimpleConfig)} , m_appBlacklistConfig{KSharedConfig::openConfig(u"applications-blacklistrc"_s, KConfig::SimpleConfig)} , m_kdeglobalsConfig{KSharedConfig::openConfig(u"kdeglobals"_s, KConfig::SimpleConfig)} - , m_ksmServerConfig{KSharedConfig::openConfig(u"ksmserverrc"_s, KConfig::SimpleConfig)} + , m_ksmServerConfig{KSharedConfig::openConfig(MOBILE_KSMSERVERRC_FILE, KConfig::SimpleConfig)} + , m_originalKwinrcConfig{KSharedConfig::openConfig(u"kwinrc"_s, KConfig::SimpleConfig)} , m_configWatcher{KConfigWatcher::create(m_mobileConfig)} { } @@ -51,9 +56,9 @@ void Settings::applyConfiguration() void Settings::loadSavedConfiguration() { - // kwinrc - loadKeys(u"kwinrc"_s, m_kwinrcConfig, getKwinrcSettings(m_mobileConfig)); - m_kwinrcConfig->sync(); + // kwinrc (legacy, we only write in the plasma-mobile/kwinrc file now) + loadKeys(u"kwinrc"_s, m_originalKwinrcConfig, getKwinrcSettings(m_mobileConfig)); + m_originalKwinrcConfig->sync(); reloadKWinConfig(); // applications-blacklistrc @@ -71,33 +76,51 @@ void Settings::loadSavedConfiguration() void Settings::applyMobileConfiguration() { - // kwinrc - writeKeys(u"kwinrc"_s, m_kwinrcConfig, getKwinrcSettings(m_mobileConfig), false); + // kwinrc-plasma-mobile + writeKeys(MOBILE_KWINRC_FILE, m_kwinrcConfig, getKwinrcSettings(m_mobileConfig)); m_kwinrcConfig->sync(); reloadKWinConfig(); // applications-blacklistrc - writeKeys(u"applications-blacklistrc"_s, - m_appBlacklistConfig, - APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS, - true); // only write entries if they are not already defined in the config + writeKeysAndSave(u"applications-blacklistrc"_s, + m_appBlacklistConfig, + APPLICATIONS_BLACKLIST_DEFAULT_SETTINGS, + true); // only write entries if they are not already defined in the config m_appBlacklistConfig->sync(); // kdeglobals - writeKeys(u"kdeglobals"_s, m_kdeglobalsConfig, KDEGLOBALS_DEFAULT_SETTINGS, - true); // only write entries if they are not already defined in the config - writeKeys(u"kdeglobals"_s, m_kdeglobalsConfig, KDEGLOBALS_SETTINGS, false); + writeKeysAndSave(u"kdeglobals"_s, + m_kdeglobalsConfig, + KDEGLOBALS_DEFAULT_SETTINGS, + true); // only write entries if they are not already defined in the config + writeKeysAndSave(u"kdeglobals"_s, m_kdeglobalsConfig, KDEGLOBALS_SETTINGS, false); m_kdeglobalsConfig->sync(); // ksmserver - writeKeys(u"ksmserverrc"_s, m_ksmServerConfig, KSMSERVER_SETTINGS, false); + writeKeys(MOBILE_KSMSERVERRC_FILE, m_ksmServerConfig, KSMSERVER_SETTINGS); m_ksmServerConfig->sync(); // save our changes m_mobileConfig->sync(); } -void Settings::writeKeys(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings, bool overwriteOnlyIfEmpty) +void Settings::writeKeys(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings) +{ + const auto groupNames = settings.keys(); + for (const auto &groupName : groupNames) { + auto group = KConfigGroup{config, groupName}; + + const auto keys = settings[groupName].keys(); + for (const auto &key : keys) { + group.writeEntry(key, settings[groupName][key], KConfigGroup::Notify); + } + } +} + +void Settings::writeKeysAndSave(const QString &fileName, + KSharedConfig::Ptr &config, + const QMap> &settings, + bool overwriteOnlyIfEmpty) { const auto groupNames = settings.keys(); for (const auto &groupName : groupNames) { @@ -209,4 +232,8 @@ void Settings::reloadKWinConfig() // Call "start" to load enabled KWin scripts. QDBusMessage message = QDBusMessage::createMethodCall(u"org.kde.KWin"_s, u"/Scripting"_s, u"org.kde.kwin.Scripting"_s, u"start"_s); QDBusConnection::sessionBus().send(message); + + // Call reconfigure + QDBusMessage reconfigureMessage = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reconfigure"); + QDBusConnection::sessionBus().send(reconfigureMessage); } diff --git a/envmanager/settings.h b/envmanager/settings.h index d8d9814a..622d7f45 100644 --- a/envmanager/settings.h +++ b/envmanager/settings.h @@ -28,7 +28,10 @@ private: // applies our mobile configuration void applyMobileConfiguration(); - void writeKeys(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings, bool overwriteOnlyIfEmpty); + void writeKeys(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings); + + void + writeKeysAndSave(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings, bool overwriteOnlyIfEmpty); void loadKeys(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings); void saveConfigSetting(const QString &fileName, const QString &group, const QString &key, const QVariant value); const QString loadSavedConfigSetting(KSharedConfig::Ptr &config, const QString &fileName, const QString &group, const QString &key, bool write = true); @@ -39,10 +42,13 @@ private: bool m_isMobilePlatform; KSharedConfig::Ptr m_mobileConfig; - KSharedConfig::Ptr m_kwinrcConfig; + KSharedConfig::Ptr m_kwinrcConfig; // (~/.config/kwinrc-plasma-mobile) KSharedConfig::Ptr m_appBlacklistConfig; KSharedConfig::Ptr m_kdeglobalsConfig; KSharedConfig::Ptr m_ksmServerConfig; + // For legacy upgrade purposes (~/.config/kwinrc) + KSharedConfig::Ptr m_originalKwinrcConfig; + KConfigWatcher::Ptr m_configWatcher; };