From 3e1e1e7d22776231a9c0e9aaf28437813cf4ae38 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Wed, 29 Mar 2023 19:40:47 -0700 Subject: [PATCH] envmanager: Extract kded settings management to separate app, add window decoration customization --- CMakeLists.txt | 1 + components/shellsettingsplugin/CMakeLists.txt | 2 + .../mobileshellsettings.cpp | 9 ++++ envmanager/CMakeLists.txt | 27 +++++++++++ {kded => envmanager}/config.h | 21 ++++++-- envmanager/main.cpp | 48 +++++++++++++++++++ {kded => envmanager}/settings.cpp | 32 ++++--------- {kded => envmanager}/settings.h | 11 ++--- {kded => envmanager}/utils.h | 2 +- kded/CMakeLists.txt | 5 +- kded/{startdaemon.cpp => start.cpp} | 13 +++-- kded/{startdaemon.h => start.h} | 0 12 files changed, 123 insertions(+), 48 deletions(-) create mode 100644 envmanager/CMakeLists.txt rename {kded => envmanager}/config.h (57%) create mode 100644 envmanager/main.cpp rename {kded => envmanager}/settings.cpp (87%) rename {kded => envmanager}/settings.h (86%) rename {kded => envmanager}/utils.h (74%) rename kded/{startdaemon.cpp => start.cpp} (50%) rename kded/{startdaemon.h => start.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5109687b..a0aaf129 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,6 +103,7 @@ add_subdirectory(quicksettings) add_subdirectory(kcms) add_subdirectory(kded) add_subdirectory(kwin) +add_subdirectory(envmanager) find_program(PlasmaOpenSettings plasma-open-settings) set_package_properties(PlasmaOpenSettings PROPERTIES diff --git a/components/shellsettingsplugin/CMakeLists.txt b/components/shellsettingsplugin/CMakeLists.txt index ed56f210..75eb8a42 100644 --- a/components/shellsettingsplugin/CMakeLists.txt +++ b/components/shellsettingsplugin/CMakeLists.txt @@ -16,6 +16,8 @@ target_link_libraries(shellsettingsplugin KF6::Service KF6::ConfigWidgets KF6::Package + KF6::KIOGui + KF6::Notifications ) set_property(TARGET shellsettingsplugin PROPERTY LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/org/kde/plasma/private/mobileshell/shellsettingsplugin) diff --git a/components/shellsettingsplugin/mobileshellsettings.cpp b/components/shellsettingsplugin/mobileshellsettings.cpp index cc423b21..fa7fa20b 100644 --- a/components/shellsettingsplugin/mobileshellsettings.cpp +++ b/components/shellsettingsplugin/mobileshellsettings.cpp @@ -6,6 +6,9 @@ #include "mobileshellsettings.h" +#include +#include +#include #include const QString CONFIG_FILE = QStringLiteral("plasmamobilerc"); @@ -154,4 +157,10 @@ void MobileShellSettings::setConvergenceModeEnabled(bool enabled) auto group = KConfigGroup{m_config, GENERAL_CONFIG_GROUP}; group.writeEntry("convergenceModeEnabled", enabled, KConfigGroup::Notify); m_config->sync(); + + // update environment settings + auto *job = new KIO::CommandLauncherJob(QStringLiteral("plasma-mobile-envmanager --apply-settings"), {}); + job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoErrorHandlingEnabled)); + job->setDesktopName(QStringLiteral("org.kde.plasma-mobile-envmanager")); + job->start(); } diff --git a/envmanager/CMakeLists.txt b/envmanager/CMakeLists.txt new file mode 100644 index 00000000..c30eca6a --- /dev/null +++ b/envmanager/CMakeLists.txt @@ -0,0 +1,27 @@ +# SPDX-FileCopyrightText: 2023 Devin Lin +# SPDX-License-Identifier: GPL-2.0-or-later + +set(plasma-mobile-envmanager_SRCS + main.cpp + settings.cpp + utils.h + config.h +) + +add_executable(plasma-mobile-envmanager ${plasma-mobile-envmanager_SRCS} ${RESOURCES}) +target_link_libraries(plasma-mobile-envmanager + Qt::Qml + Qt::Gui + Qt::Widgets + Qt::Quick + KF6::I18n + KF6::ConfigCore + KF6::ConfigGui + KF6::CoreAddons + KF6::DBusAddons + KF6::Package +) + +target_include_directories(plasma-mobile-envmanager PRIVATE ${CMAKE_BINARY_DIR}) +install(TARGETS plasma-mobile-envmanager ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) + diff --git a/kded/config.h b/envmanager/config.h similarity index 57% rename from kded/config.h rename to envmanager/config.h index 8378b1c1..98efd60f 100644 --- a/kded/config.h +++ b/envmanager/config.h @@ -9,11 +9,8 @@ #include #include -// kwinrc -const QMap> KWINRC_SETTINGS = { - {"Plugins", {{"blurEnabled", false}, {"convergentwindowsEnabled", true}}}, - {"Wayland", {{"InputMethod", "/usr/share/applications/com.github.maliit.keyboard.desktop"}, {"VirtualKeyboardEnabled", true}}}, -}; +#include +#include // applications-blacklistrc // NOTE: we only write these entries if they are not already defined in the config @@ -27,3 +24,17 @@ const QMap> APPLICATIONS_BLACKLIST_SETTINGS = { // kdeglobals // NOTE: we only write these entries if they are not already defined in the config const QMap> KDEGLOBALS_SETTINGS = {{"General", {{"BrowserApplication", "angelfish"}}}}; + +// kwinrc +QMap> getKwinrcSettings(KSharedConfig::Ptr m_mobileConfig) +{ + auto group = KConfigGroup{m_mobileConfig, QStringLiteral("General")}; + bool convergenceModeEnabled = group.readEntry("convergenceModeEnabled", false); + + return { + {"Plugins", {{"blurEnabled", false}, {"convergentwindowsEnabled", true}}}, + {"Wayland", {{"InputMethod", "/usr/share/applications/com.github.maliit.keyboard.desktop"}, {"VirtualKeyboardEnabled", true}}}, + {"org.kde.kdecoration2", + {{"ButtonsOnRight", convergenceModeEnabled ? "HIAX" : "H"}}} // ButtonsOnRight changes depending on whether the device is in convergence mode + }; +} diff --git a/envmanager/main.cpp b/envmanager/main.cpp new file mode 100644 index 00000000..232504f0 --- /dev/null +++ b/envmanager/main.cpp @@ -0,0 +1,48 @@ +// SPDX-FileCopyrightText: 2023 Devin Lin +// SPDX-License-Identifier: LGPL-2.0-or-later + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "settings.h" +#include "version.h" + +QCommandLineParser *createParser() +{ + QCommandLineParser *parser = new QCommandLineParser; + parser->addOption(QCommandLineOption(QStringLiteral("apply-settings"), i18n("Applies the correct system settings for the current environment."))); + parser->addVersionOption(); + parser->addHelpOption(); + return parser; +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + // parse command + QScopedPointer parser{createParser()}; + parser->process(app); + + // start wizard + KLocalizedString::setApplicationDomain("plasma-mobile-envmanager"); + QCoreApplication::setApplicationName(QStringLiteral("plasma-mobile-envmanager")); + QCoreApplication::setApplicationVersion(QStringLiteral(PLASMA_MOBILE_VERSION_STRING)); + QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); + + // apply configuration + if (parser->isSet(QStringLiteral("apply-settings"))) { + Settings::self()->applyConfiguration(); + } else { + parser->showHelp(); + } + + return 0; +} diff --git a/kded/settings.cpp b/envmanager/settings.cpp similarity index 87% rename from kded/settings.cpp rename to envmanager/settings.cpp index 50876981..ea72366b 100644 --- a/kded/settings.cpp +++ b/envmanager/settings.cpp @@ -23,10 +23,11 @@ const QString LOOK_AND_FEEL_KEY = QStringLiteral("LookAndFeelPackage"); Settings::Settings(QObject *parent) : QObject{parent} , m_isMobilePlatform{KRuntimePlatform::runtimePlatform().contains(QStringLiteral("phone"))} - , m_initialStartConfig{KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig)} + , m_mobileConfig{KSharedConfig::openConfig(CONFIG_FILE, KConfig::SimpleConfig)} , m_kwinrcConfig{KSharedConfig::openConfig(QStringLiteral("kwinrc"), KConfig::SimpleConfig)} , m_appBlacklistConfig{KSharedConfig::openConfig(QStringLiteral("applications-blacklistrc"), KConfig::SimpleConfig)} , m_kdeglobalsConfig{KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig)} + , m_configWatcher{KConfigWatcher::create(m_mobileConfig)} { } @@ -36,23 +37,6 @@ Settings *Settings::self() return settings; } -bool Settings::shouldStartWizard() -{ - if (!m_isMobilePlatform) { - return false; - } - - const auto group = KConfigGroup{m_initialStartConfig, INITIAL_START_CONFIG_GROUP}; - return !group.readEntry("wizardRun", false); -} - -void Settings::setWizardFinished() -{ - auto group = KConfigGroup{m_initialStartConfig, INITIAL_START_CONFIG_GROUP}; - group.writeEntry("wizardRun", true, KConfigGroup::Notify); - m_initialStartConfig->sync(); -} - void Settings::applyConfiguration() { if (!m_isMobilePlatform) { @@ -72,7 +56,7 @@ void Settings::loadSavedConfiguration() loadSavedConfigSetting(m_kdeglobalsConfig, QStringLiteral("kdeglobals"), QStringLiteral("KDE"), LOOK_AND_FEEL_KEY); // kwinrc - loadKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, KWINRC_SETTINGS); + loadKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, getKwinrcSettings(m_mobileConfig)); m_kwinrcConfig->sync(); reloadKWinConfig(); @@ -85,7 +69,7 @@ void Settings::loadSavedConfiguration() m_kdeglobalsConfig->sync(); // save our changes - m_initialStartConfig->sync(); + m_mobileConfig->sync(); } void Settings::applyMobileConfiguration() @@ -102,7 +86,7 @@ void Settings::applyMobileConfiguration() } // kwinrc - writeKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, KWINRC_SETTINGS, false); + writeKeys(QStringLiteral("kwinrc"), m_kwinrcConfig, getKwinrcSettings(m_mobileConfig), false); m_kwinrcConfig->sync(); reloadKWinConfig(); @@ -117,7 +101,7 @@ void Settings::applyMobileConfiguration() m_kdeglobalsConfig->sync(); // save our changes - m_initialStartConfig->sync(); + m_mobileConfig->sync(); } void Settings::writeKeys(const QString &fileName, KSharedConfig::Ptr &config, const QMap> &settings, bool overwriteOnlyIfEmpty) @@ -151,7 +135,7 @@ void Settings::loadKeys(const QString &fileName, KSharedConfig::Ptr &config, con // NOTE: this only saves a value if it hasn't already been saved void Settings::saveConfigSetting(const QString &fileName, const QString &group, const QString &key, const QVariant value) { - auto savedGroup = KConfigGroup{m_initialStartConfig, SAVED_CONFIG_GROUP}; + auto savedGroup = KConfigGroup{m_mobileConfig, SAVED_CONFIG_GROUP}; auto fileGroup = KConfigGroup{&savedGroup, fileName}; auto keyGroup = KConfigGroup{&fileGroup, group}; @@ -164,7 +148,7 @@ void Settings::saveConfigSetting(const QString &fileName, const QString &group, // NOTE: this deletes the stored value from the config after loading void Settings::loadSavedConfigSetting(KSharedConfig::Ptr &config, const QString &fileName, const QString &group, const QString &key) { - const auto savedGroup = KConfigGroup{m_initialStartConfig, SAVED_CONFIG_GROUP}; + const auto savedGroup = KConfigGroup{m_mobileConfig, SAVED_CONFIG_GROUP}; const auto fileGroup = KConfigGroup{&savedGroup, fileName}; auto keyGroup = KConfigGroup{&fileGroup, group}; diff --git a/kded/settings.h b/envmanager/settings.h similarity index 86% rename from kded/settings.h rename to envmanager/settings.h index 28d3b179..146c00a8 100644 --- a/kded/settings.h +++ b/envmanager/settings.h @@ -6,6 +6,7 @@ #include #include +#include #include class Settings : public QObject @@ -16,12 +17,6 @@ public: Settings(QObject *parent = nullptr); static Settings *self(); - // whether the initial start wizard should be started - bool shouldStartWizard(); - - // set that the wizard has finished - void setWizardFinished(); - // apply the configuration void applyConfiguration(); @@ -42,8 +37,10 @@ private: // whether this is Plasma Mobile bool m_isMobilePlatform; - KSharedConfig::Ptr m_initialStartConfig; + KSharedConfig::Ptr m_mobileConfig; KSharedConfig::Ptr m_kwinrcConfig; KSharedConfig::Ptr m_appBlacklistConfig; KSharedConfig::Ptr m_kdeglobalsConfig; + + KConfigWatcher::Ptr m_configWatcher; }; diff --git a/kded/utils.h b/envmanager/utils.h similarity index 74% rename from kded/utils.h rename to envmanager/utils.h index 78050620..1c0a25b8 100644 --- a/kded/utils.h +++ b/envmanager/utils.h @@ -7,6 +7,6 @@ static const QLoggingCategory &LOGGING_CATEGORY() { - static const QLoggingCategory category("plasma-mobile-initial-start"); + static const QLoggingCategory category("plasma-mobile-envmanager"); return category; } diff --git a/kded/CMakeLists.txt b/kded/CMakeLists.txt index 0910db4a..6157f365 100644 --- a/kded/CMakeLists.txt +++ b/kded/CMakeLists.txt @@ -4,10 +4,7 @@ kcoreaddons_add_plugin(kded_plasma_mobile_start INSTALL_NAMESPACE "kf${QT_MAJOR_VERSION}/kded") target_sources(kded_plasma_mobile_start PRIVATE - startdaemon.cpp - settings.cpp - config.h - utils.h + start.cpp ) target_link_libraries(kded_plasma_mobile_start PRIVATE diff --git a/kded/startdaemon.cpp b/kded/start.cpp similarity index 50% rename from kded/startdaemon.cpp rename to kded/start.cpp index c05b6520..72381e7b 100644 --- a/kded/startdaemon.cpp +++ b/kded/start.cpp @@ -7,16 +7,15 @@ #include -#include "settings.h" -#include "startdaemon.h" - -K_PLUGIN_CLASS_WITH_JSON(PlasmaMobileStartDaemon, "kded_plasma_mobile_start.json") +#include "start.h" PlasmaMobileStartDaemon::PlasmaMobileStartDaemon(QObject *parent, const QList &) : KDEDModule{parent} { - // apply configuration - Settings::self()->applyConfiguration(); + auto *job = new KIO::CommandLauncherJob(QStringLiteral("plasma-mobile-envmanager --apply-settings"), {}); + job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoErrorHandlingEnabled)); + job->setDesktopName(QStringLiteral("org.kde.plasma-mobile-envmanager")); + job->start(); } -#include "startdaemon.moc" +#include "start.moc" diff --git a/kded/startdaemon.h b/kded/start.h similarity index 100% rename from kded/startdaemon.h rename to kded/start.h