From 687fcd820341719864cceb4ba7e946597b5009a4 Mon Sep 17 00:00:00 2001 From: Cyril Rossi Date: Fri, 6 Dec 2019 14:11:29 +0100 Subject: [PATCH] KCM KWinDecoration port to KConfigXT Summary: Port to KConfigXt and also consider immutable element Reviewers: #kwin, ervin, bport, mart, davidedmundson Subscribers: zzag, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D25949 --- kcmkwin/kwindecoration/CMakeLists.txt | 3 + kcmkwin/kwindecoration/kcm.cpp | 243 ++++++------------ kcmkwin/kwindecoration/kcm.h | 45 ++-- .../kwindecorationsettings.kcfg | 53 ++++ .../kwindecorationsettings.kcfgc | 6 + .../package/contents/ui/Buttons.qml | 25 +- .../package/contents/ui/Themes.qml | 12 +- .../package/contents/ui/main.qml | 27 +- kcmkwin/kwindecoration/utils.cpp | 22 +- kcmkwin/kwindecoration/utils.h | 1 + 10 files changed, 204 insertions(+), 233 deletions(-) create mode 100644 kcmkwin/kwindecoration/kwindecorationsettings.kcfg create mode 100644 kcmkwin/kwindecoration/kwindecorationsettings.kcfgc diff --git a/kcmkwin/kwindecoration/CMakeLists.txt b/kcmkwin/kwindecoration/CMakeLists.txt index f591f69d5e..5be0504848 100644 --- a/kcmkwin/kwindecoration/CMakeLists.txt +++ b/kcmkwin/kwindecoration/CMakeLists.txt @@ -10,6 +10,8 @@ set(kcmkwindecoration_SRCS utils.cpp ) +kconfig_add_kcfg_files(kcmkwindecoration_SRCS kwindecorationsettings.kcfgc GENERATE_MOC) + add_library(kcm_kwindecoration MODULE ${kcmkwindecoration_SRCS}) target_link_libraries(kcm_kwindecoration @@ -23,6 +25,7 @@ target_link_libraries(kcm_kwindecoration kcoreaddons_desktop_to_json(kcm_kwindecoration "kwindecoration.desktop" SERVICE_TYPES kcmodule.desktop) # This desktop file is installed only for retrocompatibility with sycoca +install(FILES kwindecorationsettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR}) install(FILES kwindecoration.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) install(FILES window-decorations.knsrc DESTINATION ${KDE_INSTALL_KNSRCDIR}) install(TARGETS kcm_kwindecoration DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms) diff --git a/kcmkwin/kwindecoration/kcm.cpp b/kcmkwin/kwindecoration/kcm.cpp index f8d6be6183..afd5236462 100644 --- a/kcmkwin/kwindecoration/kcm.cpp +++ b/kcmkwin/kwindecoration/kcm.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2019 Valerio Pilo + * Copyright (c) 2019 Cyril Rossi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -36,6 +37,7 @@ #include +#include "kwindecorationsettings.h" K_PLUGIN_FACTORY_WITH_JSON(KCMKWinDecorationFactory, "kwindecoration.json", registerPlugin();) @@ -44,52 +46,17 @@ Q_DECLARE_METATYPE(KDecoration2::BorderSize) namespace { -const QString s_configFile { QStringLiteral("kwinrc") }; -const QString s_configGroup { QStringLiteral("org.kde.kdecoration2") }; -const QString s_configPlugin { QStringLiteral("library") }; -const QString s_configTheme { QStringLiteral("theme") }; -const QString s_configBorderSize { QStringLiteral("BorderSize") }; -const QString s_configBorderSizeAuto { QStringLiteral("BorderSizeAuto") }; -const QString s_configCloseOnDoubleClickOnMenu { QStringLiteral("CloseOnDoubleClickOnMenu") }; -const QString s_configShowToolTips { QStringLiteral("ShowToolTips") }; -const QString s_configDecoButtonsOnLeft { QStringLiteral("ButtonsOnLeft") }; -const QString s_configDecoButtonsOnRight { QStringLiteral("ButtonsOnRight") }; - -const KDecoration2::BorderSize s_defaultBorderSize = KDecoration2::BorderSize::Normal; const KDecoration2::BorderSize s_defaultRecommendedBorderSize = KDecoration2::BorderSize::Normal; -const bool s_defaultBorderSizeAuto = true; -const bool s_defaultCloseOnDoubleClickOnMenu = false; -const bool s_defaultShowToolTips = true; - -const DecorationButtonsList s_defaultDecoButtonsOnLeft { - KDecoration2::DecorationButtonType::Menu, - KDecoration2::DecorationButtonType::OnAllDesktops -}; -const DecorationButtonsList s_defaultDecoButtonsOnRight { - KDecoration2::DecorationButtonType::ContextHelp, - KDecoration2::DecorationButtonType::Minimize, - KDecoration2::DecorationButtonType::Maximize, - KDecoration2::DecorationButtonType::Close -}; - -#if HAVE_BREEZE_DECO -const QString s_defaultPlugin { QStringLiteral(BREEZE_KDECORATION_PLUGIN_ID) }; -const QString s_defaultTheme { QStringLiteral("Breeze") }; -#else -const QString s_defaultPlugin { QStringLiteral("org.kde.kwin.aurorae") }; -const QString s_defaultTheme { QStringLiteral("kwin4_decoration_qml_plastik") }; -#endif } KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &arguments) - : KQuickAddons::ConfigModule(parent, arguments) + : KQuickAddons::ManagedConfigModule(parent, arguments) , m_themesModel(new KDecoration2::Configuration::DecorationsModel(this)) , m_proxyThemesModel(new QSortFilterProxyModel(this)) , m_leftButtonsModel(new KDecoration2::Preview::ButtonsModel(DecorationButtonsList(), this)) , m_rightButtonsModel(new KDecoration2::Preview::ButtonsModel(DecorationButtonsList(), this)) , m_availableButtonsModel(new KDecoration2::Preview::ButtonsModel(this)) - , m_savedSettings{ s_defaultBorderSize, s_defaultBorderSizeAuto, -2 /* for setTheme() */, false, s_defaultShowToolTips, s_defaultDecoButtonsOnLeft, s_defaultDecoButtonsOnRight } - , m_currentSettings(m_savedSettings) + , m_settings(new KWinDecorationSettings(this)) { auto about = new KAboutData(QStringLiteral("kcm_kwindecoration"), i18n("Window Decorations"), @@ -100,26 +67,35 @@ KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &argume i18n("Author"), QStringLiteral("vpilo@coldshock.net")); setAboutData(about); + setButtons(Apply | Default | Help); #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) qmlRegisterType(); qmlRegisterType(); + qmlRegisterType(); #else qmlRegisterAnonymousType("org.kde.kwin.KWinDecoration", 1); qmlRegisterAnonymousType("org.kde.kwin.KWinDecoration", 1); + qmlRegisterAnonymousType("org.kde.kwin.KWinDecoration", 1); #endif m_proxyThemesModel->setSourceModel(m_themesModel); m_proxyThemesModel->setFilterCaseSensitivity(Qt::CaseInsensitive); m_proxyThemesModel->setSortCaseSensitivity(Qt::CaseInsensitive); m_proxyThemesModel->sort(0); - connect(m_leftButtonsModel, &QAbstractItemModel::rowsInserted, this, &KCMKWinDecoration::updateNeedsSave); - connect(m_leftButtonsModel, &QAbstractItemModel::rowsMoved, this, &KCMKWinDecoration::updateNeedsSave); - connect(m_leftButtonsModel, &QAbstractItemModel::rowsRemoved, this, &KCMKWinDecoration::updateNeedsSave); - connect(m_leftButtonsModel, &QAbstractItemModel::modelReset, this, &KCMKWinDecoration::updateNeedsSave); - connect(m_rightButtonsModel, &QAbstractItemModel::rowsInserted, this, &KCMKWinDecoration::updateNeedsSave); - connect(m_rightButtonsModel, &QAbstractItemModel::rowsMoved, this, &KCMKWinDecoration::updateNeedsSave); - connect(m_rightButtonsModel, &QAbstractItemModel::rowsRemoved, this, &KCMKWinDecoration::updateNeedsSave); - connect(m_rightButtonsModel, &QAbstractItemModel::modelReset, this, &KCMKWinDecoration::updateNeedsSave); + connect(m_settings, &KWinDecorationSettings::themeChanged, this, &KCMKWinDecoration::themeChanged); + connect(m_settings, &KWinDecorationSettings::borderSizeChanged, this, &KCMKWinDecoration::borderSizeChanged); + + connect(m_leftButtonsModel, &QAbstractItemModel::rowsInserted, this, &KCMKWinDecoration::onLeftButtonsChanged); + connect(m_leftButtonsModel, &QAbstractItemModel::rowsMoved, this, &KCMKWinDecoration::onLeftButtonsChanged); + connect(m_leftButtonsModel, &QAbstractItemModel::rowsRemoved, this, &KCMKWinDecoration::onLeftButtonsChanged); + connect(m_leftButtonsModel, &QAbstractItemModel::modelReset, this, &KCMKWinDecoration::onLeftButtonsChanged); + + connect(m_rightButtonsModel, &QAbstractItemModel::rowsInserted, this, &KCMKWinDecoration::onRightButtonsChanged); + connect(m_rightButtonsModel, &QAbstractItemModel::rowsMoved, this, &KCMKWinDecoration::onRightButtonsChanged); + connect(m_rightButtonsModel, &QAbstractItemModel::rowsRemoved, this, &KCMKWinDecoration::onRightButtonsChanged); + connect(m_rightButtonsModel, &QAbstractItemModel::modelReset, this, &KCMKWinDecoration::onRightButtonsChanged); + + connect(this, &KCMKWinDecoration::borderSizeChanged, this, &KCMKWinDecoration::settingsChanged); // Update the themes when the color scheme or a theme's settings change QDBusConnection::sessionBus() @@ -129,6 +105,11 @@ KCMKWinDecoration::KCMKWinDecoration(QObject *parent, const QVariantList &argume QMetaObject::invokeMethod(m_themesModel, "init", Qt::QueuedConnection); } +KWinDecorationSettings *KCMKWinDecoration::settings() const +{ + return m_settings; +} + void KCMKWinDecoration::reloadKWinSettings() { QMetaObject::invokeMethod(m_themesModel, "init", Qt::QueuedConnection); @@ -155,101 +136,51 @@ void KCMKWinDecoration::getNewStuff(QQuickItem *context) void KCMKWinDecoration::load() { - const KConfigGroup config = KSharedConfig::openConfig(s_configFile)->group(s_configGroup); + ManagedConfigModule::load(); - const QString plugin = config.readEntry(s_configPlugin, s_defaultPlugin); - const QString theme = config.readEntry(s_configTheme, s_defaultTheme); - int themeIndex = m_proxyThemesModel->mapFromSource(m_themesModel->findDecoration(plugin, theme)).row(); - if (themeIndex < 0) { - qWarning() << "Plugin" << plugin << "and theme" << theme << "not found"; - } else { - qDebug() << "Current theme: plugin" << plugin << "and theme" << theme; - } - setTheme(themeIndex); + m_leftButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnLeft())); + m_rightButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnRight())); - setCloseOnDoubleClickOnMenu(config.readEntry(s_configCloseOnDoubleClickOnMenu, s_defaultCloseOnDoubleClickOnMenu)); - setShowToolTips(config.readEntry(s_configShowToolTips, s_defaultShowToolTips)); + setBorderSize(borderSizeIndexFromString(m_settings->borderSize())); - const QString defaultSizeName = Utils::borderSizeToString(s_defaultBorderSize); - setBorderSize(Utils::stringToBorderSize(config.readEntry(s_configBorderSize, defaultSizeName))); - setBorderSizeAuto(config.readEntry(s_configBorderSizeAuto, s_defaultBorderSizeAuto)); - - m_leftButtonsModel->replace(Utils::readDecorationButtons(config, s_configDecoButtonsOnLeft, s_defaultDecoButtonsOnLeft)); - m_rightButtonsModel->replace(Utils::readDecorationButtons(config, s_configDecoButtonsOnRight, s_defaultDecoButtonsOnRight)); - m_currentSettings.buttonsOnLeft = m_leftButtonsModel->buttons(); - m_currentSettings.buttonsOnRight = m_rightButtonsModel->buttons(); - - m_savedSettings = m_currentSettings; - - updateNeedsSave(); + emit themeChanged(); } void KCMKWinDecoration::save() { - KConfigGroup config = KSharedConfig::openConfig(s_configFile)->group(s_configGroup); - - if (m_currentSettings.themeIndex >= 0) { - const QModelIndex index = m_proxyThemesModel->index(m_currentSettings.themeIndex, 0); - if (index.isValid()) { - const QString plugin = index.data(KDecoration2::Configuration::DecorationsModel::PluginNameRole).toString(); - const QString theme = index.data(KDecoration2::Configuration::DecorationsModel::ThemeNameRole).toString(); - config.writeEntry(s_configPlugin, plugin); - config.writeEntry(s_configTheme, theme); - qDebug() << "Saved theme: plugin" << plugin << "and theme" << theme; - } else { - qWarning() << "Cannot match theme index" << m_currentSettings.themeIndex << "in model"; - } + if (!m_settings->borderSizeAuto()) { + m_settings->setBorderSize(borderSizeIndexToString(m_borderSizeIndex)); + } else { + m_settings->setBorderSize(m_settings->defaultBorderSizeValue()); } - config.writeEntry(s_configCloseOnDoubleClickOnMenu, m_currentSettings.closeOnDoubleClickOnMenu); - config.writeEntry(s_configShowToolTips, m_currentSettings.showToolTips); - config.writeEntry(s_configBorderSize, Utils::borderSizeToString(m_currentSettings.borderSize)); - config.writeEntry(s_configBorderSizeAuto, m_currentSettings.borderSizeAuto); - config.writeEntry(s_configDecoButtonsOnLeft, Utils::buttonsToString(m_currentSettings.buttonsOnLeft), KConfigGroup::Notify); - config.writeEntry(s_configDecoButtonsOnRight, Utils::buttonsToString(m_currentSettings.buttonsOnRight), KConfigGroup::Notify); - config.sync(); - - m_savedSettings = m_currentSettings; + ManagedConfigModule::save(); // Send a signal to all kwin instances QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"), QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); QDBusConnection::sessionBus().send(message); - - updateNeedsSave(); } void KCMKWinDecoration::defaults() { - int themeIndex = m_proxyThemesModel->mapFromSource(m_themesModel->findDecoration(s_defaultPlugin, s_defaultTheme)).row(); - if (themeIndex < 0) { - qWarning() << "Default plugin" << s_defaultPlugin << "and theme" << s_defaultTheme << "not found"; - } - setTheme(themeIndex); - setBorderSize(s_defaultBorderSize); - setBorderSizeAuto(s_defaultBorderSizeAuto); - setCloseOnDoubleClickOnMenu(s_defaultCloseOnDoubleClickOnMenu); - setShowToolTips(s_defaultShowToolTips); + ManagedConfigModule::defaults(); - m_leftButtonsModel->replace(s_defaultDecoButtonsOnLeft); - m_rightButtonsModel->replace(s_defaultDecoButtonsOnRight); + setBorderSize(recommendedBorderSize()); - updateNeedsSave(); + m_leftButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnLeft())); + m_rightButtonsModel->replace(Utils::buttonsFromString(m_settings->buttonsOnRight())); } -void KCMKWinDecoration::updateNeedsSave() +void KCMKWinDecoration::onLeftButtonsChanged() { - m_currentSettings.buttonsOnLeft = m_leftButtonsModel->buttons(); - m_currentSettings.buttonsOnRight = m_rightButtonsModel->buttons(); + m_settings->setButtonsOnLeft(Utils::buttonsToString(m_leftButtonsModel->buttons())); +} - setNeedsSave(m_savedSettings.closeOnDoubleClickOnMenu != m_currentSettings.closeOnDoubleClickOnMenu - || m_savedSettings.showToolTips != m_currentSettings.showToolTips - || m_savedSettings.borderSize != m_currentSettings.borderSize - || m_savedSettings.borderSizeAuto != m_currentSettings.borderSizeAuto - || m_savedSettings.themeIndex != m_currentSettings.themeIndex - || m_savedSettings.buttonsOnLeft != m_currentSettings.buttonsOnLeft - || m_savedSettings.buttonsOnRight != m_currentSettings.buttonsOnRight); +void KCMKWinDecoration::onRightButtonsChanged() +{ + m_settings->setButtonsOnRight(Utils::buttonsToString(m_rightButtonsModel->buttons())); } QSortFilterProxyModel *KCMKWinDecoration::themesModel() const @@ -279,13 +210,13 @@ QStringList KCMKWinDecoration::borderSizesModel() const int KCMKWinDecoration::borderSize() const { - return Utils::getBorderSizeNames().keys().indexOf(m_currentSettings.borderSize); + return m_borderSizeIndex; } int KCMKWinDecoration::recommendedBorderSize() const { typedef KDecoration2::Configuration::DecorationsModel::DecorationRole DecoRole; - const QModelIndex proxyIndex = m_proxyThemesModel->index(m_currentSettings.themeIndex, 0); + const QModelIndex proxyIndex = m_proxyThemesModel->index(theme(), 0); if (proxyIndex.isValid()) { const QModelIndex index = m_proxyThemesModel->mapToSource(proxyIndex); if (index.isValid()) { @@ -296,80 +227,52 @@ int KCMKWinDecoration::recommendedBorderSize() const return Utils::getBorderSizeNames().keys().indexOf(s_defaultRecommendedBorderSize); } -bool KCMKWinDecoration::borderSizeAuto() const -{ - return m_currentSettings.borderSizeAuto; -} - int KCMKWinDecoration::theme() const { - return m_currentSettings.themeIndex; -} - -bool KCMKWinDecoration::closeOnDoubleClickOnMenu() const -{ - return m_currentSettings.closeOnDoubleClickOnMenu; -} - -bool KCMKWinDecoration::showToolTips() const -{ - return m_currentSettings.showToolTips; + return m_proxyThemesModel->mapFromSource(m_themesModel->findDecoration(m_settings->pluginName(), m_settings->theme())).row(); } void KCMKWinDecoration::setBorderSize(int index) { - setBorderSize(Utils::getBorderSizeNames().keys().at(index)); + if (m_borderSizeIndex != index) { + m_borderSizeIndex = index; + emit borderSizeChanged(); + } } void KCMKWinDecoration::setBorderSize(KDecoration2::BorderSize size) { - if (m_currentSettings.borderSize == size) { - return; - } - m_currentSettings.borderSize = size; - emit borderSizeChanged(); - updateNeedsSave(); -} - -void KCMKWinDecoration::setBorderSizeAuto(bool set) -{ - if (m_currentSettings.borderSizeAuto == set) { - return; - } - m_currentSettings.borderSizeAuto = set; - emit borderSizeAutoChanged(); - updateNeedsSave(); + m_settings->setBorderSize(Utils::borderSizeToString(size)); } void KCMKWinDecoration::setTheme(int index) { - // The initial themeIndex is set to -2 to always initially apply a theme, any theme - if (m_currentSettings.themeIndex == index) { - return; + QModelIndex dataIndex = m_proxyThemesModel->index(index, 0); + if (dataIndex.isValid()) { + m_settings->setTheme(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::ThemeNameRole).toString()); + m_settings->setPluginName(m_proxyThemesModel->data(dataIndex, KDecoration2::Configuration::DecorationsModel::PluginNameRole).toString()); + emit themeChanged(); } - m_currentSettings.themeIndex = index; - emit themeChanged(); - updateNeedsSave(); } -void KCMKWinDecoration::setCloseOnDoubleClickOnMenu(bool enable) +bool KCMKWinDecoration::isSaveNeeded() const { - if (m_currentSettings.closeOnDoubleClickOnMenu == enable) { - return; - } - m_currentSettings.closeOnDoubleClickOnMenu = enable; - emit closeOnDoubleClickOnMenuChanged(); - updateNeedsSave(); + return !m_settings->borderSizeAuto() && borderSizeIndexFromString(m_settings->borderSize()) != m_borderSizeIndex; } -void KCMKWinDecoration::setShowToolTips(bool show) +bool KCMKWinDecoration::isDefaults() const { - if (m_currentSettings.showToolTips == show) { - return; - } - m_currentSettings.showToolTips = show; - emit showToolTipsChanged(); - updateNeedsSave(); + return m_settings->borderSizeAuto() && recommendedBorderSize() == m_borderSizeIndex; +} + +int KCMKWinDecoration::borderSizeIndexFromString(const QString &size) const +{ + return Utils::getBorderSizeNames().keys().indexOf(Utils::stringToBorderSize(size)); +} + +QString KCMKWinDecoration::borderSizeIndexToString(int index) const +{ + return Utils::borderSizeToString(Utils::getBorderSizeNames().keys().at(index)); } #include "kcm.moc" diff --git a/kcmkwin/kwindecoration/kcm.h b/kcmkwin/kwindecoration/kcm.h index ba0534f783..75944695aa 100644 --- a/kcmkwin/kwindecoration/kcm.h +++ b/kcmkwin/kwindecoration/kcm.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2019 Valerio Pilo + * Copyright (c) 2019 Cyril Rossi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,7 +21,7 @@ #include "utils.h" -#include +#include class QAbstractItemModel; @@ -46,24 +47,25 @@ class DecorationsModel; } } -class KCMKWinDecoration : public KQuickAddons::ConfigModule +class KWinDecorationSettings; + +class KCMKWinDecoration : public KQuickAddons::ManagedConfigModule { Q_OBJECT + Q_PROPERTY(KWinDecorationSettings *settings READ settings CONSTANT) Q_PROPERTY(QSortFilterProxyModel *themesModel READ themesModel CONSTANT) Q_PROPERTY(QStringList borderSizesModel READ borderSizesModel CONSTANT) Q_PROPERTY(int borderSize READ borderSize WRITE setBorderSize NOTIFY borderSizeChanged) Q_PROPERTY(int recommendedBorderSize READ recommendedBorderSize CONSTANT) - Q_PROPERTY(bool borderSizeAuto READ borderSizeAuto WRITE setBorderSizeAuto NOTIFY borderSizeAutoChanged) Q_PROPERTY(int theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(QAbstractListModel *leftButtonsModel READ leftButtonsModel NOTIFY buttonsChanged) Q_PROPERTY(QAbstractListModel *rightButtonsModel READ rightButtonsModel NOTIFY buttonsChanged) Q_PROPERTY(QAbstractListModel *availableButtonsModel READ availableButtonsModel CONSTANT) - Q_PROPERTY(bool closeOnDoubleClickOnMenu READ closeOnDoubleClickOnMenu WRITE setCloseOnDoubleClickOnMenu NOTIFY closeOnDoubleClickOnMenuChanged) - Q_PROPERTY(bool showToolTips READ showToolTips WRITE setShowToolTips NOTIFY showToolTipsChanged) public: KCMKWinDecoration(QObject *parent, const QVariantList &arguments); + KWinDecorationSettings *settings() const; QSortFilterProxyModel *themesModel() const; QAbstractListModel *leftButtonsModel(); QAbstractListModel *rightButtonsModel(); @@ -71,17 +73,11 @@ public: QStringList borderSizesModel() const; int borderSize() const; int recommendedBorderSize() const; - bool borderSizeAuto() const; int theme() const; - bool closeOnDoubleClickOnMenu() const; - bool showToolTips() const; void setBorderSize(int index); void setBorderSize(KDecoration2::BorderSize size); - void setBorderSizeAuto(bool set); void setTheme(int index); - void setCloseOnDoubleClickOnMenu(bool enable); - void setShowToolTips(bool show); Q_INVOKABLE void getNewStuff(QQuickItem *context); @@ -89,9 +85,6 @@ Q_SIGNALS: void themeChanged(); void buttonsChanged(); void borderSizeChanged(); - void borderSizeAutoChanged(); - void closeOnDoubleClickOnMenuChanged(); - void showToolTipsChanged(); public Q_SLOTS: void load() override; @@ -99,10 +92,17 @@ public Q_SLOTS: void defaults() override; private Q_SLOTS: - void updateNeedsSave(); + void onLeftButtonsChanged(); + void onRightButtonsChanged(); void reloadKWinSettings(); private: + bool isSaveNeeded() const override; + bool isDefaults() const override; + + int borderSizeIndexFromString(const QString &size) const; + QString borderSizeIndexToString(int index) const; + KDecoration2::Configuration::DecorationsModel *m_themesModel; QSortFilterProxyModel *m_proxyThemesModel; @@ -112,17 +112,6 @@ private: QPointer m_newStuffDialog; - struct Settings - { - KDecoration2::BorderSize borderSize; - bool borderSizeAuto; - int themeIndex; - bool closeOnDoubleClickOnMenu; - bool showToolTips; - DecorationButtonsList buttonsOnLeft; - DecorationButtonsList buttonsOnRight; - }; - - Settings m_savedSettings; - Settings m_currentSettings; + int m_borderSizeIndex = -1; + KWinDecorationSettings *m_settings; }; diff --git a/kcmkwin/kwindecoration/kwindecorationsettings.kcfg b/kcmkwin/kwindecoration/kwindecorationsettings.kcfg new file mode 100644 index 0000000000..496cecf853 --- /dev/null +++ b/kcmkwin/kwindecoration/kwindecorationsettings.kcfg @@ -0,0 +1,53 @@ + + + + + + + #if HAVE_BREEZE_DECO + const QString s_defaultPlugin { QStringLiteral(BREEZE_KDECORATION_PLUGIN_ID) }; + #else + const QString s_defaultPlugin { QStringLiteral("org.kde.kwin.aurorae") }; + #endif + + s_defaultPlugin + + + + #if HAVE_BREEZE_DECO + const QString s_defaultTheme { QStringLiteral("Breeze") }; + #else + const QString s_defaultTheme { QStringLiteral("kwin4_decoration_qml_plastik") }; + #endif + + s_defaultTheme + + + + Normal + + + + true + + + + false + + + + true + + + + MS + + + + HIAX + + + diff --git a/kcmkwin/kwindecoration/kwindecorationsettings.kcfgc b/kcmkwin/kwindecoration/kwindecorationsettings.kcfgc new file mode 100644 index 0000000000..9d45368f47 --- /dev/null +++ b/kcmkwin/kwindecoration/kwindecorationsettings.kcfgc @@ -0,0 +1,6 @@ +File=kwindecorationsettings.kcfgc +ClassName=KWinDecorationSettings +Mutators=true +DefaultValueGetters=true +GenerateProperties=true +ParentInConstructor=true diff --git a/kcmkwin/kwindecoration/package/contents/ui/Buttons.qml b/kcmkwin/kwindecoration/package/contents/ui/Buttons.qml index f571a5841f..ee7e6e2419 100644 --- a/kcmkwin/kwindecoration/package/contents/ui/Buttons.qml +++ b/kcmkwin/kwindecoration/package/contents/ui/Buttons.qml @@ -31,6 +31,8 @@ ColumnLayout { Layout.fillHeight: true property int buttonIconSize: units.iconSizes.medium property int titleBarSpacing: units.smallSpacing * 2 + readonly property bool draggingTitlebarButtons: leftButtonsView.dragging || rightButtonsView.dragging + readonly property bool hideDragHint: draggingTitlebarButtons || availableButtonsGrid.dragging KDecoration.Bridge { id: bridgeItem @@ -122,12 +124,12 @@ ColumnLayout { } index = childIndex + 1 } - if (drop.keys.indexOf("decoButtonAdd") != -1) { + if (drop.keys.indexOf("decoButtonAdd") !== -1) { view.model.add(index, drag.source.type); - } else if (drop.keys.indexOf("decoButtonLeft") != -1) { - if (view == leftButtonsView) { + } else if (drop.keys.indexOf("decoButtonLeft") !== -1) { + if (view === leftButtonsView) { // move in same view - if (index != drag.source.itemIndex) { + if (index !== drag.source.itemIndex) { drag.source.buttonsModel.move(drag.source.itemIndex, index); } } else { @@ -135,10 +137,10 @@ ColumnLayout { view.model.add(index, drag.source.type); drag.source.buttonsModel.remove(drag.source.itemIndex); } - } else if (drop.keys.indexOf("decoButtonRight") != -1) { - if (view == rightButtonsView) { + } else if (drop.keys.indexOf("decoButtonRight") !== -1) { + if (view === rightButtonsView) { // move in same view - if (index != drag.source.itemIndex) { + if (index !== drag.source.itemIndex) { drag.source.buttonsModel.move(drag.source.itemIndex, index); } } else { @@ -152,6 +154,7 @@ ColumnLayout { } GridView { id: availableButtonsGrid + property bool dragging: false Layout.fillWidth: true Layout.minimumHeight: availableButtonsGrid.cellHeight * 2 Layout.margins: units.largeSpacing @@ -162,7 +165,7 @@ ColumnLayout { Layout.margins: units.largeSpacing width: availableButtonsGrid.cellWidth height: availableButtonsGrid.cellHeight - opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 0.15 : 1.0 + opacity: draggingTitlebarButtons ? 0.15 : 1.0 Rectangle { id: availableButtonFrame anchors.horizontalCenter: parent.horizontalCenter @@ -181,6 +184,7 @@ ColumnLayout { height: buttonIconSize Drag.keys: [ "decoButtonAdd" ] Drag.active: dragArea.drag.active + Drag.onActiveChanged: availableButtonsGrid.dragging = Drag.active color: palette.windowText } MouseArea { @@ -225,14 +229,15 @@ ColumnLayout { font.weight: Font.Bold level: 2 anchors.centerIn: parent - opacity: (leftButtonsView.dragging || rightButtonsView.dragging) ? 1.0 : 0.0 + opacity: draggingTitlebarButtons ? 1.0 : 0.0 } } } Text { id: dragHint + readonly property real dragHintOpacitiy: enabled ? 1.0 : 0.3 color: palette.windowText - opacity: (leftButtonsView.dragging || rightButtonsView.dragging || availableButtonsGrid.dragging) ? 0.0 : 1.0 + opacity: hideDragHint ? 0.0 : dragHintOpacitiy Layout.fillWidth: true Layout.topMargin: titleBarSpacing Layout.bottomMargin: titleBarSpacing diff --git a/kcmkwin/kwindecoration/package/contents/ui/Themes.qml b/kcmkwin/kwindecoration/package/contents/ui/Themes.qml index e9b27ca4d9..28e5899db2 100644 --- a/kcmkwin/kwindecoration/package/contents/ui/Themes.qml +++ b/kcmkwin/kwindecoration/package/contents/ui/Themes.qml @@ -35,7 +35,6 @@ KCM.GridView { view.model: kcm.themesModel view.currentIndex: kcm.theme - view.onCurrentIndexChanged: kcm.theme = view.currentIndex view.onContentHeightChanged: view.positionViewAtIndex(view.currentIndex, GridView.Visible) view.implicitCellWidth: Kirigami.Units.gridUnit * 18 @@ -84,7 +83,10 @@ KCM.GridView { } MouseArea { anchors.fill: parent - onClicked: view.currentIndex = index + onClicked: { + kcm.theme = index + view.currentIndex = index + } } Connections { target: kcm @@ -97,13 +99,17 @@ KCM.GridView { tooltip: i18n("Edit %1 Theme", model.display) enabled: model.configureable onTriggered: { + kcm.theme = index view.currentIndex = index bridgeItem.bridge.configure() } } ] - onClicked: view.currentIndex = index + onClicked: { + kcm.theme = index + view.currentIndex = index + } } Connections { target: kcm diff --git a/kcmkwin/kwindecoration/package/contents/ui/main.qml b/kcmkwin/kwindecoration/package/contents/ui/main.qml index 403db2ab8f..677bcd5f66 100644 --- a/kcmkwin/kwindecoration/package/contents/ui/main.qml +++ b/kcmkwin/kwindecoration/package/contents/ui/main.qml @@ -25,7 +25,6 @@ import org.kde.kirigami 2.4 as Kirigami Kirigami.Page { KCM.ConfigModule.quickHelp: i18n("This module lets you configure the window decorations.") - KCM.ConfigModule.buttons: KCM.ConfigModule.Help | KCM.ConfigModule.Default | KCM.ConfigModule.Apply title: kcm.name SystemPalette { @@ -79,6 +78,7 @@ Kirigami.Page { Themes { Layout.fillWidth: true Layout.fillHeight: true + enabled: !kcm.settings.isImmutable("pluginName") && !kcm.settings.isImmutable("theme") } RowLayout { @@ -88,24 +88,24 @@ Kirigami.Page { Layout.fillWidth: true Layout.maximumWidth: implicitWidth text: i18nc("checkbox label", "Use theme's default window border size") - checked: kcm.borderSizeAuto - onCheckedChanged: { - kcm.borderSizeAuto = checked; + enabled: !kcm.settings.isImmutable("borderSizeAuto") + checked: kcm.settings.borderSizeAuto + onToggled: { + kcm.settings.borderSizeAuto = checked; borderSizeComboBox.autoBorderUpdate() } } Controls.ComboBox { id: borderSizeComboBox - enabled: !borderSizeAutoCheckbox.checked + enabled: !borderSizeAutoCheckbox.checked && !kcm.settings.isImmutable("borderSize") model: kcm.borderSizesModel + currentIndex: kcm.borderSize onActivated: { kcm.borderSize = currentIndex } function autoBorderUpdate() { if (borderSizeAutoCheckbox.checked) { - currentIndex = kcm.recommendedBorderSize - } else { - currentIndex = kcm.borderSize + kcm.borderSize = kcm.recommendedBorderSize } } @@ -130,14 +130,16 @@ Kirigami.Page { Buttons { Layout.fillWidth: true Layout.fillHeight: true + enabled: !kcm.settings.isImmutable("buttonsOnLeft") && !kcm.settings.isImmutable("buttonsOnRight") } Controls.CheckBox { id: closeOnDoubleClickOnMenuCheckBox text: i18nc("checkbox label", "Close windows by double clicking the menu button") - checked: kcm.closeOnDoubleClickOnMenu + enabled: !kcm.settings.isImmutable("closeOnDoubleClickOnMenu") + checked: kcm.settings.closeOnDoubleClickOnMenu onToggled: { - kcm.closeOnDoubleClickOnMenu = checked + kcm.settings.closeOnDoubleClickOnMenu = checked infoLabel.visible = checked } } @@ -154,8 +156,9 @@ Kirigami.Page { Controls.CheckBox { id: showToolTipsCheckBox text: i18nc("checkbox label", "Show titlebar button tooltips") - checked: kcm.showToolTips - onToggled: kcm.showToolTips = checked + enabled: !kcm.settings.isImmutable("showToolTips") + checked: kcm.settings.showToolTips + onToggled: kcm.settings.showToolTips = checked } } } diff --git a/kcmkwin/kwindecoration/utils.cpp b/kcmkwin/kwindecoration/utils.cpp index b26b698bf8..2f8c45bb4b 100644 --- a/kcmkwin/kwindecoration/utils.cpp +++ b/kcmkwin/kwindecoration/utils.cpp @@ -80,19 +80,21 @@ QString buttonsToString(const DecorationButtonsList &buttons) return ret; } -DecorationButtonsList readDecorationButtons(const KConfigGroup &config, const QString &key, const DecorationButtonsList &defaultValue) +DecorationButtonsList buttonsFromString(const QString &buttons) { - auto buttonsFromString = [](const QString &buttons) -> DecorationButtonsList { - DecorationButtonsList ret; - for (auto it = buttons.begin(); it != buttons.end(); ++it) { - for (auto it2 = s_buttonNames.constBegin(); it2 != s_buttonNames.constEnd(); ++it2) { - if (it2.value() == (*it)) { - ret << it2.key(); - } + DecorationButtonsList ret; + for (auto it = buttons.begin(); it != buttons.end(); ++it) { + for (auto it2 = s_buttonNames.constBegin(); it2 != s_buttonNames.constEnd(); ++it2) { + if (it2.value() == (*it)) { + ret << it2.key(); } } - return ret; - }; + } + return ret; +} + +DecorationButtonsList readDecorationButtons(const KConfigGroup &config, const QString &key, const DecorationButtonsList &defaultValue) +{ return buttonsFromString(config.readEntry(key, buttonsToString(defaultValue))); } diff --git a/kcmkwin/kwindecoration/utils.h b/kcmkwin/kwindecoration/utils.h index 1df5b3efb1..3a54196ab4 100644 --- a/kcmkwin/kwindecoration/utils.h +++ b/kcmkwin/kwindecoration/utils.h @@ -30,6 +30,7 @@ namespace Utils { QString buttonsToString(const DecorationButtonsList &buttons); +DecorationButtonsList buttonsFromString(const QString &buttons); DecorationButtonsList readDecorationButtons(const KConfigGroup &config, const QString &key, const DecorationButtonsList &defaultValue); KDecoration2::BorderSize stringToBorderSize(const QString &name);