Skip to content

Instantly share code, notes, and snippets.

@hxss
Last active May 16, 2020 17:33
Show Gist options
  • Save hxss/6d6d8748640752b9ca9a6660ff77d52f to your computer and use it in GitHub Desktop.
Save hxss/6d6d8748640752b9ca9a6660ff77d52f to your computer and use it in GitHub Desktop.
Linux XFCE scripts for changing xrandr and dpi settings on hdmi toggle
#/etc/udev/rules.d/10-hdmi-dpi.rules
KERNEL=="card0", ACTION=="change", RUN+="/home/hxss/.config/scripts/xorg/hdmi.sh"
#/home/hxss/.config/systemd/user/hdmi-config.service
[Unit]
Description=Run HDMI configuration
[Service]
ExecStart=/home/hxss/.config/scripts/xorg/hdmi.sh
#!/bin/sh
hdmiState=`cat /sys/class/drm/*HDMI*/status`
function chngDPI() {
case "$hdmiState" in
"connected")
scale=1
dpi=96
;;
*)
scale=1.4
dpi=124
;;
esac
# dconf write /org/cinnamon/desktop/interface/text-scaling-factor $scale
logger -p info "dpi: $dpi"
xfconf-query -c xsettings -p /Xft/DPI -s $dpi
}
function xrandr_restore()
{
params=''
for display in `xfconf-query -c displays -l | perl -ne '/\/Default\/([^\/]*)\n/ and print "$1\n"'`
do
active=`xfconf-query -c displays -p /Default/$display/Active`
$active && state="auto" || state="off"
posx=`xfconf-query -c displays -p /Default/$display/Position/X`
posy=`xfconf-query -c displays -p /Default/$display/Position/Y`
params="${params}--output $display --$state --pos ${posx}x${posy} "
done
logger -p info "xrandr $params"
xrandr $params
}
function xfce_xrandr() {
logger -p info "xfce_xrandr; HDMI $hdmiState"
case "$hdmiState" in
"connected") xrandr_restore ;;
*) xrandr --auto ;;
esac
}
logger -p info "${BASH_SOURCE[0]}"
user=`stat -c %U $0`
if [ "$user" == `whoami` ]; then
chngDPI
xfce_xrandr
elif [ "`w -hs $user`" ]; then
machinectl shell --uid=$user .host /usr/bin/systemctl --user --no-block start hdmi-config.service
fi
@nasedase
Copy link

nasedase commented May 16, 2020

I'm looking for a script to scale up XFCE when i enable a display profile with my 4K TV. Could you explain what this does in more detail?

@hxss
Copy link
Author

hxss commented May 16, 2020

this script toggle dpi and apply xrandr settings from xfconf when you insert hdmi cable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment