Don't set the XFWM theme twice

Now the script won't set the XFWM theme twice on hiDPI systems every time the user changes their theme.
Also replaced read only variables inside loops with mutable ones.
This commit is contained in:
Rokosun 2023-10-25 12:52:28 +02:00
parent b741df884e
commit 0600a8f119

View File

@ -71,22 +71,27 @@ set_xfwm_theme() {
# Use the highDPI variant of the XFWM theme # Use the highDPI variant of the XFWM theme
use_hdpi_theme_variant() { 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 for variant in xhdpi hdpi; do
# If this variant of the theme is already enabled then break out of the loop # 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 # 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 if theme_exists "$highDPI_theme"; then
set_xfwm_theme "$highDPI_theme" 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" 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 break
fi fi
done 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 # Use the normal variant of the XFWM theme
@ -98,7 +103,7 @@ use_normal_theme_variant() {
[ "${current_xfwm_theme##*-}" != "$variant" ] && continue [ "${current_xfwm_theme##*-}" != "$variant" ] && continue
# Store the name for the normal variant of this theme in normal_theme variable # 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 if theme_exists "$normal_theme"; then
set_xfwm_theme "$normal_theme" set_xfwm_theme "$normal_theme"
@ -156,10 +161,12 @@ sync_theme() {
# Apply the current theme for XFWM unless it's initial_sync on system reboot # Apply the current theme for XFWM unless it's initial_sync on system reboot
if [ "$1" != 'initial_sync' ]; then 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 # 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 fi
# Cleanup flatpak_themes_dir and remove ~/.config/gtk-4.0 # Cleanup flatpak_themes_dir and remove ~/.config/gtk-4.0