hidpify.sh

So I worked on this on a whim in a random thread some weeks back.
I revisited it recently and cleaned it up a little.

Its a little script that just automates what I would do for HiDPI config in KDE Plasma.
All you really need to use it is which DPI you would like.

PS

It is largely intended for those who have not already made modifications to files such as /etc/environment or /etc/sddm.conf and so on.

(though the script could give clues for the curious as to which files and options can be useful)

7 Likes

Just an update that it is smarter now;

-includes the 'mostly working' Qt_Auto_Screen_Scale
-removes and adds lines less like a confused assassin
-and prompts for password instead of telling you to use sudo.

Cheers!

2 Likes

@cscs
could you change you script and add

DPI=$(xrdb -query | grep dpi | grep -o '[^Xft.dpi:]\+$')

instead of reading it from user

But ... are we sure we dont want to let the user choose ?

(hm ... on second thought I could default it to automatic with the possibility for manual)

1 Like

also why not remove the need for sudo
by saving the environment variables
in ~/.profile
instead of /etc/environment.

autohidpi.sh

#!/usr/bin/env bash
#                         hidpify.sh                        #
## This script will automate DPI settings for a KDE system ##
#####                        cscs                       #####


# You are powerless. Explain yourself.
#if [ "$EUID" -ne 0 ]
#  then echo "Please run using sudo";
#  exit;
#fi

# Who are you anyways
YOU=$(who | awk '{print $1}')
# And what do you want?
RV=$(xrdb -query | grep dpi | grep -o '[^Xft.dpi:]\+$')
# to get only number 
DPI=$(bc <<< "scale = 0;  $RV / 1")
# Generate a "fractional value" (FV) from a 96dpi default (ie: 120 = 1.25)
FV=$(bc <<< "scale = 2;  $DPI / 96")
# And where are your firefox and thunderbird profiles?


MPPP=$(printf 'user_pref("layout.css.devPixelsPerPx", "'"$FV"'");')

#while getopts 'i:r:' opt ; do
# Apply KDE DPI through system settings
if [ "`which kwriteconfig5`" ]; then
# sudo -H -u $YOU 
kwriteconfig5 --file /home/$YOU/.config/kcmfonts --group "General" --key "forceFontDPI" "$DPI" ;
fi
# Apply SDDM DPI
 #sed -i '/^ServerArguments/ s/$/ '"-dpi $DPI"'/' /etc/sddm.conf ;

# Apply GTK scaling using the FV
 sed -i '$a\' /home/$YOU/.profile ;
 printf "export GDK_SCALE=$FV" >> /home/$YOU/.profile ;
 export GDK_SCALE=$FV

# Apply Automatic QT scaling which *should* force screen DPI
 sed -i '$a\' /home/$YOU/.profile ;
 printf "export QT_AUTO_SCREEN_SCALE_FACTOR=1" >> /home/$YOU/.profile ;
 export QT_AUTO_SCREEN_SCALE_FACTOR=1

# Apply Firefox pixelsperpx using FV
if [ "`which firefox`" ]; then
FFPRO=$(find /home/$YOU/.mozilla/firefox -name "*.default" -print)
# sudo -H -u $YOU 
touch -a $FFPRO/user.js ;
# sudo -H -u $YOU 
sed -i '$a\' $FFPRO/user.js ;
# sudo -H -u $YOU 
printf "$MPPP" >> $FFPRO/user.js ;
fi

# Apply Thunderbird pixelsperpx using FV
if [ "`which thunderbird`" ]; then
TBPRO=$(find /home/$YOU/.thunderbird/ -name "*.default" -print)
# sudo -H -u $YOU 
touch -a $TBPRO/user.js ;
# sudo -H -u $YOU 
sed -i '$a\' $TBPRO/user.js ;
# sudo -H -u $YOU 
printf "$MPPP" >> $TBPRO/user.js ;
fi
exit

rmautohidpi.sh

#!/usr/bin/env bash
#                         hidpify.sh                        #
## This script will automate DPI settings for a KDE system ##
#####                        cscs                       #####

# You are powerless. Explain yourself.
#if [ "$EUID" -ne 0 ]
#  then echo "Please run using sudo";
#  exit;
#fi

# Who are you anyways
YOU=$(who | awk '{print $1}')
# And what do you want?
RV=$(xrdb -query | grep dpi | grep -o '[^Xft.dpi:]\+$')
# to get only number 
DPI=$(bc <<< "scale = 0;  $RV / 1")
# Generate a "fractional value" (FV) from a 96dpi default (ie: 120 = 1.25)
FV=$(bc <<< "scale = 2;  $DPI / 96")
# And where are your firefox and thunderbird profiles?

MPPP=$(printf 'user_pref("layout.css.devPixelsPerPx", "'"$FV"'");')
if [ "`which thunderbird`" ]; then
TBPRO=$(find /home/$YOU/.thunderbird/ -name "*.default" -print)
 sed -i -e "/$MPPP/d" $TBPRO/user.js ;
fi


if [ "`which firefox`" ]; then
FFPRO=$(find /home/$YOU/.mozilla/firefox -name "*.default" -print)
 sed -i -e "/$MPPP/d" $FFPRO/user.js ;
fi


 sed -i -e "/export GDK_SCALE=$FV/d" /home/$YOU/.profile ;
 sed -i -e "/export QT_AUTO_SCREEN_SCALE_FACTOR=1/d" /home/$YOU/.profile ;
 #sed -i -e "s/ -dpi $DPI//g" /etc/sddm.conf ;
# sudo -H -u $YOU 
if [ "`which kwriteconfig5`" ]; then
kwriteconfig5 --file /home/$YOU/.config/kcmfonts --group "General" --key "forceFontDPI" "96" ; 
fi

exit

multiple reasons.
sddm.conf for example requires the privileges.
There are multuple places to put some of the other configs (like xprofile) ... but they all act a little differently. I set mine in /etc/environment so the script does too.
If you want more information (such as how xprofile only works after login and more) see this:
https://wiki.archlinux.org/index.php/Environment_variables

1 Like

Forum kindly sponsored by