1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-28 07:22:50 -05:00

fix qt auto-theme

This commit is contained in:
bbedward
2025-08-01 08:06:21 -04:00
parent ce9f4efb5d
commit be6ef5fc77
7 changed files with 126 additions and 89 deletions

View File

@@ -9,9 +9,11 @@ HOME_DIR="$3"
MODE="$4" # "generate" or "restore"
IS_LIGHT="$5" # "true" for light mode, "false" for dark mode
ICON_THEME="$6" # Icon theme name
GTK_THEMING="$7" # "true" to enable GTK theming, "false" to disable
QT_THEMING="$8" # "true" to enable Qt theming, "false" to disable
if [ -z "$SHELL_DIR" ] || [ -z "$HOME_DIR" ]; then
echo "Usage: $0 <wallpaper_path> <shell_dir> <home_dir> [mode] [is_light] [icon_theme]" >&2
echo "Usage: $0 <wallpaper_path> <shell_dir> <home_dir> [mode] [is_light] [icon_theme] [gtk_theming] [qt_theming]" >&2
echo " For restore mode, wallpaper_path can be empty" >&2
exit 1
fi
@@ -20,6 +22,8 @@ fi
MODE=${MODE:-"generate"}
IS_LIGHT=${IS_LIGHT:-"false"}
ICON_THEME=${ICON_THEME:-"System Default"}
GTK_THEMING=${GTK_THEMING:-"false"}
QT_THEMING=${QT_THEMING:-"false"}
update_theme_settings() {
local color_scheme="$1"
@@ -84,6 +88,75 @@ update_gtk_css() {
echo "Updated GTK-3.0 CSS import"
}
update_qt_config() {
local home_dir="$1"
local username=$(basename "$home_dir")
echo "Updating Qt configuration..."
# Function to update Qt config files with color scheme settings
update_qt_color_config() {
local config_file="$1"
local version="$2"
local color_scheme_path="$home_dir/.config/qt${version}ct/colors/matugen.conf"
if [ -f "$config_file" ]; then
# Update existing config with awk - properly handle existing [Appearance] section
awk -v scheme_path="$color_scheme_path" '
BEGIN { in_appearance = 0; custom_palette_set = 0; color_scheme_set = 0 }
/^\[Appearance\]/ {
in_appearance = 1;
print;
next
}
/^\[/ && !/^\[Appearance\]/ {
# End of [Appearance] section - add missing settings before next section
if (in_appearance) {
if (!custom_palette_set) { print "custom_palette=true" }
if (!color_scheme_set) { print "color_scheme_path=" scheme_path }
}
in_appearance = 0;
print;
next
}
in_appearance && /^custom_palette=/ {
print "custom_palette=true"
custom_palette_set = 1
next
}
in_appearance && /^color_scheme_path=/ {
print "color_scheme_path=" scheme_path
color_scheme_set = 1
next
}
{ print }
END {
# Handle case where [Appearance] is the last section
if (in_appearance) {
if (!custom_palette_set) print "custom_palette=true"
if (!color_scheme_set) print "color_scheme_path=" scheme_path
}
}
' "$config_file" > "$config_file.tmp" && mv "$config_file.tmp" "$config_file"
else
# Create new config file
printf '[Appearance]\ncustom_palette=true\ncolor_scheme_path=%s\n' "$color_scheme_path" > "$config_file"
fi
}
# Update Qt5ct if available
if command -v qt5ct >/dev/null 2>&1; then
update_qt_color_config "$home_dir/.config/qt5ct/qt5ct.conf" "5"
echo "Updated Qt5ct configuration"
fi
# Update Qt6ct if available
if command -v qt6ct >/dev/null 2>&1; then
update_qt_color_config "$home_dir/.config/qt6ct/qt6ct.conf" "6"
echo "Updated Qt6ct configuration"
fi
}
# Handle restore mode
if [ "$MODE" = "restore" ]; then
echo "Restoring default theme settings..."
@@ -143,8 +216,26 @@ fi
update_theme_settings "$color_scheme" "$ICON_THEME"
# Update GTK CSS imports
update_gtk_css "$HOME_DIR"
# Update GTK CSS imports if GTK theming is enabled
if [ "$GTK_THEMING" = "true" ]; then
update_gtk_css "$HOME_DIR"
echo "GTK theming updated"
else
echo "GTK theming disabled - skipping GTK CSS updates"
fi
# Update Qt configuration if Qt theming is enabled
if [ "$QT_THEMING" = "true" ]; then
update_qt_config "$HOME_DIR"
echo "Qt theming updated"
else
echo "Qt theming disabled - skipping Qt configuration updates"
fi
echo "System theme files generated successfully"
echo "dank-colors.css files should be available in $HOME_DIR/.config/gtk-3.0/ and $HOME_DIR/.config/gtk-4.0/"
if [ "$GTK_THEMING" = "true" ]; then
echo "dank-colors.css files should be available in $HOME_DIR/.config/gtk-3.0/ and $HOME_DIR/.config/gtk-4.0/"
fi
if [ "$QT_THEMING" = "true" ]; then
echo "Qt color schemes should be available in $HOME_DIR/.config/qt5ct/colors/ and $HOME_DIR/.config/qt6ct/colors/"
fi