fixes-package/bin/periodic/fix-theming

78 lines
2.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2023-08-06 00:14:02 +00:00
# Exit out if the same script is already running in the background
pidof -sq -o %PPID -x "$(basename "$0")" && exit
# Set the directory paths
2023-08-06 13:08:58 +00:00
flatpak_themes_dir="$HOME/.themes"
flatpak_icons_dir="$HOME/.icons"
2023-08-06 00:14:02 +00:00
2023-08-06 13:08:58 +00:00
# Create flatpak icons & themes directories if they don't exist
mkdir -p "$flatpak_themes_dir" "$flatpak_icons_dir" ||
{ echo "failed to make directories $flatpak_themes_dir & $flatpak_icons_dir"; exit 1; }
2023-08-06 00:14:02 +00:00
sync_theme() {
2023-08-06 13:08:58 +00:00
# Get the current system theme
current_theme=$(xfconf-query -c xsettings -p /Net/ThemeName)
2023-08-06 00:14:02 +00:00
2023-08-06 13:08:58 +00:00
# Enable syncing the current theme with xfwm4 theme if not already enabled
[ "$(xfconf-query -c xsettings -p /Xfce/SyncThemes)" != 'true' ] && xfconf-query -c xsettings -p /Xfce/SyncThemes -n -t bool -s true
# Apply the current theme with gsettings
gsettings set org.gnome.desktop.interface gtk-theme "$current_theme"
# Apply the current theme for GTK and Libadwaita apps on flatpak
flatpak override --user --env=GTK_THEME="$current_theme"
2023-08-06 00:14:02 +00:00
2023-08-06 13:08:58 +00:00
# Cleanup flatpak_themes_dir
rm -rf "${flatpak_themes_dir:?}"/*
2023-08-06 00:14:02 +00:00
2023-08-06 13:08:58 +00:00
# Go through each item in $XDG_DATA_DIRS to find the directory where
# the current theme is stored, and copy/sync them to flatpak_themes_dir
while read -r dir; do
current_theme_dir=${dir%/}/themes/${current_theme}
if [ -d "$current_theme_dir" ]; then
rsync -av --delete --progress "$current_theme_dir" "$flatpak_themes_dir"
break
fi
done < <(printf '%s:%s\n' "$HOME/.local/share" "$XDG_DATA_DIRS" | tr ':' '\n')
2023-08-06 00:14:02 +00:00
}
sync_icons() {
2023-08-06 13:08:58 +00:00
# Get the current icon theme
current_icon_theme=$(xfconf-query -c xsettings -p /Net/IconThemeName)
2023-08-06 00:14:02 +00:00
2023-08-06 13:08:58 +00:00
# Cleanup flatpak_icons_dir
rm -rf "${flatpak_icons_dir:?}"/*
2023-08-06 00:14:02 +00:00
2023-08-06 13:08:58 +00:00
# Go through each item in $XDG_DATA_DIRS to find the directory where
# the current icon theme is stored, and copy/sync them to flatpak_icons_dir
while read -r dir; do
current_icon_theme_dir=${dir%/}/icons/${current_icon_theme}
if [ -d "$current_icon_theme_dir" ]; then
rsync -av --delete --progress "$current_icon_theme_dir" "$flatpak_icons_dir"
break
fi
done < <(printf '%s:%s\n' "$HOME/.local/share" "$XDG_DATA_DIRS" | tr ':' '\n')
}
sync_font() {
2023-08-06 13:08:58 +00:00
# Get the current system font
font=$(xfconf-query -c xsettings -p /Gtk/FontName)
# Apply the same font for the title of xfce windows
xfconf-query -c xfwm4 -p /general/title_font -n -t string -s "$font"
}
2022-09-15 23:14:20 +00:00
2023-08-06 13:08:58 +00:00
# Initial synchronization
sync_theme
2023-08-06 00:14:02 +00:00
sync_icons
sync_font
2023-08-06 13:08:58 +00:00
# Monitor when the user changes their system theme or icons or font in XFCE and sync them as needed
while read -r line; do
2023-08-06 13:08:58 +00:00
case "$line" in
'set: /Net/ThemeName') sync_theme ;;
'set: /Net/IconThemeName') sync_icons ;;
'set: /Gtk/FontName') sync_font ;;
esac
done < <(xfconf-query -c xsettings -m)