diff --git a/kcms/fonts/CMakeLists.txt b/kcms/fonts/CMakeLists.txt index b3b4c043e..ef512fd37 100644 --- a/kcms/fonts/CMakeLists.txt +++ b/kcms/fonts/CMakeLists.txt @@ -9,6 +9,7 @@ set(kcm_fonts_PART_SRCS fonts.cpp fontsaasettings.cpp kxftconfig.cpp + fontinit.cpp ../kfontinst/lib/FcEngine.cpp ../kcms-common.cpp ) diff --git a/kcms/fonts/fontinit.cpp b/kcms/fonts/fontinit.cpp new file mode 100644 index 000000000..d1c65d9e1 --- /dev/null +++ b/kcms/fonts/fontinit.cpp @@ -0,0 +1,34 @@ +/* + This file is part of the KDE project. + + SPDX-FileCopyrightText: 2021 David Edmundson + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include +#include +#include +#include + +extern "C" { +Q_DECL_EXPORT void kcminit_fonts() +{ + KConfig cfg(QStringLiteral("kcmfonts")); + KConfigGroup fontsCfg(&cfg, "General"); + + QString fontDpiKey = KWindowSystem::isPlatformWayland() ? QStringLiteral("forceFontDPIWayland") : QStringLiteral("forceFontDPI"); + + if (!fontsCfg.hasKey(fontDpiKey)) { + return; + } + + const QByteArray input = "Xft.dpi: " + QByteArray::number(fontsCfg.readEntry(fontDpiKey, 0)); + QProcess p; + p.start(QStringLiteral("xrdb"), {QStringLiteral("-quiet"), QStringLiteral("-merge"), QStringLiteral("-nocpp")}); + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.write(input); + p.closeWriteChannel(); + p.waitForFinished(-1); +} +} diff --git a/kcms/fonts/kcm_fonts.desktop b/kcms/fonts/kcm_fonts.desktop index f1050b627..b9e735ca1 100644 --- a/kcms/fonts/kcm_fonts.desktop +++ b/kcms/fonts/kcm_fonts.desktop @@ -1,7 +1,7 @@ [Desktop Entry] Icon=preferences-desktop-font Type=Service -X-KDE-ServiceTypes=KCModule +X-KDE-ServiceTypes=KCModule,KCModuleInit X-DocPath=kcontrol/fonts/index.html X-KDE-Library=kcm_fonts @@ -10,6 +10,9 @@ X-KDE-ParentApp=kcontrol X-KDE-System-Settings-Parent-Category=appearance X-KDE-Weight=50 +X-KDE-Init-Symbol=kcminit_fonts +X-KDE-Init-Phase=0 + Name=Fonts Name[ar]=الخطوط Name[az]=Şriftlər diff --git a/startkde/startplasma-waylandsession.cpp b/startkde/startplasma-waylandsession.cpp index 3a054a04f..7f916e409 100644 --- a/startkde/startplasma-waylandsession.cpp +++ b/startkde/startplasma-waylandsession.cpp @@ -10,7 +10,6 @@ int main(int argc, char **argv) { QCoreApplication app(argc, argv); - setupFontDpi(); QScopedPointer ksplash; if (!qEnvironmentVariableIsSet("KWIN_RESTART_COUNT")) { diff --git a/startkde/startplasma-x11.cpp b/startkde/startplasma-x11.cpp index d6b2c5439..817de3511 100644 --- a/startkde/startplasma-x11.cpp +++ b/startkde/startplasma-x11.cpp @@ -58,7 +58,6 @@ int main(int argc, char **argv) } setupCursor(false); - setupFontDpi(); QScopedPointer ksplash(setupKSplash()); runEnvironmentScripts(); diff --git a/startkde/startplasma.cpp b/startkde/startplasma.cpp index 008fdfcaf..a17967b47 100644 --- a/startkde/startplasma.cpp +++ b/startkde/startplasma.cpp @@ -391,25 +391,6 @@ bool syncDBusEnvironment() return job->exec(); } -void setupFontDpi() -{ - KConfig cfg(QStringLiteral("kcmfonts")); - KConfigGroup fontsCfg(&cfg, "General"); - - if (!fontsCfg.hasKey("forceFontDPI")) { - return; - } - - // TODO port to c++? - const QByteArray input = "Xft.dpi: " + QByteArray::number(fontsCfg.readEntry("forceFontDPI", 0)); - QProcess p; - p.start(QStringLiteral("xrdb"), {QStringLiteral("-quiet"), QStringLiteral("-merge"), QStringLiteral("-nocpp")}); - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.write(input); - p.closeWriteChannel(); - p.waitForFinished(-1); -} - static bool desktopLockedAtStart = false; QProcess *setupKSplash()