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
Executable
+100
@@ -0,0 +1,100 @@
|
||||
#!/bin/sh
|
||||
# chandra-kde-colors dark|light
|
||||
#
|
||||
# Point KDE / Qt apps at a dark or light color scheme: called by the compositor when the Settings
|
||||
# Dark mode switch flips (compositor/host/system_theme.mbt), in the login session only.
|
||||
#
|
||||
# KDE apps (KWrite, Kate, Dolphin, Okular...) don't read a scheme by its name: KColorScheme reads
|
||||
# the [Colors:*] groups of ~/.config/kdeglobals, which Plasma's tools copy in from the scheme's
|
||||
# .colors file. Setting only [General] ColorScheme=BreezeDark (what kwriteconfig did here before)
|
||||
# leaves those groups as they were, or missing, and apps fall back to their built-in light
|
||||
# colors. So this copies the scheme's color groups into kdeglobals itself, which needs neither
|
||||
# Plasma, kded nor plasma-apply-colorscheme, then tells running apps (the KDE platform theme,
|
||||
# QT_QPA_PLATFORMTHEME=kde) to repaint.
|
||||
#
|
||||
# The scheme: the dark/light counterpart of the current one when it has one (FooLight <->
|
||||
# FooDark), else BreezeDark/BreezeLight, else Chandra's own ChandraDark/ChandraLight
|
||||
# (session/color-schemes, installed to /usr/local/share/color-schemes).
|
||||
set -u
|
||||
case "${1:-}" in
|
||||
dark) from=light to=dark defaults="BreezeDark ChandraDark" ;;
|
||||
light) from=dark to=light defaults="BreezeLight ChandraLight" ;;
|
||||
*) echo "usage: chandra-kde-colors dark|light" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
cfg="${XDG_CONFIG_HOME:-$HOME/.config}"
|
||||
kg="$cfg/kdeglobals"
|
||||
dirs="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
|
||||
scheme_file() { # NAME -> path of NAME.colors in the data dirs, if any
|
||||
old_ifs=$IFS; IFS=:
|
||||
for d in $dirs; do
|
||||
if [ -n "$d" ] && [ -f "$d/color-schemes/$1.colors" ]; then
|
||||
IFS=$old_ifs; printf '%s\n' "$d/color-schemes/$1.colors"; return 0
|
||||
fi
|
||||
done
|
||||
IFS=$old_ifs; return 1
|
||||
}
|
||||
|
||||
current=""
|
||||
[ -f "$kg" ] && current=$(sed -n '/^\[General\]/,/^\[/s/^ColorScheme=//p' "$kg" | head -n 1)
|
||||
name="" file=""
|
||||
if [ -n "$current" ]; then
|
||||
# Keep the case: MyLight -> MyDark, my-light -> my-dark, MYLIGHT -> MYDARK.
|
||||
F=$(printf '%s' "$from" | sed 's/^./\U&/') T=$(printf '%s' "$to" | sed 's/^./\U&/')
|
||||
UF=$(printf '%s' "$from" | tr a-z A-Z) UT=$(printf '%s' "$to" | tr a-z A-Z)
|
||||
other=$(printf '%s' "$current" | sed "s/$F/$T/;t;s/$from/$to/;t;s/$UF/$UT/")
|
||||
if [ "$other" != "$current" ] && file=$(scheme_file "$other"); then name=$other; fi
|
||||
fi
|
||||
if [ -z "$name" ]; then
|
||||
for n in $defaults; do
|
||||
if file=$(scheme_file "$n"); then name=$n; break; fi
|
||||
done
|
||||
fi
|
||||
if [ -z "$name" ]; then
|
||||
echo "chandra-kde-colors: no $to color scheme found in $dirs" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$cfg" || exit 1
|
||||
[ -f "$kg" ] || : >"$kg"
|
||||
# kdeglobals without its color groups (and with ColorScheme=NAME in [General]), then the
|
||||
# scheme's color groups.
|
||||
awk -v name="$name" -v kg="$kg" '
|
||||
function colors(g) { return g ~ /^\[(Colors:|ColorEffects:|WM\])/ }
|
||||
FILENAME == kg {
|
||||
if ($0 ~ /^\[/) {
|
||||
group = $0
|
||||
if (group == "[General]") { general = 1 }
|
||||
skip = colors(group)
|
||||
}
|
||||
if (skip) next
|
||||
if (group == "[General]" && $0 ~ /^ColorScheme=/) next
|
||||
print
|
||||
if ($0 == "[General]") print "ColorScheme=" name
|
||||
next
|
||||
}
|
||||
FNR == 1 {
|
||||
if (!general) { print ""; print "[General]"; print "ColorScheme=" name }
|
||||
print ""
|
||||
}
|
||||
/^\[/ { group = $0; keep = colors(group) }
|
||||
keep { print }
|
||||
' "$kg" "$file" >"$kg.chandra-new" && mv "$kg.chandra-new" "$kg" || exit 1
|
||||
|
||||
# Running apps: the KDE platform theme reloads its palette on KGlobalSettings.notifyChange
|
||||
# (0 = PaletteChanged); KConfigWatcher users listen for kconfig ConfigChanged.
|
||||
if command -v dbus-send >/dev/null 2>&1; then
|
||||
dbus-send --session --type=signal /KGlobalSettings org.kde.KGlobalSettings.notifyChange \
|
||||
int32:0 int32:0 2>/dev/null
|
||||
elif command -v gdbus >/dev/null 2>&1; then
|
||||
gdbus emit --session --object-path /KGlobalSettings \
|
||||
--signal org.kde.KGlobalSettings.notifyChange 0 0 >/dev/null 2>&1
|
||||
fi
|
||||
if command -v gdbus >/dev/null 2>&1; then
|
||||
gdbus emit --session --object-path /kdeglobals --signal org.kde.kconfig.notify.ConfigChanged \
|
||||
"{'General': [b'ColorScheme'], 'Colors:Window': [b'BackgroundNormal'], 'Colors:View': [b'BackgroundNormal']}" \
|
||||
>/dev/null 2>&1
|
||||
fi
|
||||
printf '%s\n' "$name"
|
||||
true
|
||||
+25
-2
@@ -35,6 +35,29 @@ export MOZ_ENABLE_WAYLAND=1
|
||||
export QT_QPA_PLATFORM=wayland
|
||||
export SDL_VIDEODRIVER=wayland
|
||||
|
||||
# Qt's platform theme decides where Qt apps get their palette from. With XDG_CURRENT_DESKTOP=chandra
|
||||
# Qt picks none of its desktop themes, so Qt 6 apps never saw the Dark mode switch (KDE Frameworks
|
||||
# 6 apps such as KWrite then pick Breeze Light). Prefer KDE's own (plasma-integration: reads the
|
||||
# kdeglobals colors chandra-kde-colors writes and repaints live when the switch flips), else Qt's
|
||||
# xdgdesktopportal theme (Qt 6.5+ follows the portal's color-scheme, which the compositor serves,
|
||||
# and KDE Frameworks apps then pick Breeze Dark/Light). A value set elsewhere (qt6ct, say) wins.
|
||||
qt_theme_plugin() { # QT_MAJOR GLOB -> success if a platform theme plugin matching GLOB exists
|
||||
for d in /usr/lib/qt$1/plugins /usr/lib64/qt$1/plugins /usr/lib/*-linux-gnu*/qt$1/plugins \
|
||||
/usr/lib/qt/plugins /usr/lib64/qt/plugins /usr/local/lib/qt$1/plugins; do
|
||||
for f in "$d"/platformthemes/$2; do [ -e "$f" ] && return 0; done
|
||||
done
|
||||
return 1
|
||||
}
|
||||
if [ -z "${QT_QPA_PLATFORMTHEME:-}" ]; then
|
||||
if qt_theme_plugin 6 'KDEPlasmaPlatformTheme6.so'; then
|
||||
export QT_QPA_PLATFORMTHEME=kde
|
||||
elif qt_theme_plugin 6 'libqxdgdesktopportal.so'; then
|
||||
export QT_QPA_PLATFORMTHEME=xdgdesktopportal
|
||||
elif qt_theme_plugin 5 'KDEPlasmaPlatformTheme*.so'; then
|
||||
export QT_QPA_PLATFORMTHEME=kde
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$HOME/.local/state/chandra"
|
||||
log="$HOME/.local/state/chandra/session.log"
|
||||
[ -n "$CHANDRA_SESSION_LOG_STARTED" ] || : >"$log"
|
||||
@@ -72,10 +95,10 @@ fi
|
||||
if command -v dbus-update-activation-environment >/dev/null 2>&1; then
|
||||
dbus-update-activation-environment --systemd \
|
||||
WAYLAND_DISPLAY="$(basename "$sock")" XDG_SESSION_TYPE XDG_CURRENT_DESKTOP \
|
||||
XDG_SESSION_DESKTOP >>"$log" 2>&1 ||
|
||||
XDG_SESSION_DESKTOP QT_QPA_PLATFORM QT_QPA_PLATFORMTHEME >>"$log" 2>&1 ||
|
||||
dbus-update-activation-environment \
|
||||
WAYLAND_DISPLAY="$(basename "$sock")" XDG_SESSION_TYPE XDG_CURRENT_DESKTOP \
|
||||
XDG_SESSION_DESKTOP >>"$log" 2>&1 || true
|
||||
XDG_SESSION_DESKTOP QT_QPA_PLATFORM QT_QPA_PLATFORMTHEME >>"$log" 2>&1 || true
|
||||
fi
|
||||
|
||||
# xdg-desktop-portal picks its backends once, at start, from $XDG_CURRENT_DESKTOP (here
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
# Chandra's own dark KDE color scheme, from the Moon Night desktop palette (config/themes).
|
||||
# chandra-kde-colors uses it when Breeze's schemes aren't installed.
|
||||
|
||||
[Colors:Window]
|
||||
BackgroundAlternate=39,49,64
|
||||
BackgroundNormal=31,41,55
|
||||
DecorationFocus=124,156,255
|
||||
DecorationHover=124,156,255
|
||||
ForegroundActive=124,156,255
|
||||
ForegroundInactive=156,163,175
|
||||
ForegroundLink=124,156,255
|
||||
ForegroundNegative=248,113,113
|
||||
ForegroundNeutral=251,191,36
|
||||
ForegroundNormal=243,244,246
|
||||
ForegroundPositive=74,222,128
|
||||
ForegroundVisited=180,140,255
|
||||
|
||||
[Colors:View]
|
||||
BackgroundAlternate=24,32,48
|
||||
BackgroundNormal=17,24,39
|
||||
DecorationFocus=124,156,255
|
||||
DecorationHover=124,156,255
|
||||
ForegroundActive=124,156,255
|
||||
ForegroundInactive=156,163,175
|
||||
ForegroundLink=124,156,255
|
||||
ForegroundNegative=248,113,113
|
||||
ForegroundNeutral=251,191,36
|
||||
ForegroundNormal=243,244,246
|
||||
ForegroundPositive=74,222,128
|
||||
ForegroundVisited=180,140,255
|
||||
|
||||
[Colors:Button]
|
||||
BackgroundAlternate=59,70,88
|
||||
BackgroundNormal=55,65,81
|
||||
DecorationFocus=124,156,255
|
||||
DecorationHover=124,156,255
|
||||
ForegroundActive=124,156,255
|
||||
ForegroundInactive=156,163,175
|
||||
ForegroundLink=124,156,255
|
||||
ForegroundNegative=248,113,113
|
||||
ForegroundNeutral=251,191,36
|
||||
ForegroundNormal=243,244,246
|
||||
ForegroundPositive=74,222,128
|
||||
ForegroundVisited=180,140,255
|
||||
|
||||
[Colors:Selection]
|
||||
BackgroundAlternate=98,124,210
|
||||
BackgroundNormal=124,156,255
|
||||
DecorationFocus=124,156,255
|
||||
DecorationHover=124,156,255
|
||||
ForegroundActive=11,16,32
|
||||
ForegroundInactive=156,163,175
|
||||
ForegroundLink=11,16,32
|
||||
ForegroundNegative=248,113,113
|
||||
ForegroundNeutral=251,191,36
|
||||
ForegroundNormal=11,16,32
|
||||
ForegroundPositive=74,222,128
|
||||
ForegroundVisited=180,140,255
|
||||
|
||||
[Colors:Tooltip]
|
||||
BackgroundAlternate=31,41,55
|
||||
BackgroundNormal=17,24,39
|
||||
DecorationFocus=124,156,255
|
||||
DecorationHover=124,156,255
|
||||
ForegroundActive=124,156,255
|
||||
ForegroundInactive=156,163,175
|
||||
ForegroundLink=124,156,255
|
||||
ForegroundNegative=248,113,113
|
||||
ForegroundNeutral=251,191,36
|
||||
ForegroundNormal=243,244,246
|
||||
ForegroundPositive=74,222,128
|
||||
ForegroundVisited=180,140,255
|
||||
|
||||
[Colors:Complementary]
|
||||
BackgroundAlternate=31,41,55
|
||||
BackgroundNormal=17,24,39
|
||||
DecorationFocus=124,156,255
|
||||
DecorationHover=124,156,255
|
||||
ForegroundActive=124,156,255
|
||||
ForegroundInactive=156,163,175
|
||||
ForegroundLink=124,156,255
|
||||
ForegroundNegative=248,113,113
|
||||
ForegroundNeutral=251,191,36
|
||||
ForegroundNormal=243,244,246
|
||||
ForegroundPositive=74,222,128
|
||||
ForegroundVisited=180,140,255
|
||||
|
||||
[Colors:Header]
|
||||
BackgroundAlternate=39,49,64
|
||||
BackgroundNormal=31,41,55
|
||||
DecorationFocus=124,156,255
|
||||
DecorationHover=124,156,255
|
||||
ForegroundActive=124,156,255
|
||||
ForegroundInactive=156,163,175
|
||||
ForegroundLink=124,156,255
|
||||
ForegroundNegative=248,113,113
|
||||
ForegroundNeutral=251,191,36
|
||||
ForegroundNormal=243,244,246
|
||||
ForegroundPositive=74,222,128
|
||||
ForegroundVisited=180,140,255
|
||||
|
||||
[ColorEffects:Disabled]
|
||||
Color=56,56,56
|
||||
ColorAmount=0
|
||||
ColorEffect=0
|
||||
ContrastAmount=0.65
|
||||
ContrastEffect=1
|
||||
IntensityAmount=0.1
|
||||
IntensityEffect=2
|
||||
|
||||
[ColorEffects:Inactive]
|
||||
ChangeSelectionColor=true
|
||||
Enable=false
|
||||
|
||||
[General]
|
||||
ColorScheme=ChandraDark
|
||||
Name=Chandra Dark
|
||||
|
||||
[WM]
|
||||
activeBackground=31,41,55
|
||||
activeBlend=243,244,246
|
||||
activeForeground=243,244,246
|
||||
inactiveBackground=17,24,39
|
||||
inactiveBlend=156,163,175
|
||||
inactiveForeground=156,163,175
|
||||
@@ -0,0 +1,125 @@
|
||||
# Chandra's own light KDE color scheme, from the Moon Day desktop palette (config/themes).
|
||||
# chandra-kde-colors uses it when Breeze's schemes aren't installed.
|
||||
|
||||
[Colors:Window]
|
||||
BackgroundAlternate=234,238,246
|
||||
BackgroundNormal=244,246,251
|
||||
DecorationFocus=59,107,255
|
||||
DecorationHover=59,107,255
|
||||
ForegroundActive=59,107,255
|
||||
ForegroundInactive=91,101,119
|
||||
ForegroundLink=59,107,255
|
||||
ForegroundNegative=220,38,38
|
||||
ForegroundNeutral=202,138,4
|
||||
ForegroundNormal=27,34,51
|
||||
ForegroundPositive=22,163,74
|
||||
ForegroundVisited=124,58,237
|
||||
|
||||
[Colors:View]
|
||||
BackgroundAlternate=246,248,252
|
||||
BackgroundNormal=255,255,255
|
||||
DecorationFocus=59,107,255
|
||||
DecorationHover=59,107,255
|
||||
ForegroundActive=59,107,255
|
||||
ForegroundInactive=91,101,119
|
||||
ForegroundLink=59,107,255
|
||||
ForegroundNegative=220,38,38
|
||||
ForegroundNeutral=202,138,4
|
||||
ForegroundNormal=27,34,51
|
||||
ForegroundPositive=22,163,74
|
||||
ForegroundVisited=124,58,237
|
||||
|
||||
[Colors:Button]
|
||||
BackgroundAlternate=210,218,232
|
||||
BackgroundNormal=221,227,240
|
||||
DecorationFocus=59,107,255
|
||||
DecorationHover=59,107,255
|
||||
ForegroundActive=59,107,255
|
||||
ForegroundInactive=91,101,119
|
||||
ForegroundLink=59,107,255
|
||||
ForegroundNegative=220,38,38
|
||||
ForegroundNeutral=202,138,4
|
||||
ForegroundNormal=27,34,51
|
||||
ForegroundPositive=22,163,74
|
||||
ForegroundVisited=124,58,237
|
||||
|
||||
[Colors:Selection]
|
||||
BackgroundAlternate=120,150,255
|
||||
BackgroundNormal=59,107,255
|
||||
DecorationFocus=59,107,255
|
||||
DecorationHover=59,107,255
|
||||
ForegroundActive=255,255,255
|
||||
ForegroundInactive=91,101,119
|
||||
ForegroundLink=255,255,255
|
||||
ForegroundNegative=220,38,38
|
||||
ForegroundNeutral=202,138,4
|
||||
ForegroundNormal=255,255,255
|
||||
ForegroundPositive=22,163,74
|
||||
ForegroundVisited=124,58,237
|
||||
|
||||
[Colors:Tooltip]
|
||||
BackgroundAlternate=244,246,251
|
||||
BackgroundNormal=251,252,255
|
||||
DecorationFocus=59,107,255
|
||||
DecorationHover=59,107,255
|
||||
ForegroundActive=59,107,255
|
||||
ForegroundInactive=91,101,119
|
||||
ForegroundLink=59,107,255
|
||||
ForegroundNegative=220,38,38
|
||||
ForegroundNeutral=202,138,4
|
||||
ForegroundNormal=27,34,51
|
||||
ForegroundPositive=22,163,74
|
||||
ForegroundVisited=124,58,237
|
||||
|
||||
[Colors:Complementary]
|
||||
BackgroundAlternate=234,238,246
|
||||
BackgroundNormal=244,246,251
|
||||
DecorationFocus=59,107,255
|
||||
DecorationHover=59,107,255
|
||||
ForegroundActive=59,107,255
|
||||
ForegroundInactive=91,101,119
|
||||
ForegroundLink=59,107,255
|
||||
ForegroundNegative=220,38,38
|
||||
ForegroundNeutral=202,138,4
|
||||
ForegroundNormal=27,34,51
|
||||
ForegroundPositive=22,163,74
|
||||
ForegroundVisited=124,58,237
|
||||
|
||||
[Colors:Header]
|
||||
BackgroundAlternate=234,238,246
|
||||
BackgroundNormal=244,246,251
|
||||
DecorationFocus=59,107,255
|
||||
DecorationHover=59,107,255
|
||||
ForegroundActive=59,107,255
|
||||
ForegroundInactive=91,101,119
|
||||
ForegroundLink=59,107,255
|
||||
ForegroundNegative=220,38,38
|
||||
ForegroundNeutral=202,138,4
|
||||
ForegroundNormal=27,34,51
|
||||
ForegroundPositive=22,163,74
|
||||
ForegroundVisited=124,58,237
|
||||
|
||||
[ColorEffects:Disabled]
|
||||
Color=56,56,56
|
||||
ColorAmount=0
|
||||
ColorEffect=0
|
||||
ContrastAmount=0.65
|
||||
ContrastEffect=1
|
||||
IntensityAmount=0.1
|
||||
IntensityEffect=2
|
||||
|
||||
[ColorEffects:Inactive]
|
||||
ChangeSelectionColor=true
|
||||
Enable=false
|
||||
|
||||
[General]
|
||||
ColorScheme=ChandraLight
|
||||
Name=Chandra Light
|
||||
|
||||
[WM]
|
||||
activeBackground=244,246,251
|
||||
activeBlend=27,34,51
|
||||
activeForeground=27,34,51
|
||||
inactiveBackground=234,238,246
|
||||
inactiveBlend=91,101,119
|
||||
inactiveForeground=91,101,119
|
||||
@@ -23,6 +23,10 @@ Installs:
|
||||
/usr/local/bin/chandra-root run one graphical app as root in the session (run0)
|
||||
/usr/local/bin/chandra-ctl talk to the running session: `chandra-ctl reload` loads
|
||||
the panel modules again (docs/reloading.md)
|
||||
/usr/local/bin/chandra-kde-colors Dark mode for KDE/Qt apps: copies a color scheme into
|
||||
kdeglobals (docs/dark-mode.md)
|
||||
/usr/local/share/color-schemes/Chandra{Dark,Light}.colors KDE color schemes, used when Breeze's
|
||||
aren't installed
|
||||
/usr/local/share/chandra/{config,wit,assets}/ files the compositor reads at runtime
|
||||
/usr/local/share/chandra/modules/*.wasm the panel's wasm modules (build them first: just modules)
|
||||
/usr/share/wayland-sessions/chandra.desktop display-manager entry
|
||||
@@ -48,6 +52,9 @@ targets = [
|
||||
"/usr/local/bin/chandra-session",
|
||||
"/usr/local/bin/chandra-root",
|
||||
"/usr/local/bin/chandra-ctl",
|
||||
"/usr/local/bin/chandra-kde-colors",
|
||||
"/usr/local/share/color-schemes/ChandraDark.colors",
|
||||
"/usr/local/share/color-schemes/ChandraLight.colors",
|
||||
"/usr/share/wayland-sessions/chandra.desktop",
|
||||
"/usr/share/xdg-desktop-portal/portals/chandra.portal",
|
||||
"/usr/share/xdg-desktop-portal/chandra-portals.conf",
|
||||
@@ -132,6 +139,9 @@ if not native:
|
||||
install(os.path.join(root, "session/chandra-session"), "/usr/local/bin/chandra-session")
|
||||
install(os.path.join(root, "session/chandra-root"), "/usr/local/bin/chandra-root")
|
||||
install(os.path.join(root, "session/chandra-ctl"), "/usr/local/bin/chandra-ctl")
|
||||
install(os.path.join(root, "session/chandra-kde-colors"), "/usr/local/bin/chandra-kde-colors")
|
||||
for f in ("ChandraDark.colors", "ChandraLight.colors"):
|
||||
put(os.path.join(root, "session/color-schemes", f), "/usr/local/share/color-schemes/" + f, 0o644)
|
||||
# The display-manager entry stays a real file: some managers don't follow symlinks there.
|
||||
put(os.path.join(root, "session/chandra.desktop"), "/usr/share/wayland-sessions/chandra.desktop", 0o644)
|
||||
# xdg-desktop-portal reads backends only from /usr/share (or $XDG_DESKTOP_PORTAL_DIR), not
|
||||
|
||||
Reference in new issue
Block a user