[BUG] run_matugen() regenerates the whole palette in light mode when gtk-application-prefer-dark-theme is 'true' instead of '1'

未关闭 适合新手
#1,765 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
bash, linux
领域
backend

调研方向

阅读 .config/ml4w/scripts/ml4w-wallpaper,特别是第 109–113 行 GTK 首选项检查附近的 run_matugen(),并将其处理方式与 issue 中提到的两个脚本进行比较。更新检查逻辑,使 1 和 true 都选择深色模式,而 0 和 false 选择浅色模式。按照 issue 中的说明,四个值都能在不产生 stderr 的情况下得到预期模式,即为完成。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

run_matugen() in .config/ml4w/scripts/ml4w-wallpaper decides between light and dark mode with a numeric comparison against gtk-application-prefer-dark-theme:

https://github.com/mylinuxforwork/dotfiles/blob/3de368eb047c663d4ac06da1ce2558c96bc1ad2a/dotfiles/.config/ml4w/scripts/ml4w-wallpaper#L109-L113

theme_pref=$(grep -E '^gtk-application-prefer-dark-theme=' "$HOME/.config/gtk-3.0/settings.ini" | awk -F'=' '{print $2}')
local mode="light"
[ "$theme_pref" -eq 1 ] && mode="dark"

gtk-application-prefer-dark-theme is a GTK boolean, so true/false is an equally valid spelling of 1/0. When the key holds true, [ -eq ] fails:

$ theme_pref="true"; [ "$theme_pref" -eq 1 ] && mode="dark"
bash: line 1: [: true: integer expected

The && chain short-circuits, mode keeps its default light, and matugen regenerates the entire palette in light mode — waybar, window borders, GTK, rofi, swaync, btop, kitty, nwg-dock and the quickshell components all go light on a dark setup. With wallpaper automation enabled it happens unattended, so it looks like an update silently changed the theme.

This is an internal inconsistency, not a missing feature. Two other consumers of the same key in this repo already accept both spellings:

  • .config/ml4w/listeners/gtk-theme-switcher.sh — line 49 handles 1/true and 0/false explicitly, and even warns on unexpected values:
    if [[ "$THEME_PREF" == "1" || "$THEME_PREF" == "true" ]]; then
    
  • .config/hypr/scripts/gtk.sh — line 28 treats only 0/false as light:
    if [[ $prefer_dark_theme == "0" || $prefer_dark_theme == "false" ]]; then
    

So of the three places that read this key, only run_matugen() was left with the numeric test.

The dotfiles ship gtk-application-prefer-dark-theme=1, which is why this doesn't show on a clean install. It surfaces once any third-party GTK settings tool normalizes settings.ini to the boolean spelling.

Steps to reproduce

On my machine the key was flipped to true by kde-gtk-config, which is part of the default CachyOS package set even in a Hyprland session. It rewrote ~/.config/gtk-3.0/settings.ini and ~/.config/gtk-4.0/settings.ini into KDE's format — both files and ~/.config/xsettingsd/xsettingsd.conf share the same mtime to the second, and the values it left behind are KDE's (breeze, breeze_cursors, ocean). I did not determine what invoked it, so I can't give exact steps for that part.

The bug itself is independent of that trigger and can be reproduced directly:

  1. Confirm the current palette is dark: grep '"background"' ~/.config/ml4w/colors/colors.json
  2. Set the key to its boolean spelling:
    sed -i 's/^gtk-application-prefer-dark-theme=1/gtk-application-prefer-dark-theme=true/' ~/.config/gtk-3.0/settings.ini
  3. Re-run the wallpaper script:
    ~/.config/ml4w/scripts/ml4w-wallpaper "$(cat ~/.cache/ml4w/hyprland-dotfiles/current_wallpaper)"
  4. It logs Running matugen in light mode, and colors.json comes back light ("background": "#faf8ff" on my source wallpaper, vs #121318 before).
Expected behavior

run_matugen() should treat true the same as 1, consistently with gtk-theme-switcher.sh and gtk.sh, and keep generating a dark palette.

A one-line change is enough:

case "$theme_pref" in 1 | true) mode="dark" ;; esac

I verified this against all four values: 1 → dark, true → dark, 0 → light, false → light, with no stderr output. After applying it, the script logs Running matugen in dark mode and the palette returns to its previous values.

Screenshots

No response

Distribution

Other (please specify below)

If Other, specify

CachyOS (Arch-based), ML4W OS 2.12.3, Hyprland 0.56.1

Additional context

There is a second-order effect worth flagging: while the key holds true, .config/ml4w/scripts/ml4w-toggle-theme cannot switch modes either. It tests grep -q "gtk-application-prefer-dark-theme=1", does not match true, falls through to the else branch, and runs sed 's/gtk-application-prefer-dark-theme=0/...=1/', which does not match either. It prints Switched to dark theme while leaving the GTK3 file unchanged — so the user cannot correct the state from the UI, which is what makes the palette change feel permanent.

I searched open and closed issues before reporting (prefer-dark-theme, matugen, light theme, run_matugen, settings.ini, kde-gtk-config) and did not find this. #1596 looked close but is the opposite direction and was fixed in 2.13.0.

I have no strong preference on the fix; the case above is just the smallest change that matches what the other two scripts already do. Happy to open a PR if that helps.

Code of Conduct
  • I agree to follow this project's Code of Conduct
主要语言
QML
星标
5.1k
派生
386
平均合并
16 小时 45 分钟
30 天内合并 PR
14

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

mylinuxforwork/dotfiles 的其他 Issue

查看 mylinuxforwork/dotfiles 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。