From df074a9056bd426fd626c619e23bc5620a30c971 Mon Sep 17 00:00:00 2001 From: Hongfei Shang Date: Sun, 19 Jun 2022 05:05:38 +0800 Subject: [PATCH] decoration: ukui title font dynamic update --- CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 2 ++ src/decorations/decorationbridge.cpp | 26 ++++++++++++++++++++++++++ src/decorations/decorationbridge.h | 6 ++++++ src/decorations/settings.cpp | 9 +++++++++ src/decorations/settings.h | 3 +++ 6 files changed, 50 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d8bc972d..d3ec2997c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,10 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS X11Extras ) +find_package(PkgConfig) +pkg_check_modules(Qsettings REQUIRED gsettings-qt) +include_directories(${Qsettings_INCLUDE_DIRS}) + find_package(Qt5Test ${QT_MIN_VERSION} CONFIG QUIET) set_package_properties(Qt5Test PROPERTIES PURPOSE "Required for tests" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2cdd67bc2..1ade3cbbc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -224,6 +224,8 @@ target_link_libraries(kwin epoxy::epoxy Threads::Threads + + ${Qsettings_LIBRARIES} ) add_subdirectory(backends) diff --git a/src/decorations/decorationbridge.cpp b/src/decorations/decorationbridge.cpp index 4139a09b7..cdd61aec7 100644 --- a/src/decorations/decorationbridge.cpp +++ b/src/decorations/decorationbridge.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include namespace KWin { @@ -153,11 +155,22 @@ void DecorationBridge::init() { m_themeId = 0; } + + const QFont font = QFontDatabase::systemFont(QFontDatabase::TitleFont); + m_nFont = font.pointSize(); + m_strFontFamily = font.family(); + QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), QStringLiteral("slotThemeChange"), this, SLOT(slotThemeUpdate(int))); + + QDBusConnection::sessionBus().connect(QString(), + QStringLiteral("/KGlobalSettings"), + QStringLiteral("org.kde.KGlobalSettings"), + QStringLiteral("slotFontChange"), + this, SLOT(fontUpdate(int, QString))); } void DecorationBridge::slotThemeUpdate(int themeId) @@ -165,6 +178,17 @@ void DecorationBridge::slotThemeUpdate(int themeId) m_themeId = themeId; } +void DecorationBridge::fontUpdate(int nfont, QString strFamily) +{ + m_nFont = nfont; + m_strFontFamily = strFamily; + QFont font; + font.setPointSize(nfont); + font.setFamily(strFamily); + + Q_EMIT sig_updateFont(font); +} + void DecorationBridge::initPlugin() { const KPluginMetaData metaData = KPluginMetaData::findPluginById(s_pluginName, m_plugin); @@ -300,6 +324,8 @@ KDecoration2::Decoration *DecorationBridge::createDecoration(AbstractClient *cli } args.insert(QStringLiteral("dpi"), m_dpi); //每创建一个渲染端,就把dpi值带过去,后面每新建一个客户就不需要反复获取获取dpi值 args.insert(QStringLiteral("themeId"), m_themeId); //针对UKUI定制的主题id + args.insert(QStringLiteral("systemFontSize"), m_nFont); //标题栏字体大小 + args.insert(QStringLiteral("systemFont"), m_strFontFamily); //标题栏字体类型 auto deco = m_factory->create(client, QVariantList({args})); deco->setSettings(m_settings); deco->init(); diff --git a/src/decorations/decorationbridge.h b/src/decorations/decorationbridge.h index c71da0e84..9d1b54bca 100644 --- a/src/decorations/decorationbridge.h +++ b/src/decorations/decorationbridge.h @@ -66,8 +66,11 @@ public: Q_SIGNALS: void metaDataLoaded(); + void sig_updateFont(QFont); + public Q_SLOTS: void slotThemeUpdate(int); + void fontUpdate(int nfont, QString strFamily); private: QString readPlugin(); @@ -88,6 +91,9 @@ private: int m_dpi; //dpi值 int m_themeId; //主题id + int m_nFont; + QString m_strFontFamily; + KWIN_SINGLETON(DecorationBridge) }; } // Decoration diff --git a/src/decorations/settings.cpp b/src/decorations/settings.cpp index e493da6bc..0fe0f51a2 100644 --- a/src/decorations/settings.cpp +++ b/src/decorations/settings.cpp @@ -49,6 +49,7 @@ SettingsImpl::SettingsImpl(KDecoration2::DecorationSettings *parent) ); connect(Workspace::self(), &Workspace::configChanged, this, &SettingsImpl::readSettings); connect(DecorationBridge::self(), &DecorationBridge::metaDataLoaded, this, &SettingsImpl::readSettings); + connect(DecorationBridge::self(), &DecorationBridge::sig_updateFont, this, &SettingsImpl::updateFont); } SettingsImpl::~SettingsImpl() = default; @@ -142,6 +143,14 @@ static KDecoration2::BorderSize stringToSize(const QString &name) return it.value(); } +void SettingsImpl::updateFont(QFont font) +{ + if (font != m_font) { + m_font = font; + Q_EMIT decorationSettings()->fontChanged(m_font); + } +} + void SettingsImpl::readSettings() { KConfigGroup config = kwinApp()->config()->group(QStringLiteral("org.kde.kdecoration2")); diff --git a/src/decorations/settings.h b/src/decorations/settings.h index 250447f05..d12b79971 100644 --- a/src/decorations/settings.h +++ b/src/decorations/settings.h @@ -42,6 +42,9 @@ public: return m_font; } +public Q_SLOTS: + void updateFont(QFont font); + private: void readSettings(); QVector< KDecoration2::DecorationButtonType > readDecorationButtons(const KConfigGroup &config,