Skip to content

Instantly share code, notes, and snippets.

@grantmcdermott

grantmcdermott/hidpi.sh

Last active Jun 7, 2021
Embed
What would you like to do?
Script for fixing HiDPI issues on Linux (for programs that I use). Useful for automating steps outlined here: https://wiki.archlinux.org/index.php/HiDPI#Applications
#!/bin/sh
#DDIR=$HOME/hidpi_test ## test version
DDIR='/usr/share/applications'
## There are two basic hidpi cases that we need to distinguish and correct for:
## 1) Electron-based apps and 2) QT-based apps
## 1) Electron-based apps (append '--force-scale-device-factor=2' to executable)
for FILE in code-oss.desktop google-chrome.desktop gparted.desktop skypeforlinux.desktop slack.desktop nteract.desktop
do
if ! grep -q '\-\-force\-device\-scale\-factor=2' $DDIR/$FILE
then
sed -i 's/ %/ --force-device-scale-factor=2 %/g' $DDIR/$FILE
echo "Updated $FILE"
fi
done
## We have to do a separate pass for brave, which annoyingly won't scale unless we
## replace 'Exec=brave' with the full executable path, i.e. 'Exec=/usr/bin/brave'
## and also adjust the incognito and new browser windows.
for FILE in brave-browser.desktop
do
EX_PATH=$(which brave)
EX_STR="Exec=${EX_PATH}"
if ! grep -q "${EX_STR}" $DDIR/$FILE
then
gawk -i inplace -v my_env="Exec=$(which brave)" '$1 ~ /^Exec=/ {sub(/Exec=brave/, my_env)}1' $DDIR/$FILE
echo "Updated $FILE execution path"
fi
if ! grep -q '\-\-force\-device\-scale\-factor=2' $DDIR/$FILE
then
sed -i "s|Exec=$(which brave)|Exec=$(which brave) --force-device-scale-factor=2|g" $DDIR/$FILE
echo "Updated $FILE"
fi
done
## 2) QT-based apps (prepend 'env QT_SCALE_FACTOR=0.5' to executable)
for FILE in com.obsproject.Studio.desktop rstudio.desktop Zoom.desktop
do
if ! grep -q 'env\ QT\_SCALE\_FACTOR=0.5' $DDIR/$FILE
then
sed -i 's/Exec=/Exec=env QT_SCALE_FACTOR=0.5 /g' $DDIR/$FILE
echo "Updated $FILE"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment