2022-09-18 20:05:57 +00:00
|
|
|
#!/bin/bash
|
2023-08-03 14:40:26 +00:00
|
|
|
|
2022-09-22 14:51:45 +00:00
|
|
|
sync_theme() {
|
|
|
|
# Get the current system theme
|
|
|
|
theme=$(xfconf-query -c xsettings -p /Net/ThemeName)
|
2023-08-03 14:40:26 +00:00
|
|
|
|
|
|
|
# Enable syncing the current theme with xfwm4
|
|
|
|
if [ "$(xfconf-query -c xsettings -p /Xfce/SyncThemes)" != 'true' ]; then
|
|
|
|
xfconf-query -c xsettings -p /Xfce/SyncThemes -n -t bool -s true
|
|
|
|
fi
|
|
|
|
|
2022-09-22 14:51:45 +00:00
|
|
|
# Apply the current theme with gsettings
|
|
|
|
gsettings set org.gnome.desktop.interface gtk-theme "$theme"
|
2023-08-03 14:40:26 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
if [ ! -d "$flatpak_override_dir" ]; then
|
|
|
|
mkdir -p "$flatpak_override_dir" || { echo 'Failed creating directory!'; return 1; }
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Write the theme configuration to the global override file
|
|
|
|
echo "[Environment]
|
|
|
|
GTK_THEME=$theme" > "$flatpak_override_dir/global"
|
2022-09-22 14:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sync_font() {
|
|
|
|
# Get the current system font
|
|
|
|
font=$(xfconf-query -c xsettings -p /Gtk/FontName)
|
2023-08-03 14:40:26 +00:00
|
|
|
|
2022-09-22 14:51:45 +00:00
|
|
|
# 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
|
|
|
|
2022-09-22 14:51:45 +00:00
|
|
|
sync_theme
|
|
|
|
sync_font
|
|
|
|
|
2023-08-03 14:40:26 +00:00
|
|
|
# Monitor when the user changes their system theme or font in XFCE and sync them as needed
|
2022-09-22 14:51:45 +00:00
|
|
|
while read -r line; do
|
2022-09-18 22:40:44 +00:00
|
|
|
case "$line" in
|
2022-09-22 14:51:45 +00:00
|
|
|
'set: /Net/ThemeName') sync_theme ;;
|
|
|
|
'set: /Gtk/FontName') sync_font ;;
|
2022-09-18 22:40:44 +00:00
|
|
|
esac
|
2022-09-21 17:56:17 +00:00
|
|
|
done < <(xfconf-query -c xsettings -m)
|