Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Qt theming ] qt apps material theming using kvantum #1055

Merged
merged 11 commits into from
Feb 3, 2025
576 changes: 576 additions & 0 deletions .config/Kvantum/Colloid/Colloid.kvconfig

Large diffs are not rendered by default.

6,276 changes: 6,276 additions & 0 deletions .config/Kvantum/Colloid/Colloid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
569 changes: 569 additions & 0 deletions .config/Kvantum/Colloid/ColloidDark.kvconfig

Large diffs are not rendered by default.

6,359 changes: 6,359 additions & 0 deletions .config/Kvantum/Colloid/ColloidDark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
571 changes: 571 additions & 0 deletions .config/Kvantum/MaterialAdw/MaterialAdw.kvconfig

Large diffs are not rendered by default.

6,359 changes: 6,359 additions & 0 deletions .config/Kvantum/MaterialAdw/MaterialAdw.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions .config/Kvantum/kvantum.kvconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[General]
theme=MaterialAdw
219 changes: 112 additions & 107 deletions .config/ags/scripts/color_generation/applycolor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ STATE_DIR="$XDG_STATE_HOME/ags"
term_alpha=100 #Set this to < 100 make all your terminals transparent
# sleep 0 # idk i wanted some delay or colors dont get applied properly
if [ ! -d "$CACHE_DIR"/user/generated ]; then
mkdir -p "$CACHE_DIR"/user/generated
mkdir -p "$CACHE_DIR"/user/generated
fi
cd "$CONFIG_DIR" || exit

Expand Down Expand Up @@ -38,145 +38,150 @@ transparentize() {
}

get_light_dark() {
lightdark=""
if [ ! -f "$STATE_DIR/user/colormode.txt" ]; then
echo "" > "$STATE_DIR/user/colormode.txt"
else
lightdark=$(sed -n '1p' "$STATE_DIR/user/colormode.txt")
fi
echo "$lightdark"
lightdark=""
if [ ! -f "$STATE_DIR/user/colormode.txt" ]; then
echo "" >"$STATE_DIR/user/colormode.txt"
else
lightdark=$(sed -n '1p' "$STATE_DIR/user/colormode.txt")
fi
echo "$lightdark"
}

apply_fuzzel() {
# Check if scripts/templates/fuzzel/fuzzel.ini exists
if [ ! -f "scripts/templates/fuzzel/fuzzel.ini" ]; then
echo "Template file not found for Fuzzel. Skipping that."
return
fi
# Copy template
mkdir -p "$CACHE_DIR"/user/generated/fuzzel
cp "scripts/templates/fuzzel/fuzzel.ini" "$CACHE_DIR"/user/generated/fuzzel/fuzzel.ini
# Apply colors
for i in "${!colorlist[@]}"; do
sed -i "s/{{ ${colorlist[$i]} }}/${colorvalues[$i]#\#}/g" "$CACHE_DIR"/user/generated/fuzzel/fuzzel.ini
done

cp "$CACHE_DIR"/user/generated/fuzzel/fuzzel.ini "$XDG_CONFIG_HOME"/fuzzel/fuzzel.ini
# Check if scripts/templates/fuzzel/fuzzel.ini exists
if [ ! -f "scripts/templates/fuzzel/fuzzel.ini" ]; then
echo "Template file not found for Fuzzel. Skipping that."
return
fi
# Copy template
mkdir -p "$CACHE_DIR"/user/generated/fuzzel
cp "scripts/templates/fuzzel/fuzzel.ini" "$CACHE_DIR"/user/generated/fuzzel/fuzzel.ini
# Apply colors
for i in "${!colorlist[@]}"; do
sed -i "s/{{ ${colorlist[$i]} }}/${colorvalues[$i]#\#}/g" "$CACHE_DIR"/user/generated/fuzzel/fuzzel.ini
done

cp "$CACHE_DIR"/user/generated/fuzzel/fuzzel.ini "$XDG_CONFIG_HOME"/fuzzel/fuzzel.ini
}

apply_term() {
# Check if terminal escape sequence template exists
if [ ! -f "scripts/templates/terminal/sequences.txt" ]; then
echo "Template file not found for Terminal. Skipping that."
return
# Check if terminal escape sequence template exists
if [ ! -f "scripts/templates/terminal/sequences.txt" ]; then
echo "Template file not found for Terminal. Skipping that."
return
fi
# Copy template
mkdir -p "$CACHE_DIR"/user/generated/terminal
cp "scripts/templates/terminal/sequences.txt" "$CACHE_DIR"/user/generated/terminal/sequences.txt
# Apply colors
for i in "${!colorlist[@]}"; do
sed -i "s/${colorlist[$i]} #/${colorvalues[$i]#\#}/g" "$CACHE_DIR"/user/generated/terminal/sequences.txt
done

sed -i "s/\$alpha/$term_alpha/g" "$CACHE_DIR/user/generated/terminal/sequences.txt"

for file in /dev/pts/*; do
if [[ $file =~ ^/dev/pts/[0-9]+$ ]]; then
cat "$CACHE_DIR"/user/generated/terminal/sequences.txt >"$file"
fi
# Copy template
mkdir -p "$CACHE_DIR"/user/generated/terminal
cp "scripts/templates/terminal/sequences.txt" "$CACHE_DIR"/user/generated/terminal/sequences.txt
# Apply colors
for i in "${!colorlist[@]}"; do
sed -i "s/${colorlist[$i]} #/${colorvalues[$i]#\#}/g" "$CACHE_DIR"/user/generated/terminal/sequences.txt
done

sed -i "s/\$alpha/$term_alpha/g" "$CACHE_DIR/user/generated/terminal/sequences.txt"

for file in /dev/pts/*; do
if [[ $file =~ ^/dev/pts/[0-9]+$ ]]; then
cat "$CACHE_DIR"/user/generated/terminal/sequences.txt > "$file"
fi
done
done
}

apply_hyprland() {
# Check if scripts/templates/hypr/hyprland/colors.conf exists
if [ ! -f "scripts/templates/hypr/hyprland/colors.conf" ]; then
echo "Template file not found for Hyprland colors. Skipping that."
return
fi
# Copy template
mkdir -p "$CACHE_DIR"/user/generated/hypr/hyprland
cp "scripts/templates/hypr/hyprland/colors.conf" "$CACHE_DIR"/user/generated/hypr/hyprland/colors.conf
# Apply colors
for i in "${!colorlist[@]}"; do
sed -i "s/{{ ${colorlist[$i]} }}/${colorvalues[$i]#\#}/g" "$CACHE_DIR"/user/generated/hypr/hyprland/colors.conf
done

cp "$CACHE_DIR"/user/generated/hypr/hyprland/colors.conf "$XDG_CONFIG_HOME"/hypr/hyprland/colors.conf
# Check if scripts/templates/hypr/hyprland/colors.conf exists
if [ ! -f "scripts/templates/hypr/hyprland/colors.conf" ]; then
echo "Template file not found for Hyprland colors. Skipping that."
return
fi
# Copy template
mkdir -p "$CACHE_DIR"/user/generated/hypr/hyprland
cp "scripts/templates/hypr/hyprland/colors.conf" "$CACHE_DIR"/user/generated/hypr/hyprland/colors.conf
# Apply colors
for i in "${!colorlist[@]}"; do
sed -i "s/{{ ${colorlist[$i]} }}/${colorvalues[$i]#\#}/g" "$CACHE_DIR"/user/generated/hypr/hyprland/colors.conf
done

cp "$CACHE_DIR"/user/generated/hypr/hyprland/colors.conf "$XDG_CONFIG_HOME"/hypr/hyprland/colors.conf
}

apply_hyprlock() {
# Check if scripts/templates/hypr/hyprlock.conf exists
if [ ! -f "scripts/templates/hypr/hyprlock.conf" ]; then
echo "Template file not found for hyprlock. Skipping that."
return
fi
# Copy template
mkdir -p "$CACHE_DIR"/user/generated/hypr/
cp "scripts/templates/hypr/hyprlock.conf" "$CACHE_DIR"/user/generated/hypr/hyprlock.conf
# Apply colors
# sed -i "s/{{ SWWW_WALL }}/${wallpath_png}/g" "$CACHE_DIR"/user/generated/hypr/hyprlock.conf
for i in "${!colorlist[@]}"; do
sed -i "s/{{ ${colorlist[$i]} }}/${colorvalues[$i]#\#}/g" "$CACHE_DIR"/user/generated/hypr/hyprlock.conf
done

cp "$CACHE_DIR"/user/generated/hypr/hyprlock.conf "$XDG_CONFIG_HOME"/hypr/hyprlock.conf
# Check if scripts/templates/hypr/hyprlock.conf exists
if [ ! -f "scripts/templates/hypr/hyprlock.conf" ]; then
echo "Template file not found for hyprlock. Skipping that."
return
fi
# Copy template
mkdir -p "$CACHE_DIR"/user/generated/hypr/
cp "scripts/templates/hypr/hyprlock.conf" "$CACHE_DIR"/user/generated/hypr/hyprlock.conf
# Apply colors
# sed -i "s/{{ SWWW_WALL }}/${wallpath_png}/g" "$CACHE_DIR"/user/generated/hypr/hyprlock.conf
for i in "${!colorlist[@]}"; do
sed -i "s/{{ ${colorlist[$i]} }}/${colorvalues[$i]#\#}/g" "$CACHE_DIR"/user/generated/hypr/hyprlock.conf
done

cp "$CACHE_DIR"/user/generated/hypr/hyprlock.conf "$XDG_CONFIG_HOME"/hypr/hyprlock.conf
}

apply_lightdark() {
lightdark=$(get_light_dark)
if [ "$lightdark" = "light" ]; then
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
else
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
fi
lightdark=$(get_light_dark)
if [ "$lightdark" = "light" ]; then
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
else
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
fi
}

apply_gtk() { # Using gradience-cli
usegradience=$(sed -n '4p' "$STATE_DIR/user/colormode.txt")
if [[ "$usegradience" = "nogradience" ]]; then
rm "$XDG_CONFIG_HOME/gtk-3.0/gtk.css"
rm "$XDG_CONFIG_HOME/gtk-4.0/gtk.css"
return
fi

# Copy template
mkdir -p "$CACHE_DIR"/user/generated/gradience
cp "scripts/templates/gradience/preset.json" "$CACHE_DIR"/user/generated/gradience/preset.json

# Apply colors
for i in "${!colorlist[@]}"; do
sed -i "s/{{ ${colorlist[$i]} }}/${colorvalues[$i]}/g" "$CACHE_DIR"/user/generated/gradience/preset.json
done

mkdir -p "$XDG_CONFIG_HOME/presets" # create gradience presets folder
gradience-cli apply -p "$CACHE_DIR"/user/generated/gradience/preset.json --gtk both

# And set GTK theme manually as Gradience defaults to light adw-gtk3
# (which is unreadable when broken when you use dark mode)
lightdark=$(get_light_dark)
if [ "$lightdark" = "light" ]; then
gsettings set org.gnome.desktop.interface gtk-theme 'adw-gtk3'
else
gsettings set org.gnome.desktop.interface gtk-theme adw-gtk3-dark
fi
usegradience=$(sed -n '4p' "$STATE_DIR/user/colormode.txt")
if [[ "$usegradience" = "nogradience" ]]; then
rm "$XDG_CONFIG_HOME/gtk-3.0/gtk.css"
rm "$XDG_CONFIG_HOME/gtk-4.0/gtk.css"
return
fi

# Copy template
mkdir -p "$CACHE_DIR"/user/generated/gradience
cp "scripts/templates/gradience/preset.json" "$CACHE_DIR"/user/generated/gradience/preset.json

# Apply colors
for i in "${!colorlist[@]}"; do
sed -i "s/{{ ${colorlist[$i]} }}/${colorvalues[$i]}/g" "$CACHE_DIR"/user/generated/gradience/preset.json
done

mkdir -p "$XDG_CONFIG_HOME/presets" # create gradience presets folder
gradience-cli apply -p "$CACHE_DIR"/user/generated/gradience/preset.json --gtk both

# And set GTK theme manually as Gradience defaults to light adw-gtk3
# (which is unreadable when broken when you use dark mode)
lightdark=$(get_light_dark)
if [ "$lightdark" = "light" ]; then
gsettings set org.gnome.desktop.interface gtk-theme 'adw-gtk3'
else
gsettings set org.gnome.desktop.interface gtk-theme adw-gtk3-dark
fi
}

apply_ags() {
ags run-js "handleStyles(false);"
ags run-js 'openColorScheme.value = true; Utils.timeout(2000, () => openColorScheme.value = false);'
ags run-js "handleStyles(false);"
ags run-js 'openColorScheme.value = true; Utils.timeout(2000, () => openColorScheme.value = false);'
}

apply_qt() {
sh "$CONFIG_DIR/scripts/kvantum/materialQT.sh" # generate kvantum theme
python "$CONFIG_DIR/scripts/kvantum/changeAdwColors.py" # apply config colors
}

colornames=$(cat $STATE_DIR/scss/_material.scss | cut -d: -f1)
colorstrings=$(cat $STATE_DIR/scss/_material.scss | cut -d: -f2 | cut -d ' ' -f2 | cut -d ";" -f1)
IFS=$'\n'
colorlist=( $colornames ) # Array of color names
colorvalues=( $colorstrings ) # Array of color values
colorlist=($colornames) # Array of color names
colorvalues=($colorstrings) # Array of color values

apply_ags &
apply_hyprland &
apply_hyprlock &
apply_lightdark &
apply_gtk &
apply_qt &
apply_fuzzel &
apply_term &
79 changes: 79 additions & 0 deletions .config/ags/scripts/kvantum/adwsvg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import re
import os

def read_scss(file_path):
"""Reads an SCSS file and returns a dictionary of color variables."""
colors = {}
with open(file_path, 'r') as file:
for line in file:
match = re.match(r'\$(\w+):\s*(#[0-9A-Fa-f]{6});', line.strip())
if match:
variable_name, color = match.groups()
colors[variable_name] = color
return colors

def update_svg_colors(svg_path, old_to_new_colors, output_path):
"""
Updates the colors in an SVG file based on the provided color map.

:param svg_path: Path to the SVG file.
:param old_to_new_colors: Dictionary mapping old colors to new colors.
:param output_path: Path to save the updated SVG file.
"""
# Read the SVG content
with open(svg_path, 'r') as file:
svg_content = file.read()

# Replace old colors with new colors
for old_color, new_color in old_to_new_colors.items():
svg_content = re.sub(old_color, new_color, svg_content, flags=re.IGNORECASE)

# Write the updated SVG content to the output file
with open(output_path, 'w') as file:
file.write(svg_content)

print(f"SVG colors have been updated and saved to {output_path}!")

def main():
xdg_config_home = os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))
xdg_state_home = os.environ.get("XDG_STATE_HOME", os.path.expanduser("~/.local/state"))

scss_file = os.path.join(xdg_state_home, "ags", "scss", "_material.scss")
svg_path = os.path.join(xdg_config_home, "Kvantum", "Colloid", "Colloid.svg")
output_path = os.path.join(xdg_config_home, "Kvantum", "MaterialAdw", "MaterialAdw.svg")

# Read colors from the SCSS file
color_data = read_scss(scss_file)

# Specify the old colors and map them to new colors from the SCSS file
old_to_new_colors = {
#'#cccccc': color_data['surfaceDim'], # Map old SVG color to new SCSS color
#'#666666': color_data['surfaceDim'],
'#3c84f7': color_data['primary'],
#'#5a5a5a': color_data['neutral_paletteKeyColor'],
'#000000': color_data['shadow'],
'#f04a50': color_data['error'],
'#4285f4': color_data['primaryFixedDim'],
'#f2f2f2': color_data['background'],
#'#dfdfdf': color_data['surfaceContainerLow'],
'#ffffff': color_data['background'],
'#1e1e1e': color_data['onPrimaryFixed'],
#'#b6b6b6': color_data['surfaceContainer'],
'#333': color_data['inverseSurface'],
'#212121': color_data['onSecondaryFixed'],
'#5b9bf8': color_data['secondaryContainer'],
'#26272a': color_data['term7'],
#'#b3b3b3': color_data['surfaceBright'],
#'#b74aff': color_data['tertiary'],
#'#989898': color_data['surfaceContainerHighest'],
#'#c1c1c1': color_data['surfaceContainerHigh'],
'#444444': color_data['onBackground'],
'#333333': color_data['onPrimaryFixed'],
}

# Update the SVG colors
update_svg_colors(svg_path, old_to_new_colors, output_path)

if __name__ == "__main__":
main()

Loading