Roko's improvments
This commit is contained in:
parent
3e259fb09e
commit
0cdccf7d72
|
@ -4,74 +4,74 @@
|
||||||
pidof -sq -o %PPID -x "$(basename "$0")" && exit
|
pidof -sq -o %PPID -x "$(basename "$0")" && exit
|
||||||
|
|
||||||
# Set the directory paths
|
# Set the directory paths
|
||||||
target_themes_dir="$HOME/.themes"
|
flatpak_themes_dir="$HOME/.themes"
|
||||||
target_icons_dir="$HOME/.icons"
|
flatpak_icons_dir="$HOME/.icons"
|
||||||
|
|
||||||
# Create target directories if they don't exist
|
# Create flatpak icons & themes directories if they don't exist
|
||||||
mkdir -p "$target_themes_dir" "$target_icons_dir" ||
|
mkdir -p "$flatpak_themes_dir" "$flatpak_icons_dir" ||
|
||||||
{ echo "failed to make directories $target_themes_dir & $target_icons_dir"; exit 1; }
|
{ echo "failed to make directories $flatpak_themes_dir & $flatpak_icons_dir"; exit 1; }
|
||||||
|
|
||||||
sync_theme() {
|
sync_theme() {
|
||||||
# Get the current system theme
|
# Get the current system theme
|
||||||
theme_name=$(xfconf-query -c xsettings -p /Net/ThemeName)
|
current_theme=$(xfconf-query -c xsettings -p /Net/ThemeName)
|
||||||
|
|
||||||
# Cleanup source & target themes directories
|
# Enable syncing the current theme with xfwm4 theme if not already enabled
|
||||||
source_themes_dirs=()
|
[ "$(xfconf-query -c xsettings -p /Xfce/SyncThemes)" != 'true' ] && xfconf-query -c xsettings -p /Xfce/SyncThemes -n -t bool -s true
|
||||||
rm -rf "$target_themes_dir"/*
|
# 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"
|
||||||
|
|
||||||
# Go through each item in $XDG_DATA_DIRS to find all other directories where
|
|
||||||
# themes are stored, and save only the current one to source_themes_dirs
|
|
||||||
while read -r dir; do
|
|
||||||
themes_subdir=${dir%/}/themes/${theme_name}
|
|
||||||
[ -d "$themes_subdir" ] && source_themes_dirs+=("$themes_subdir")
|
|
||||||
done < <(printf '%s:%s\n' "$XDG_DATA_DIRS" "$HOME/.local/share" | tr ':' '\n' | sort -u)
|
|
||||||
|
|
||||||
rsync -av --delete --progress "${source_themes_dirs[@]}" "$target_themes_dir"
|
# Cleanup flatpak_themes_dir
|
||||||
echo "Directory $target_themes_dir is synchronized with source directories"
|
rm -rf "${flatpak_themes_dir:?}"/*
|
||||||
|
|
||||||
# Enable syncing the current theme with xfwm4 if not already enabled
|
# Go through each item in $XDG_DATA_DIRS to find the directory where
|
||||||
[ "$(xfconf-query -c xsettings -p /Xfce/SyncThemes)" != 'true' ] && xfconf-query -c xsettings -p /Xfce/SyncThemes -n -t bool -s true
|
# the current theme is stored, and copy/sync them to flatpak_themes_dir
|
||||||
# Apply the current theme with gsettings
|
while read -r dir; do
|
||||||
gsettings set org.gnome.desktop.interface gtk-theme "$theme_name"
|
current_theme_dir=${dir%/}/themes/${current_theme}
|
||||||
# Apply the current theme for the all the GTK flatpaks
|
if [ -d "$current_theme_dir" ]; then
|
||||||
flatpak override --user --env=GTK_THEME="$theme_name"
|
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')
|
||||||
}
|
}
|
||||||
|
|
||||||
sync_icons() {
|
sync_icons() {
|
||||||
# Get the current icons theme
|
# Get the current icon theme
|
||||||
icons_theme_name=$(xfconf-query -c xsettings -p /Net/IconThemeName)
|
current_icon_theme=$(xfconf-query -c xsettings -p /Net/IconThemeName)
|
||||||
|
|
||||||
# Cleanup source & target themes directories
|
# Cleanup flatpak_icons_dir
|
||||||
source_icons_dirs=()
|
rm -rf "${flatpak_icons_dir:?}"/*
|
||||||
rm -rf "$target_icons_dir"/*
|
|
||||||
|
|
||||||
# Go through each item in $XDG_DATA_DIRS to find all other directories where
|
# Go through each item in $XDG_DATA_DIRS to find the directory where
|
||||||
# icons are stored, and save only the current one to source_icons_dirs
|
# the current icon theme is stored, and copy/sync them to flatpak_icons_dir
|
||||||
while read -r dir; do
|
while read -r dir; do
|
||||||
icons_subdir=${dir%/}/icons/${icons_theme_name}
|
current_icon_theme_dir=${dir%/}/icons/${current_icon_theme}
|
||||||
[ -d "$icons_subdir" ] && source_icons_dirs+=("$icons_subdir")
|
if [ -d "$current_icon_theme_dir" ]; then
|
||||||
done < <(printf '%s:%s\n' "$XDG_DATA_DIRS" "$HOME/.local/share" | tr ':' '\n' | sort -u)
|
rsync -av --delete --progress "$current_icon_theme_dir" "$flatpak_icons_dir"
|
||||||
|
break
|
||||||
rsync -av --delete --progress "${source_icons_dirs[@]}" "$target_icons_dir"
|
fi
|
||||||
echo "Directory $target_icons_dir is synchronized with source directories"
|
done < <(printf '%s:%s\n' "$HOME/.local/share" "$XDG_DATA_DIRS" | tr ':' '\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
sync_font() {
|
sync_font() {
|
||||||
# Get the current system font
|
# Get the current system font
|
||||||
font=$(xfconf-query -c xsettings -p /Gtk/FontName)
|
font=$(xfconf-query -c xsettings -p /Gtk/FontName)
|
||||||
# Apply the same font for the title of xfce windows
|
# Apply the same font for the title of xfce windows
|
||||||
xfconf-query -c xfwm4 -p /general/title_font -n -t string -s "$font"
|
xfconf-query -c xfwm4 -p /general/title_font -n -t string -s "$font"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Initial synchronization
|
||||||
sync_theme
|
sync_theme
|
||||||
sync_icons
|
sync_icons
|
||||||
sync_font
|
sync_font
|
||||||
|
|
||||||
# Monitor when the user changes their system theme or font in XFCE and sync them as needed
|
# Monitor when the user changes their system theme or icons or font in XFCE and sync them as needed
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
case "$line" in
|
case "$line" in
|
||||||
'set: /Net/ThemeName') sync_theme ;;
|
'set: /Net/ThemeName') sync_theme ;;
|
||||||
'set: /Net/IconThemeName') sync_icons ;;
|
'set: /Net/IconThemeName') sync_icons ;;
|
||||||
'set: /Gtk/FontName') sync_font ;;
|
'set: /Gtk/FontName') sync_font ;;
|
||||||
esac
|
esac
|
||||||
done < <(xfconf-query -c xsettings -m)
|
done < <(xfconf-query -c xsettings -m)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user