Files
chandra/docs/dark-mode.md
T
Claude 5403777451
CI / test (push) Successful in 2m10s
Session: replace a Qt platform theme whose plugin isn't installed
QT_QPA_PLATFORMTHEME=gnome left in the environment without QGnomePlatform
made Qt load no platform theme, so KF6 apps got a light Breeze palette
while the Breeze style and Dolphin's view read the dark kdeglobals colors:
Dolphin's rows alternated near-black (with dark text) and light.
chandra-session now keeps a preset theme only if its plugin exists for Qt 6
or 5, else picks kde / xdgdesktopportal as before. Reproduced and checked
with Dolphin 26.08 / Qt 6.11 / KF 6.32 headless.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hivwxSsQ56aGGv4cFQ
2026-11-26 01:43:02 +00:00

5.5 KiB

Dark mode for apps

The Settings module's Dark mode switch restyles Chandra itself and, in the login session (chandra-session, --drm), tells apps:

  • xdg-desktop-portal Settings (Chrome/Chromium, Electron, Firefox, GTK 4 / libadwaita, Qt 6.5+): the compositor is a portal backend itself (compositor/portal). It owns org.freedesktop.impl.portal.desktop.chandra on the session bus and answers org.freedesktop.appearance color-scheme (1 dark, 2 light), emitting SettingChanged when the 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.
  • 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) to a theme whose plugin is installed (a leftover gnome without QGnomePlatform is replaced: Qt then loads no theme, and Dolphin mixes a light palette with dark kdeglobals rows): 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

xdg-desktop-portal chooses backends from $XDG_CURRENT_DESKTOP-portals.conf, then the backends' UseIn= keys. The session sets XDG_CURRENT_DESKTOP=chandra and there was no chandra-portals.conf; GTK's and GNOME's backends say UseIn=gnome, KDE's UseIn=KDE. So xdg-desktop-portal (1.18, as in Ubuntu 24.04) exported no Settings interface at all, and Chrome, which asks the portal, never saw the preference that gsettings held.

Checking it on your machine

After reinstalling (just install) and logging in to Chandra again:

# 1 = dark, 2 = light; flip the switch and run it again
gdbus call --session -d org.freedesktop.portal.Desktop -o /org/freedesktop/portal/desktop \
  -m org.freedesktop.portal.Settings.ReadOne org.freedesktop.appearance color-scheme
# the backend itself
busctl --user status org.freedesktop.impl.portal.desktop.chandra
  • xdg-desktop-portal must be installed (xdg-desktop-portal package). It reads its config only when it starts: chandra-session restarts it at login, or run 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:

    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).