iso-profiles-settings/tromjaro/xfce/desktop-overlay/usr/bin/fix-theming

38 lines
1.6 KiB
Plaintext
Raw Normal View History

2022-09-01 23:31:12 +00:00
#!/bin/sh
sync_theme() {
# Get the current system theme
theme=$(xfconf-query -c xsettings -p /Net/ThemeName)
# Find the best match for the xfwm4 theme that corresponds with the current system theme
xfwm4_theme=$(find /usr/share/themes/ /usr/local/share/themes/ "$HOME"/.themes/ "$HOME"/.local/share/themes/ -mindepth 2 -maxdepth 2 -type d -name xfwm4 -printf '%h\n' 2>/dev/null | grep -o "/${theme}[^/]*$" | sort | head -n1)
# If a match is not found then use the Default theme
[ -z "$xfwm4_theme" ] && xfwm4_theme='Default'
# Apply the xfwm4 theme
xfconf-query -c xfwm4 -p /general/theme -n -t string -s "${xfwm4_theme#/}"
# Apply the current theme with gsettings
gsettings set org.gnome.desktop.interface gtk-theme "$theme"
}
sync_icon_theme() {
# Get the current icon theme
icon_theme=$(xfconf-query -c xsettings -p /Net/IconThemeName)
# Apply the same theme in qt5ct and qt6ct configuration
sed -i "s/^icon_theme=.*$/icon_theme=$icon_theme/" "$HOME"/.config/qt5ct/qt5ct.conf
sed -i "s/^icon_theme=.*$/icon_theme=$icon_theme/" "$HOME"/.config/qt6ct/qt6ct.conf
}
while :; do
# Get the current system theme
theme_new=$(xfconf-query -c xsettings -p /Net/ThemeName)
# Get the current icon theme
icon_theme_new=$(xfconf-query -c xsettings -p /Net/IconThemeName)
# Run sync_theme if the new system theme doesn't match the previous one
[ "$theme_new" != "$theme_prev" ] && sync_theme
# Run sync_icon_theme if the new icon theme doesn't match the previous one
[ "$icon_theme_new" != "$icon_theme_prev" ] && sync_icon_theme
# The new values become the previous values
theme_prev=$theme_new
icon_theme_prev=$icon_theme_new
sleep 3
done