Skip to content

Instantly share code, notes, and snippets.

@grantmcdermott

grantmcdermott/hidpi.sh

Last active May 20, 2020
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='/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 atom.desktop brave-browser.desktop code-oss.desktop google-chrome.desktop skypeforlinux.desktop slack.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
## We have to do an extra pass for brave, which annoyingly won't scale
## unless we replace 'Exec=brave' with the full executable path, i.e.
## 'Exec=/usr/bin/brave'
if [ $FILE = 'brave-browser.desktop' ]
then
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 "Also updated $FILE execution path"
fi
fi
done
## 2) QT-based apps (prepend 'env QT_SCALE_FACTOR=0.5' to executable)
for FILE in com.obsproject.Studio.desktop rstudio.desktop texstudio.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
You can’t perform that action at this time.