From be6ef5fc779bf337b080c5f76a71c88d62f53d4d Mon Sep 17 00:00:00 2001 From: bbedward Date: Fri, 1 Aug 2025 08:06:21 -0400 Subject: [PATCH] fix qt auto-theme --- Common/Colors.qml | 12 ++++- Common/Prefs.qml | 1 + README.md | 6 +++ generate-themes.sh | 99 ++++++++++++++++++++++++++++++++++++-- matugen-config.toml | 10 +++- templates/qt-colors.colors | 82 ------------------------------- templates/qtct-colors.conf | 5 ++ 7 files changed, 126 insertions(+), 89 deletions(-) delete mode 100644 templates/qt-colors.colors create mode 100644 templates/qtct-colors.conf diff --git a/Common/Colors.qml b/Common/Colors.qml index ba9a63a0..02fef696 100644 --- a/Common/Colors.qml +++ b/Common/Colors.qml @@ -292,12 +292,16 @@ palette = 15=${fg_b}`; // Get current theme preferences const isLight = (typeof Theme !== "undefined" && Theme.isLightMode) ? "true" : "false"; const iconTheme = (typeof Prefs !== "undefined" && Prefs.iconTheme) ? Prefs.iconTheme : "System Default"; + const gtkTheming = (typeof Prefs !== "undefined" && Prefs.gtkThemingEnabled) ? "true" : "false"; + const qtTheming = (typeof Prefs !== "undefined" && Prefs.qtThemingEnabled) ? "true" : "false"; console.log("Theme mode:", isLight === "true" ? "light" : "dark"); console.log("Icon theme:", iconTheme); + console.log("GTK theming enabled:", gtkTheming); + console.log("Qt theming enabled:", qtTheming); systemThemeGenerationInProgress = true; - systemThemeGenerator.command = [shellDir + "/generate-themes.sh", wallpaperPath, shellDir, homeDir, "generate", isLight, iconTheme]; + systemThemeGenerator.command = [shellDir + "/generate-themes.sh", wallpaperPath, shellDir, homeDir, "generate", isLight, iconTheme, gtkTheming, qtTheming]; systemThemeGenerator.running = true; } @@ -323,11 +327,15 @@ palette = 15=${fg_b}`; // Get current theme preferences const isLight = (typeof Theme !== "undefined" && Theme.isLightMode) ? "true" : "false"; const iconTheme = (typeof Prefs !== "undefined" && Prefs.iconTheme) ? Prefs.iconTheme : "System Default"; + const gtkTheming = (typeof Prefs !== "undefined" && Prefs.gtkThemingEnabled) ? "true" : "false"; + const qtTheming = (typeof Prefs !== "undefined" && Prefs.qtThemingEnabled) ? "true" : "false"; console.log("Restoring to theme mode:", isLight === "true" ? "light" : "dark"); console.log("Icon theme:", iconTheme); + console.log("GTK theming enabled:", gtkTheming); + console.log("Qt theming enabled:", qtTheming); - systemThemeRestoreProcess.command = [shellDir + "/generate-themes.sh", "", shellDir, homeDir, "restore", isLight, iconTheme]; + systemThemeRestoreProcess.command = [shellDir + "/generate-themes.sh", "", shellDir, homeDir, "restore", isLight, iconTheme, gtkTheming, qtTheming]; systemThemeRestoreProcess.running = true; } diff --git a/Common/Prefs.qml b/Common/Prefs.qml index 28adce76..9a740d17 100644 --- a/Common/Prefs.qml +++ b/Common/Prefs.qml @@ -545,6 +545,7 @@ Singleton { Quickshell.execDetached(["sh", "-lc", script]); } + function applyStoredIconTheme() { updateGtkIconTheme(iconTheme); updateQtIconTheme(iconTheme); diff --git a/README.md b/README.md index 9bd883e3..cc52a862 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,12 @@ sudo dnf copr enable heus-sueh/packages && sudo dnf install matugen gtk-theme-name=Colloid ``` +**Recommended QT base them:** Breeze is recommended, on arch it can be installed with `pacman -S breeze breeze5` and then in `~/.confg/qt6ct/qt6ct.conf` and `~/.confg/qt5ct/qt5ct.conf` set the following: +``` +[Appearance] +style=Breeze +``` + Enable these features in Settings → Appearance → System App Theming after installing the dependencies. 3. Install DankMaterialShell diff --git a/generate-themes.sh b/generate-themes.sh index 69ea06a7..ef68bb5b 100755 --- a/generate-themes.sh +++ b/generate-themes.sh @@ -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 [mode] [is_light] [icon_theme]" >&2 + echo "Usage: $0 [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/" \ No newline at end of file +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 \ No newline at end of file diff --git a/matugen-config.toml b/matugen-config.toml index 5001cefe..6e10c26a 100644 --- a/matugen-config.toml +++ b/matugen-config.toml @@ -10,4 +10,12 @@ output_path = '~/.config/gtk-4.0/dank-colors.css' [templates.qt] input_path = './templates/qt-colors.colors' -output_path = '~/.local/share/color-schemes/Matugen.colors' \ No newline at end of file +output_path = '~/.local/share/color-schemes/Matugen.colors' + +[templates.qt5ct] +input_path = './templates/qtct-colors.conf' +output_path = '~/.config/qt5ct/colors/matugen.conf' + +[templates.qt6ct] +input_path = './templates/qtct-colors.conf' +output_path = '~/.config/qt6ct/colors/matugen.conf' \ No newline at end of file diff --git a/templates/qt-colors.colors b/templates/qt-colors.colors deleted file mode 100644 index 737d1bf2..00000000 --- a/templates/qt-colors.colors +++ /dev/null @@ -1,82 +0,0 @@ -[ColorEffects:Disabled] -Color={{colors.surface_dim.default.hex}} -ColorAmount=0 -ColorEffect=0 -ContrastAmount=0.65 -ContrastEffect=1 -IntensityAmount=0.1 -IntensityEffect=2 - -[ColorEffects:Inactive] -ChangeSelectionColor=true -Color={{colors.surface_variant.default.hex}} -ColorAmount=0.025 -ColorEffect=2 -ContrastAmount=0.1 -ContrastEffect=2 -Enable=false -IntensityAmount=0 -IntensityEffect=0 - -[Colors:Button] -BackgroundAlternate={{colors.surface_container_low.default.hex}} -BackgroundNormal={{colors.surface_container_high.default.hex}} -DecorationFocus={{colors.primary.default.hex}} -DecorationHover={{colors.primary.default.hex}} -ForegroundActive={{colors.primary.default.hex}} -ForegroundInactive={{colors.on_surface_variant.default.hex}} -ForegroundLink={{colors.secondary.default.hex}} -ForegroundNegative={{colors.error.default.hex}} -ForegroundNeutral={{colors.tertiary.default.hex}} -ForegroundNormal={{colors.on_surface.default.hex}} -ForegroundPositive={{colors.tertiary_fixed.default.hex}} -ForegroundVisited={{colors.on_secondary_container.default.hex}} - -[Colors:Selection] -BackgroundAlternate={{colors.surface_container_low.default.hex}} -BackgroundNormal={{colors.primary.default.hex}} -DecorationFocus={{colors.primary.default.hex}} -DecorationHover={{colors.primary.default.hex}} -ForegroundActive={{colors.on_primary.default.hex}} -ForegroundInactive={{colors.on_surface_variant.default.hex}} -ForegroundLink={{colors.secondary_fixed.default.hex}} -ForegroundNegative={{colors.error_container.default.hex}} -ForegroundNeutral={{colors.tertiary_fixed_dim.default.hex}} -ForegroundNormal={{colors.on_primary.default.hex}} -ForegroundPositive={{colors.tertiary_container.default.hex}} -ForegroundVisited={{colors.on_secondary_container.default.hex}} - -[Colors:View] -BackgroundAlternate={{colors.surface_container.default.hex}} -BackgroundNormal={{colors.background.default.hex}} -DecorationFocus={{colors.on_primary_container.default.hex}} -DecorationHover={{colors.on_primary.default.hex}} -ForegroundActive={{colors.primary.default.hex}} -ForegroundInactive={{colors.on_surface_variant.default.hex}} -ForegroundLink={{colors.secondary.default.hex}} -ForegroundNegative={{colors.error.default.hex}} -ForegroundNeutral={{colors.tertiary.default.hex}} -ForegroundNormal={{colors.on_background.default.hex}} -ForegroundPositive={{colors.tertiary_fixed.default.hex}} -ForegroundVisited={{colors.on_secondary_container.default.hex}} - -[Colors:Window] -BackgroundAlternate={{colors.primary_container.default.hex}} -BackgroundNormal={{colors.surface_container.default.hex}} -DecorationFocus={{colors.primary.default.hex}} -DecorationHover={{colors.primary.default.hex}} -ForegroundActive={{colors.primary.default.hex}} -ForegroundInactive={{colors.on_surface_variant.default.hex}} -ForegroundLink={{colors.secondary.default.hex}} -ForegroundNegative={{colors.error.default.hex}} -ForegroundNeutral={{colors.tertiary.default.hex}} -ForegroundNormal={{colors.on_background.default.hex}} -ForegroundPositive={{colors.tertiary_fixed.default.hex}} -ForegroundVisited={{colors.on_secondary_container.default.hex}} - -[General] -ColorScheme=Matugen -Name=Matugen - -[KDE] -contrast=4 \ No newline at end of file diff --git a/templates/qtct-colors.conf b/templates/qtct-colors.conf new file mode 100644 index 00000000..5d35cb46 --- /dev/null +++ b/templates/qtct-colors.conf @@ -0,0 +1,5 @@ +[ColorScheme] +active_colors={{colors.on_background.default.hex}}, {{colors.surface.default.hex}}, #ffffff, #cacaca, #9f9f9f, #b8b8b8, {{colors.on_background.default.hex}}, #ffffff, {{colors.on_surface.default.hex}}, {{colors.background.default.hex}}, {{colors.background.default.hex}}, {{colors.shadow.default.hex}}, {{colors.primary_container.default.hex}}, {{colors.on_primary_container.default.hex}}, {{colors.secondary.default.hex}}, {{colors.primary.default.hex}}, {{colors.surface.default.hex}}, {{colors.scrim.default.hex}}, {{colors.surface.default.hex}}, {{colors.on_surface.default.hex}}, {{colors.secondary.default.hex}} +disabled_colors={{colors.on_background.default.hex}}, {{colors.surface.default.hex}}, #ffffff, #cacaca, #9f9f9f, #b8b8b8, {{colors.on_background.default.hex}}, #ffffff, {{colors.on_surface.default.hex}}, {{colors.background.default.hex}}, {{colors.background.default.hex}}, {{colors.shadow.default.hex}}, {{colors.primary_container.default.hex}}, {{colors.on_primary_container.default.hex}}, {{colors.secondary.default.hex}}, {{colors.primary.default.hex}}, {{colors.surface.default.hex}}, {{colors.scrim.default.hex}}, {{colors.surface.default.hex}}, {{colors.on_surface.default.hex}}, {{colors.secondary.default.hex}} +inactive_colors={{colors.on_background.default.hex}}, {{colors.surface.default.hex}}, #ffffff, #cacaca, #9f9f9f, #b8b8b8, {{colors.on_background.default.hex}}, #ffffff, {{colors.on_surface.default.hex}}, {{colors.background.default.hex}}, {{colors.background.default.hex}}, {{colors.shadow.default.hex}}, {{colors.primary_container.default.hex}}, {{colors.on_primary_container.default.hex}}, {{colors.secondary.default.hex}}, {{colors.primary.default.hex}}, {{colors.surface.default.hex}}, {{colors.scrim.default.hex}}, {{colors.surface.default.hex}}, {{colors.on_surface.default.hex}}, {{colors.secondary.default.hex}} +