Don't change XFWM theme or mouse cursor size on reboot
Also made the code easier to read by using descriptive functions and read-only variables. Removed some unnecessary comments that cluttered the code.
This commit is contained in:
parent
43221f6357
commit
af5514884e
|
@ -4,21 +4,22 @@
|
||||||
pidof -sq -o %PPID -x "$(basename "$0")" && exit
|
pidof -sq -o %PPID -x "$(basename "$0")" && exit
|
||||||
|
|
||||||
# Set the directory/file paths
|
# Set the directory/file paths
|
||||||
flatpak_themes_dir="$HOME/.themes"
|
declare -r flatpak_themes_dir="$HOME/.themes"
|
||||||
flatpak_icons_dir="$HOME/.icons"
|
declare -r flatpak_icons_dir="$HOME/.icons"
|
||||||
profile="$HOME/.profile"
|
declare -r profile="$HOME/.profile"
|
||||||
|
|
||||||
# Create flatpak icons & themes directories if they don't exist
|
# Create flatpak icons & themes directories if they don't exist
|
||||||
mkdir -p "$flatpak_themes_dir" "$flatpak_icons_dir" ||
|
mkdir -p "$flatpak_themes_dir" "$flatpak_icons_dir" ||
|
||||||
{ echo "failed to make directories $flatpak_themes_dir & $flatpak_icons_dir"; exit 1; }
|
{ echo "failed to make directories $flatpak_themes_dir & $flatpak_icons_dir"; exit 1; }
|
||||||
|
|
||||||
# Enable option for syncing the current theme with XFWM theme if not already enabled
|
# 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
|
[ "$(xfconf-query -c xsettings -p /Xfce/SyncThemes)" != 'true' ] &&
|
||||||
|
xfconf-query -c xsettings -p /Xfce/SyncThemes -n -t bool -s true
|
||||||
|
|
||||||
xdg_directory_lookup() {
|
xdg_directory_lookup() {
|
||||||
# Go through each item in $XDG_DATA_DIRS and find the subdirectory $1
|
# Go through each item in $XDG_DATA_DIRS and find the subdirectory $1
|
||||||
while read -r dir; do
|
while read -r dir; do
|
||||||
subdir="${dir%/}/$1"
|
local subdir="${dir%/}/$1"
|
||||||
if [ -d "$subdir" ]; then
|
if [ -d "$subdir" ]; then
|
||||||
echo "$subdir"
|
echo "$subdir"
|
||||||
break
|
break
|
||||||
|
@ -26,10 +27,16 @@ xdg_directory_lookup() {
|
||||||
done < <(printf '%s:%s\n' "$HOME/.local/share" "$XDG_DATA_DIRS" | tr ':' '\n')
|
done < <(printf '%s:%s\n' "$HOME/.local/share" "$XDG_DATA_DIRS" | tr ':' '\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
theme_exists() {
|
||||||
|
local -r theme_dir=$(xdg_directory_lookup "themes/$1")
|
||||||
|
[ -d "$theme_dir" ]
|
||||||
|
}
|
||||||
|
|
||||||
# Function for setting variables in ~/.profile
|
# Function for setting variables in ~/.profile
|
||||||
profile_set_variable() {
|
profile_set_variable() {
|
||||||
# Return if the variable is already set to the correct value
|
# Return if the variable is already set to the correct value
|
||||||
grep -xq "\s*export\s\+$1=$2\s*" "$profile" && return
|
grep -xq "\s*export\s\+$1=$2\s*" "$profile" && return
|
||||||
|
|
||||||
# If the variable is set to a different value then remove that line
|
# If the variable is set to a different value then remove that line
|
||||||
grep -q "^\s*export\s\+$1=" "$profile" && sed -i "/^\s*export\s\+$1=/d" "$profile"
|
grep -q "^\s*export\s\+$1=" "$profile" && sed -i "/^\s*export\s\+$1=/d" "$profile"
|
||||||
|
|
||||||
|
@ -37,85 +44,109 @@ profile_set_variable() {
|
||||||
if grep -xq '\s*#\s*Values set by the fix-theming script\s*' "$profile"; then
|
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"
|
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
|
||||||
tail -n1 "$profile" | grep -qx '\s*' && begin='' || begin='\n'
|
# shellcheck disable=SC2015
|
||||||
|
tail -n1 "$profile" | grep -qx '\s*' &&
|
||||||
|
local -r begin='' || local -r begin='\n'
|
||||||
printf '%b# Values set by the fix-theming script\nexport %s=%s\n' "$begin" "$1" "$2" >> "$profile"
|
printf '%b# Values set by the fix-theming script\nexport %s=%s\n' "$begin" "$1" "$2" >> "$profile"
|
||||||
else
|
else
|
||||||
printf '# Values set by the fix-theming script\nexport %s=%s\n' "$1" "$2" > "$profile"
|
printf '# Values set by the fix-theming script\nexport %s=%s\n' "$1" "$2" > "$profile"
|
||||||
fi
|
fi
|
||||||
# Set variable logout_required to true
|
|
||||||
logout_required='true'
|
logout_required='true'
|
||||||
}
|
}
|
||||||
|
|
||||||
hdpi_theme_fix() {
|
set_QT_scaling() {
|
||||||
# Get the current window scaling factor (highDPI setting)
|
|
||||||
current_scaling=$(xfconf-query -c xsettings -p /Gdk/WindowScalingFactor)
|
|
||||||
# Get the current XFWM theme
|
|
||||||
current_xfwm_theme=$(xfconf-query -c xfwm4 -p /general/theme)
|
|
||||||
# Get the current mouse cursor size
|
|
||||||
cursor_size=$(xfconf-query -c xsettings -p /Gtk/CursorThemeSize)
|
|
||||||
|
|
||||||
unset logout_required
|
|
||||||
|
|
||||||
if [ "$current_scaling" -eq '2' ]; then
|
|
||||||
# Increase mouse cursor size if it's equal to 25
|
|
||||||
if [ "$cursor_size" -eq 25 ]; then
|
|
||||||
xfconf-query -c xsettings -p /Gtk/CursorThemeSize -s '45'
|
|
||||||
notify-send 'Mouse cursor size increased to 45' "Changed to a larger mouse cursor because you've enabled highDPI on your system"
|
|
||||||
fi
|
|
||||||
# Increase scaling for QT apps
|
|
||||||
for var in QT_SCALE_FACTOR QT_AUTO_SCREEN_SCALE_FACTOR QT_ENABLE_HIGHDPI_SCALING; do
|
for var in QT_SCALE_FACTOR QT_AUTO_SCREEN_SCALE_FACTOR QT_ENABLE_HIGHDPI_SCALING; do
|
||||||
profile_set_variable "$var" 2
|
profile_set_variable "$var" "$1"
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
set_cursor_size() {
|
||||||
|
xfconf-query -c xsettings -p /Gtk/CursorThemeSize -s "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
set_xfwm_theme() {
|
||||||
|
xfconf-query -c xfwm4 -p /general/theme -n -t string -s "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Use the highDPI variant of the XFWM theme
|
||||||
|
use_hdpi_theme_variant() {
|
||||||
|
local -r current_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
|
[ "${current_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
|
||||||
highDPI_theme=$current_xfwm_theme-$variant
|
local -r highDPI_theme=$current_xfwm_theme-$variant
|
||||||
# Find the directory where highDPI_theme is stored
|
|
||||||
highDPI_theme_dir=$(xdg_directory_lookup "themes/$highDPI_theme")
|
if theme_exists "$highDPI_theme"; then
|
||||||
# If this directory exists then change to that theme for XFWM
|
set_xfwm_theme "$highDPI_theme"
|
||||||
if [ -d "$highDPI_theme_dir" ]; then
|
[ "$1" != 'disable_notification' ] &&
|
||||||
xfconf-query -c xfwm4 -p /general/theme -n -t string -s "$highDPI_theme"
|
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"
|
||||||
[ "$1" != 'no_hdpi_notification' ] && 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
|
||||||
else
|
}
|
||||||
# Decrease mouse cursor size if it's equal to 45
|
|
||||||
if [ "$cursor_size" -eq 45 ]; then
|
# Use the normal variant of the XFWM theme
|
||||||
xfconf-query -c xsettings -p /Gtk/CursorThemeSize -s '25'
|
use_normal_theme_variant() {
|
||||||
notify-send 'Mouse cursor size decreased to 25' "Changed to a smaller mouse cursor because you've disabled highDPI on your system"
|
local -r current_xfwm_theme=$(xfconf-query -c xfwm4 -p /general/theme)
|
||||||
fi
|
|
||||||
# Decrease scaling for QT apps
|
|
||||||
unset logout_required
|
|
||||||
for var in QT_SCALE_FACTOR QT_AUTO_SCREEN_SCALE_FACTOR QT_ENABLE_HIGHDPI_SCALING; do
|
|
||||||
profile_set_variable "$var" 1
|
|
||||||
done
|
|
||||||
for variant in xhdpi hdpi; do
|
for variant in xhdpi hdpi; do
|
||||||
# Continue looping if this (highDPI) variant of the theme is not enabled
|
# Continue looping if this (highDPI) variant of the theme is not enabled
|
||||||
[ "${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
|
||||||
normal_theme=${current_xfwm_theme%-"$variant"}
|
local -r normal_theme=${current_xfwm_theme%-"$variant"}
|
||||||
# Find the directory where normal_theme is stored
|
|
||||||
normal_theme_dir=$(xdg_directory_lookup "themes/$normal_theme")
|
if theme_exists "$normal_theme"; then
|
||||||
# If this directory exists then change to that theme for XFWM
|
set_xfwm_theme "$normal_theme"
|
||||||
if [ -d "$normal_theme_dir" ]; then
|
|
||||||
xfconf-query -c xfwm4 -p /general/theme -n -t string -s "$normal_theme"
|
|
||||||
notify-send "XFWM theme changed to $normal_theme" "Changed to the normal variant of your chosen theme because you've disabled highDPI on your system"
|
notify-send "XFWM theme changed to $normal_theme" "Changed to the normal variant of your chosen theme because you've disabled highDPI on your system"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Change XFWM theme, QT apps scaling, and mouse cursor size according to
|
||||||
|
# the user's current window scaling (highDPI setting)
|
||||||
|
hdpi_theme_fix() {
|
||||||
|
local -r current_window_scaling=$(xfconf-query -c xsettings -p /Gdk/WindowScalingFactor)
|
||||||
|
local -r current_cursor_size=$(xfconf-query -c xsettings -p /Gtk/CursorThemeSize)
|
||||||
|
|
||||||
|
unset logout_required
|
||||||
|
|
||||||
|
if [ "$current_window_scaling" -eq '2' ]; then
|
||||||
|
# Increase scaling for QT apps
|
||||||
|
set_QT_scaling 2
|
||||||
|
# Use the highDPI variant of the XFWM theme
|
||||||
|
use_hdpi_theme_variant
|
||||||
|
if [ "$current_cursor_size" -eq 25 ]; then
|
||||||
|
set_cursor_size '45'
|
||||||
|
notify-send 'Mouse cursor size increased to 45' "Changed to a larger mouse cursor because you've enabled highDPI on your system"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
# Decrease scaling for QT apps
|
||||||
|
set_QT_scaling 1
|
||||||
|
# Use the normal variant of the XFWM theme
|
||||||
|
use_normal_theme_variant
|
||||||
|
if [ "$current_cursor_size" -eq 45 ]; then
|
||||||
|
set_cursor_size '25'
|
||||||
|
notify-send 'Mouse cursor size decreased to 25' "Changed to a smaller mouse cursor because you've disabled highDPI on your system"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Show popup menu about logout if it's required
|
# Show popup menu about logout if it's required
|
||||||
[ "$logout_required" = 'true' ] &&
|
[ "$logout_required" = 'true' ] &&
|
||||||
[ "$1" != 'no_hdpi_notification' ] &&
|
yad --image "dialog-question" --title "Alert" --buttons-layout=center --text-align=center --button=yad-yes:0 --button=yad-no:1 --text 'Logout is required in order to apply your DPI preferences to QT apps.\nWould you like to logout now?' &&
|
||||||
yad --image "dialog-question" --title "Alert" --buttons-layout=center --text-align=center --button=yad-yes:0 --button=yad-no:1 --text 'Logout is required in order to apply the DPI preferences to the QT apps.\nWould you like to logout now?' &&
|
|
||||||
xfce4-session-logout --logout
|
xfce4-session-logout --logout
|
||||||
}
|
}
|
||||||
|
|
||||||
sync_theme() {
|
sync_theme() {
|
||||||
# Get the current system theme
|
# Get the current system theme
|
||||||
current_theme=$(xfconf-query -c xsettings -p /Net/ThemeName)
|
local -r current_theme=$(xfconf-query -c xsettings -p /Net/ThemeName)
|
||||||
|
# Get the current window scaling factor (highDPI setting)
|
||||||
|
local -r current_window_scaling=$(xfconf-query -c xsettings -p /Gdk/WindowScalingFactor)
|
||||||
|
|
||||||
# Apply the current theme with gsettings
|
# Apply the current theme with gsettings
|
||||||
gsettings set org.gnome.desktop.interface gtk-theme "$current_theme"
|
gsettings set org.gnome.desktop.interface gtk-theme "$current_theme"
|
||||||
|
@ -123,17 +154,19 @@ sync_theme() {
|
||||||
# Apply the current theme for GTK and Libadwaita apps on flatpak
|
# Apply the current theme for GTK and Libadwaita apps on flatpak
|
||||||
flatpak override --user --env=GTK_THEME="$current_theme"
|
flatpak override --user --env=GTK_THEME="$current_theme"
|
||||||
|
|
||||||
# Apply the current theme for XFWM
|
# Apply the current theme for XFWM unless it's initial_sync on system reboot
|
||||||
xfconf-query -c xfwm4 -p /general/theme -n -t string -s "$current_theme"
|
if [ "$1" != 'initial_sync' ]; then
|
||||||
|
set_xfwm_theme "$current_theme"
|
||||||
|
|
||||||
# Change XFWM theme and mouse cursor size according to the user's highDPI setting
|
# Use the highDPI variant of the XFWM theme if the current_window_scaling factor is 2
|
||||||
hdpi_theme_fix 'no_hdpi_notification'
|
[ "$current_window_scaling" -eq '2' ] && use_hdpi_theme_variant 'disable_notification'
|
||||||
|
fi
|
||||||
|
|
||||||
# Cleanup flatpak_themes_dir
|
# Cleanup flatpak_themes_dir
|
||||||
rm -rf "${flatpak_themes_dir:?}"/*
|
rm -rf "${flatpak_themes_dir:?}"/*
|
||||||
|
|
||||||
# Find the directory where the current theme is stored
|
# Find the directory where the current theme is stored
|
||||||
current_theme_dir=$(xdg_directory_lookup "themes/$current_theme")
|
local -r current_theme_dir=$(xdg_directory_lookup "themes/$current_theme")
|
||||||
# Copy/sync current_theme_dir to flatpak_themes_dir
|
# Copy/sync current_theme_dir to flatpak_themes_dir
|
||||||
[ -d "$current_theme_dir" ] &&
|
[ -d "$current_theme_dir" ] &&
|
||||||
rsync -av --delete --progress "$current_theme_dir" "$flatpak_themes_dir"
|
rsync -av --delete --progress "$current_theme_dir" "$flatpak_themes_dir"
|
||||||
|
@ -141,16 +174,16 @@ sync_theme() {
|
||||||
|
|
||||||
sync_font() {
|
sync_font() {
|
||||||
# Get the current system font
|
# Get the current system font
|
||||||
font=$(xfconf-query -c xsettings -p /Gtk/FontName)
|
local -r current_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 "$current_font"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initial synchronization
|
# Initial synchronization
|
||||||
sync_theme
|
sync_theme 'initial_sync'
|
||||||
sync_font
|
sync_font
|
||||||
|
|
||||||
# Monitor when the user changes their system theme or icons or font in XFCE and sync them as needed
|
# Monitor when the user changes their system theme/icons/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 ;;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user