From d53fd656e8e91835fbb4b5e37e32bb32dfd6e445 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 18 Aug 2021 16:25:23 +0100 Subject: [PATCH] Move font DPI syncing to kcminit StartPlasma's fontDPI syncs the current font DPI to xrdb, which affects font DPI for X applications (inc apps run in xwayland) This is seldom used on wayland as with framebuffer scaling you don't want to adjust your font DPI, but it is used by some users. As it's xrdb, it needs to come after Xwayland is started for the wayland case. The goal of this patch is to move towards killing the startplasma-waylandsession binary as well as just being better design to have these things comparmentalised. kcminit is very early in the boot process before all GUI apps with the exception of ksplash. I don't think this will make a big difference as that's just a picture anyway? --- kcms/fonts/CMakeLists.txt | 1 + kcms/fonts/fontinit.cpp | 34 +++++++++++++++++++++++++ kcms/fonts/kcm_fonts.desktop | 5 +++- startkde/startplasma-waylandsession.cpp | 1 - startkde/startplasma-x11.cpp | 1 - startkde/startplasma.cpp | 19 -------------- 6 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 kcms/fonts/fontinit.cpp 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()