From 05f4dae9e3aa5a9ee9cce11dee3de98bc44c07f6 Mon Sep 17 00:00:00 2001 From: Tio TROM Date: Thu, 10 Aug 2023 17:03:39 +0200 Subject: [PATCH] added QT scaling support --- bin/periodic/fix-theming | 50 ++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/bin/periodic/fix-theming b/bin/periodic/fix-theming index 1d6a7ea..889ffc9 100755 --- a/bin/periodic/fix-theming +++ b/bin/periodic/fix-theming @@ -3,9 +3,10 @@ # Exit out if the same script is already running in the background pidof -sq -o %PPID -x "$(basename "$0")" && exit -# Set the directory paths +# Set the directory/file paths flatpak_themes_dir="$HOME/.themes" flatpak_icons_dir="$HOME/.icons" +profile="$HOME/.profile" # Create flatpak icons & themes directories if they don't exist mkdir -p "$flatpak_themes_dir" "$flatpak_icons_dir" || @@ -25,6 +26,26 @@ xdg_directory_lookup() { done < <(printf '%s:%s\n' "$HOME/.local/share" "$XDG_DATA_DIRS" | tr ':' '\n') } +# Function for setting variables in ~/.profile +profile_set_variable() { + # Return if the variable is already set to the correct value + grep -xq "\s*export\s\+$1=$2\s*" "$profile" && return + # 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" + + # 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 + tail -n1 "$profile" | grep -qx '\s*' && begin='' || begin='\n' + printf '%b# Values set by the fix-theming script\nexport %s=%s\n' "$begin" "$1" "$2" >> "$profile" + else + printf '# Values set by the fix-theming script\nexport %s=%s\n' "$1" "$2" > "$profile" + fi + # Set variable logout_required to true + logout_required='true' +} + hdpi_theme_fix() { # Get the current window scaling factor (highDPI setting) current_scaling=$(xfconf-query -c xsettings -p /Gdk/WindowScalingFactor) @@ -33,12 +54,18 @@ hdpi_theme_fix() { # 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 less than 45 - if [ "$cursor_size" -lt 45 ]; 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 + profile_set_variable "$var" 2 + done 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 @@ -49,16 +76,21 @@ hdpi_theme_fix() { # If this directory exists then change to that theme for XFWM if [ -d "$highDPI_theme_dir" ]; then 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 fi done else - # Decrease mouse cursor size if it's greater than or equal to 45 - if [ "$cursor_size" -ge 45 ]; then + # Decrease mouse cursor size if it's equal to 45 + if [ "$cursor_size" -eq 45 ]; then xfconf-query -c xsettings -p /Gtk/CursorThemeSize -s '25' notify-send 'Mouse cursor size decreased to 25' "Changed to a smaller mouse cursor because you've disabled highDPI on your system" 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 # Continue looping if this (highDPI) variant of the theme is not enabled [ "${current_xfwm_theme##*-}" != "$variant" ] && continue @@ -74,6 +106,10 @@ hdpi_theme_fix() { fi done fi + # Show popup menu about logout if it's required + [ "$logout_required" = 'true' ] && + 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 } sync_theme() { @@ -90,7 +126,7 @@ sync_theme() { xfconf-query -c xfwm4 -p /general/theme -n -t string -s "$current_theme" # Change XFWM theme and mouse cursor size according to the user's highDPI setting - hdpi_theme_fix + hdpi_theme_fix 'no_hdpi_notification' # Cleanup flatpak_themes_dir rm -rf "${flatpak_themes_dir:?}"/*