# Darkman is deliberately headless. The actual adapter runs as a separate # user unit and owns its explicit offscreen Qt environment. if systemctl --user restart --no-block darkman-apply-theme.service; then printf'[darkman-state] queued darkman-apply-theme.service\n' else printf'[darkman-state] warning: could not queue theme adapter\n' >&2 fi
read_mode() { local value if [[ -r "$state_file" ]]; then value="$(<"$state_file")" else value="$(/usr/bin/darkman get 2>/dev/null || true)" fi case"$value"in dark|light) printf'%s\n'"$value" ;; *) log"invalid or missing mode: ${value:-<empty>}" >&2 return 2 ;; esac }
update_settings_ini() { local file="$1" local gtk_theme="$2" local prefer_dark="$3" local tmp mode_bits
if [[ ! -f "$file" ]]; then log"skip missing $file" return 0 fi
tmp="$(mktemp "${file}.tmp.XXXXXX")" mode_bits="$(stat -c '%a' "$file")" if ! awk -v theme="$gtk_theme" -v dark="$prefer_dark"' BEGIN { in_settings=0; settings_seen=0; theme_seen=0; dark_seen=0 } /^\[Settings\][[:space:]]*$/ { in_settings=1; settings_seen=1; print; next } /^\[/ { if (in_settings && !theme_seen) { print "gtk-theme-name=" theme; theme_seen=1 } if (in_settings && !dark_seen) { print "gtk-application-prefer-dark-theme=" dark; dark_seen=1 } in_settings=0 print next } { if (in_settings && $0 ~ /^gtk-theme-name[[:space:]]*=/) { print "gtk-theme-name=" theme theme_seen=1 next } if (in_settings && $0 ~ /^gtk-application-prefer-dark-theme[[:space:]]*=/) { print "gtk-application-prefer-dark-theme=" dark dark_seen=1 next } print } END { if (in_settings && !theme_seen) print "gtk-theme-name=" theme if (in_settings && !dark_seen) print "gtk-application-prefer-dark-theme=" dark if (!settings_seen) { print "" print "[Settings]" print "gtk-theme-name=" theme print "gtk-application-prefer-dark-theme=" dark } } '"$file" > "$tmp"; then rm -f -- "$tmp" return 1 fi chmod"$mode_bits""$tmp" mv -- "$tmp""$file" log"updated $file" }
update_gtkrc() { local file="$1" local gtk_theme="$2" local theme_dir="$3" local tmp mode_bits
if [[ ! -f "$file" ]]; then log"skip missing $file" return 0 fi
tmp="$(mktemp "${file}.tmp.XXXXXX")" mode_bits="$(stat -c '%a' "$file")" if ! awk -v theme="$gtk_theme" -v theme_dir="$theme_dir"' BEGIN { theme_seen=0; include_seen=0 } /^[[:space:]]*include[[:space:]]+"\/usr\/share\/themes\/[^/"]+\/gtk-2\.0\/gtkrc"[[:space:]]*$/ { print "include \"/usr/share/themes/" theme_dir "/gtk-2.0/gtkrc\"" include_seen=1 next } /^[[:space:]]*gtk-theme-name[[:space:]]*=/ { print "gtk-theme-name=\"" theme "\"" theme_seen=1 next } { print } END { if (!include_seen) print "include \"/usr/share/themes/" theme_dir "/gtk-2.0/gtkrc\"" if (!theme_seen) print "gtk-theme-name=\"" theme "\"" } '"$file" > "$tmp"; then rm -f -- "$tmp" return 1 fi chmod"$mode_bits""$tmp" mv -- "$tmp""$file" log"updated $file" }
# The global Darkman service has no DISPLAY or WAYLAND_DISPLAY. The KDE # command is therefore deliberately given an offscreen Qt backend instead of # inheriting an arbitrary desktop session. kde_status=0 if QT_QPA_PLATFORM=offscreen QT_QPA_PLATFORMTHEME=kde \ /usr/bin/plasma-apply-colorscheme "$plasma_scheme"; then log"KDE color scheme applied: $plasma_scheme" else kde_status=$? log"warning: KDE color scheme adapter failed with status $kde_status" >&2 fi
/usr/bin/gsettings set org.gnome.desktop.interface gtk-theme "$gtk_theme" /usr/bin/gsettings set org.gnome.desktop.interface color-scheme "$color_scheme"
# This is a notification only; it does not write KDE configuration. /usr/bin/dbus-send --session --type=signal \ /KGlobalSettings org.kde.KGlobalSettings.notifyChange int32:0 int32:0 2>/dev/null || true
if systemctl --user is-active --quiet darkman-apply-theme.service 2>/dev/null; then systemctl --user stop darkman-apply-theme.service fi
for item in .config/hypr/autostart.lua .local/share/darkman/10-breeze-state \ .local/share/darkman/10-breeze-theme.legacy-disabled \ .local/bin/darkman-apply-breeze-theme .config/systemd/user/darkman-apply-theme.service; do if [[ -e "$home_dir/$item" ]]; then mkdir -p -- "$rescue_dir/$(dirname "$item")" mv -- "$home_dir/$item""$rescue_dir/$item" fi done
if [[ -f "$rescue_dir/.local/share/darkman/10-breeze-theme.legacy-disabled" ]]; then mv -- "$rescue_dir/.local/share/darkman/10-breeze-theme.legacy-disabled" \ "$home_dir/.local/share/darkman/10-breeze-theme" fi
for item in .config/hypr/autostart.lua .config/darkman .local/share/darkman \ .config/xdg-desktop-portal .config/gtkrc .gtkrc-2.0 .config/gtk-2.0 \ .config/gtk-3.0 .config/gtk-4.0 .config/kded6rc .config/kdeglobals \ .config/plasmarc .config/kcminputrc .config/dconf/user; do if [[ -e "$backup_dir/$item" ]]; then mkdir -p -- "$home_dir/$(dirname "$item")" cp -a "$backup_dir/$item""$home_dir/$item" fi done
systemctl --user daemon-reload printf'Restored previous implementation from %s\n'"$backup_dir" printf'New files were preserved under %s\n'"$rescue_dir"
停止主题适配器。
将新文件保存到新的 rescue 目录。
从本次备份恢复旧实现,包括 KDE、dconf、GTK、Portal 和 Hyprland 配置。
恢复旧的 10-breeze-theme 文件名。
重新加载用户 systemd 单元。
已知限制
Plasma Portal 的运行时选择没有通过重新登录 KDE 实际测试;系统仍保留 KDE Portal 配置,没有创建通用用户 Portal 配置。