|
|
|
@ -1,21 +1,45 @@
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
|
|
|
|
|
|
# This script will sync your XFCE theme & font to work systemwide and in
|
|
|
|
|
# a consistent manner accross different apps. It also improves
|
|
|
|
|
# the highDPI scaling to give you a better experience.
|
|
|
|
|
|
|
|
|
|
# Exit out if the same script is already running in the background
|
|
|
|
|
pidof -sq -o %PPID -x "$(basename "$0")" && exit
|
|
|
|
|
|
|
|
|
|
# Set the directory/file paths
|
|
|
|
|
declare -r flatpak_themes_dir="$HOME/.themes"
|
|
|
|
|
declare -r flatpak_icons_dir="$HOME/.icons"
|
|
|
|
|
declare -r config_dir="${XDG_CONFIG_HOME:-$HOME/.config}"
|
|
|
|
|
declare -r profile="$HOME/.profile"
|
|
|
|
|
|
|
|
|
|
# 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; }
|
|
|
|
|
# Create directories if they don't exist
|
|
|
|
|
mkdir -p "$flatpak_themes_dir" "$config_dir" ||
|
|
|
|
|
{ echo "failed to make directories $flatpak_themes_dir & $config_dir"; exit 1; }
|
|
|
|
|
|
|
|
|
|
# Enable option for syncing the current theme with XFWM 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
|
|
|
|
|
|
|
|
|
|
# Make sure ~/.profile is sourced inside ~/.bash_profile and ~/.zprofile
|
|
|
|
|
source_profile() {
|
|
|
|
|
for file in "$HOME/.bash_profile" "$HOME/.zprofile"; do
|
|
|
|
|
# Continue looping if it is already sourced
|
|
|
|
|
grep -Exq '\s*(.*&& )?\. "?\$HOME"?/\.profile"?\s*' "$file" ||
|
|
|
|
|
grep -Exq "\s*(.*&& )?\. ~/\.profile\s*" "$file" && continue
|
|
|
|
|
# If not then source it
|
|
|
|
|
if grep -q '\S' "$file"; then
|
|
|
|
|
# shellcheck disable=SC2015
|
|
|
|
|
tail -n1 "$file" | grep -qx '\s*' &&
|
|
|
|
|
local -r begin='' || local -r begin='\n'
|
|
|
|
|
printf '%b[ -f "$HOME/.profile" ] && . "$HOME/.profile"\n' "$begin" >> "$file"
|
|
|
|
|
else
|
|
|
|
|
echo '[ -f "$HOME/.profile" ] && . "$HOME/.profile"' > "$file"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
source_profile
|
|
|
|
|
|
|
|
|
|
xdg_directory_lookup() {
|
|
|
|
|
# Go through each item in $XDG_DATA_DIRS and find the subdirectory $1
|
|
|
|
|
while read -r dir; do
|
|
|
|
@ -43,7 +67,7 @@ profile_set_variable() {
|
|
|
|
|
# Set the variable to the correct value under a comment mentioning this script
|
|
|
|
|
if grep -xq '\s*#\s*Values set by the fix-theming script\s*' "$profile"; then
|
|
|
|
|
sed -i "/^\s*#\s*Values set by the fix-theming script\s*$/a export $1=$2" "$profile"
|
|
|
|
|
elif grep -q '\s' "$profile"; then
|
|
|
|
|
elif grep -q '\S' "$profile"; then
|
|
|
|
|
# shellcheck disable=SC2015
|
|
|
|
|
tail -n1 "$profile" | grep -qx '\s*' &&
|
|
|
|
|
local -r begin='' || local -r begin='\n'
|
|
|
|
@ -71,22 +95,27 @@ set_xfwm_theme() {
|
|
|
|
|
|
|
|
|
|
# Use the highDPI variant of the XFWM theme
|
|
|
|
|
use_hdpi_theme_variant() {
|
|
|
|
|
local -r current_xfwm_theme=$(xfconf-query -c xfwm4 -p /general/theme)
|
|
|
|
|
# shellcheck disable=SC2015
|
|
|
|
|
[ -n "$1" ] && local -r xfwm_theme="$1" ||
|
|
|
|
|
local -r xfwm_theme=$(xfconf-query -c xfwm4 -p /general/theme)
|
|
|
|
|
|
|
|
|
|
for variant in xhdpi hdpi; do
|
|
|
|
|
# If this variant of the theme is already enabled then break out of the loop
|
|
|
|
|
[ "${current_xfwm_theme##*-}" = "$variant" ] && break
|
|
|
|
|
[ "${xfwm_theme##*-}" = "$variant" ] && break
|
|
|
|
|
|
|
|
|
|
# Store the name for this variant of the theme in highDPI_theme variable
|
|
|
|
|
local -r highDPI_theme=$current_xfwm_theme-$variant
|
|
|
|
|
local highDPI_theme=$xfwm_theme-$variant
|
|
|
|
|
|
|
|
|
|
if theme_exists "$highDPI_theme"; then
|
|
|
|
|
set_xfwm_theme "$highDPI_theme"
|
|
|
|
|
[ "$1" != 'disable_notification' ] &&
|
|
|
|
|
[ -z "$1" ] &&
|
|
|
|
|
notify-send "XFWM theme changed to $highDPI_theme" "Changed to the highDPI variant of your chosen theme because you've enabled highDPI on your system"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
if ! theme_exists "$highDPI_theme"; then
|
|
|
|
|
[ -n "$1" ] && theme_exists "$1" && set_xfwm_theme "$1"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Use the normal variant of the XFWM theme
|
|
|
|
@ -98,7 +127,7 @@ use_normal_theme_variant() {
|
|
|
|
|
[ "${current_xfwm_theme##*-}" != "$variant" ] && continue
|
|
|
|
|
|
|
|
|
|
# Store the name for the normal variant of this theme in normal_theme variable
|
|
|
|
|
local -r normal_theme=${current_xfwm_theme%-"$variant"}
|
|
|
|
|
local normal_theme=${current_xfwm_theme%-"$variant"}
|
|
|
|
|
|
|
|
|
|
if theme_exists "$normal_theme"; then
|
|
|
|
|
set_xfwm_theme "$normal_theme"
|
|
|
|
@ -156,20 +185,26 @@ sync_theme() {
|
|
|
|
|
|
|
|
|
|
# Apply the current theme for XFWM unless it's initial_sync on system reboot
|
|
|
|
|
if [ "$1" != 'initial_sync' ]; then
|
|
|
|
|
set_xfwm_theme "$current_theme"
|
|
|
|
|
|
|
|
|
|
# Use the highDPI variant of the XFWM theme if the current_window_scaling factor is 2
|
|
|
|
|
[ "$current_window_scaling" -eq '2' ] && use_hdpi_theme_variant 'disable_notification'
|
|
|
|
|
if [ "$current_window_scaling" -eq '2' ]; then
|
|
|
|
|
use_hdpi_theme_variant "$current_theme"
|
|
|
|
|
else
|
|
|
|
|
set_xfwm_theme "$current_theme"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Cleanup flatpak_themes_dir
|
|
|
|
|
rm -rf "${flatpak_themes_dir:?}"/*
|
|
|
|
|
# Cleanup flatpak_themes_dir and remove ~/.config/gtk-4.0
|
|
|
|
|
rm -rf "${flatpak_themes_dir:?}"/{*,.*} "$config_dir/gtk-4.0"
|
|
|
|
|
|
|
|
|
|
# Find the directory where the current theme is stored
|
|
|
|
|
local -r current_theme_dir=$(xdg_directory_lookup "themes/$current_theme")
|
|
|
|
|
# Copy/sync current_theme_dir to flatpak_themes_dir
|
|
|
|
|
[ -d "$current_theme_dir" ] &&
|
|
|
|
|
|
|
|
|
|
if [ -d "$current_theme_dir" ]; then
|
|
|
|
|
# Copy/sync current_theme_dir to flatpak_themes_dir
|
|
|
|
|
rsync -av --delete --progress "$current_theme_dir" "$flatpak_themes_dir"
|
|
|
|
|
# Create symlink for gtk-4.0 directory
|
|
|
|
|
ln -s "$current_theme_dir/gtk-4.0" "$config_dir"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sync_font() {
|
|
|
|
@ -183,7 +218,8 @@ sync_font() {
|
|
|
|
|
sync_theme 'initial_sync'
|
|
|
|
|
sync_font
|
|
|
|
|
|
|
|
|
|
# Monitor when the user changes their system theme/icons/font in XFCE and sync them as needed
|
|
|
|
|
# Monitor when the user changes their system theme, font or
|
|
|
|
|
# DPI setting in XFCE and sync them as needed
|
|
|
|
|
while read -r line; do
|
|
|
|
|
case "$line" in
|
|
|
|
|
'set: /Net/ThemeName') sync_theme ;;
|
|
|
|
|