Dark mode for KDE/Qt apps: write kdeglobals colors and set QT_QPA_PLATFORMTHEME
CI / test (push) Failing after 17s
CI / test (push) Failing after 17s
KWrite stayed light with the Dark mode switch on. KDE apps read their colors from the [Colors:*] groups of kdeglobals, not from the scheme's name, and the switch only set [General] ColorScheme with kwriteconfig. Qt 6 apps also had no platform theme under XDG_CURRENT_DESKTOP=chandra, so Qt reported an unknown (light) color scheme whatever the portal said, and KDE Frameworks 6 apps picked Breeze Light. - session/chandra-kde-colors dark|light copies the scheme's color groups into kdeglobals (counterpart of the current scheme, else Breeze, else Chandra's own ChandraDark/ChandraLight) and emits KGlobalSettings.notifyChange so running apps repaint. The compositor calls it from the switch. - chandra-session sets QT_QPA_PLATFORMTHEME to kde (plasma-integration) or xdgdesktopportal when unset, and passes it to the activation environment. - install.py installs the script and the two color schemes. - scripts/test-kde-colors.sh tests the rewriting, and that a running KWrite turns dark live; docs/dark-mode.md explains it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjmk6mgq6Gg5vgKfMp
This commit is contained in:
8 files changed
+523
-12
No files matched your search
+52
-2
@@ -10,8 +10,45 @@ The Settings module's **Dark mode** switch restyles Chandra itself and, in the l
|
||||
switch flips, so open apps follow live.
|
||||
`session/chandra.portal` and `session/chandra-portals.conf` (installed to
|
||||
`/usr/share/xdg-desktop-portal/` by `session/install.py`) point xdg-desktop-portal at it.
|
||||
- gsettings `color-scheme` / `gtk-theme`, GTK 3/4 `settings.ini`, KDE color scheme and qt5ct/qt6ct
|
||||
(`compositor/host/system_theme.mbt`), for apps that read those instead.
|
||||
- **KDE / Qt apps** (KWrite, Kate, Dolphin, Okular): `chandra-kde-colors dark|light` (from
|
||||
`compositor/host/system_theme.mbt`) copies a dark or light color scheme's `[Colors:*]` groups
|
||||
into `~/.config/kdeglobals` and sends `org.kde.KGlobalSettings.notifyChange`, so open apps
|
||||
repaint. `chandra-session` sets `QT_QPA_PLATFORMTHEME` (see below).
|
||||
- gsettings `color-scheme` / `gtk-theme`, GTK 3/4 `settings.ini` and qt5ct/qt6ct, for apps that
|
||||
read those instead.
|
||||
|
||||
## Why KWrite stayed light
|
||||
|
||||
Two things, depending on the KDE Frameworks version:
|
||||
|
||||
- KDE apps don't load a color scheme by its name. `KColorScheme` reads the colors themselves from
|
||||
the `[Colors:Window]`, `[Colors:View]`, ... groups of `kdeglobals`, which Plasma's System Settings
|
||||
(or `plasma-apply-colorscheme`) copies in from the scheme's `.colors` file. Chandra only set
|
||||
`[General] ColorScheme=BreezeDark` with kwriteconfig, so the groups stayed light, or missing (then
|
||||
apps use their built-in light colors). Reproduced in the cloud with KWrite 23.08: light with only
|
||||
the name, dark once the groups are there.
|
||||
- Qt 6 / KDE Frameworks 6 apps outside Plasma pick Breeze Dark or Breeze Light from Qt's
|
||||
`styleHints()->colorScheme()`. Qt only knows that from a platform theme, and with
|
||||
`XDG_CURRENT_DESKTOP=chandra` and `QT_QPA_PLATFORMTHEME` unset it loads none of them, so the
|
||||
answer was always "unknown" (light), whatever the portal said. Checked with Qt 6.12: unset gives
|
||||
`Unknown`, `xdgdesktopportal` gives `Dark` and follows the switch live.
|
||||
|
||||
So now:
|
||||
|
||||
- `chandra-kde-colors` writes the full color groups. The scheme is the dark/light counterpart of
|
||||
the current one when it exists (`FooLight` <-> `FooDark`), else Breeze Dark / Breeze Light, else
|
||||
Chandra's own `ChandraDark` / `ChandraLight` (`session/color-schemes`, installed to
|
||||
`/usr/local/share/color-schemes`, from the Moon Night / Moon Day palettes). Other kdeglobals
|
||||
settings (fonts, icons) are kept.
|
||||
- `chandra-session` sets `QT_QPA_PLATFORMTHEME`, unless you set it yourself (qt6ct, say): `kde`
|
||||
when KDE's platform theme is installed (package `plasma-integration`; it reads kdeglobals and
|
||||
repaints live when the switch flips), else `xdgdesktopportal` (Qt 6.5+ follows the portal's
|
||||
color-scheme; KDE Frameworks 6 apps then load Breeze Dark/Light, which need the `breeze` color
|
||||
schemes installed). It also passes it to D-Bus/systemd-activated apps.
|
||||
|
||||
Best results: install `plasma-integration` (it brings the Breeze style and color schemes). Without
|
||||
it, Qt 5 / KDE Frameworks 5 apps still come up in the right colors but only pick up a flip when
|
||||
restarted.
|
||||
|
||||
## Why Chrome ignored the switch before
|
||||
|
||||
@@ -38,5 +75,18 @@ busctl --user status org.freedesktop.impl.portal.desktop.chandra
|
||||
`systemctl --user restart xdg-desktop-portal`.
|
||||
- In Chrome, Settings > Appearance > Mode must be **Device** (a fixed Light or Dark there wins).
|
||||
Pages follow through `prefers-color-scheme`; Chrome's own UI follows too.
|
||||
- KDE / Qt apps:
|
||||
|
||||
```sh
|
||||
echo $QT_QPA_PLATFORMTHEME # kde or xdgdesktopportal
|
||||
head -n 20 ~/.config/kdeglobals # [General] ColorScheme=..., then [Colors:*] groups
|
||||
chandra-kde-colors dark # by hand: prints the scheme it applied
|
||||
ls /usr/share/color-schemes # BreezeDark.colors etc. (package breeze / plasma-integration)
|
||||
kwrite --version
|
||||
```
|
||||
|
||||
Apps started before you logged in again keep the old `QT_QPA_PLATFORMTHEME`; restart them.
|
||||
- `scripts/test-kde-colors.sh` checks the kdeglobals rewriting and, with `kwrite`,
|
||||
`plasma-integration`, `xvfb` and ImageMagick installed, that a running KWrite turns dark.
|
||||
- `scripts/test-portal-dbus.sh` runs the backend behind the real xdg-desktop-portal on a private
|
||||
bus (what CI-less checks can do without a desktop).
|
||||
Reference in new issue
Block a user