fixes-package/bin/periodic/fix-theming
2023-08-03 16:42:27 +02:00

39 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
sync_theme() {
# Get the current system theme
theme=$(xfconf-query -c xsettings -p /Net/ThemeName)
# Enable syncing the current theme with xfwm4 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 "$theme"
# Apply the current theme for GTK apps in flatpak
# Define the path to the flatpak override directory
flatpak_override_dir="$HOME/.local/share/flatpak/overrides"
# Create the directory if it doesn't exist
[ -d "$flatpak_override_dir" ] || mkdir -p "$flatpak_override_dir" || { echo 'failed creating directory!'; return 1; }
# Write the theme configuration to the global override file
echo "[Environment]
GTK_THEME=$theme" > "$flatpak_override_dir/global"
}
sync_font() {
# 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"
}
sync_theme
sync_font
# Monitor when the user changes their system theme or font in XFCE and sync them as needed
while read -r line; do
case "$line" in
'set: /Net/ThemeName') sync_theme ;;
'set: /Gtk/FontName') sync_font ;;
esac
done < <(xfconf-query -c xsettings -m)