mirror of https://gitee.com/openkylin/kwin.git
decoration: ukui title font dynamic update
This commit is contained in:
parent
239e307271
commit
df074a9056
|
@ -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"
|
||||
|
|
|
@ -224,6 +224,8 @@ target_link_libraries(kwin
|
|||
epoxy::epoxy
|
||||
|
||||
Threads::Threads
|
||||
|
||||
${Qsettings_LIBRARIES}
|
||||
)
|
||||
|
||||
add_subdirectory(backends)
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
#include <QPainter>
|
||||
#include <QScreen>
|
||||
#include <QtDBus>
|
||||
#include <QGSettings>
|
||||
#include <QFontDatabase>
|
||||
|
||||
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<KDecoration2::Decoration>(client, QVariantList({args}));
|
||||
deco->setSettings(m_settings);
|
||||
deco->init();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue