Last active
December 12, 2020 11:50
-
-
Save ppenguin/1ec27ae0db5ebc03da1dd7dde5e29a39 to your computer and use it in GitHub Desktop.
quick&dirty but generic solution to scale external monitors connected to a (4k) laptop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/udev/rules.d/90-plugdisplay.rules | |
# may have to be modified if you e.g. have more than 1 graphics card | |
KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/plugdisplay.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# system-wide /usr/local/bin/plugdisplay.sh | |
# to be triggered by udev rule for display plug event | |
sesinfo() { | |
loginctl show-session ${1} | grep 'Name\|Display' | sed -e 's/\([A-z]*\)/\U\1/' | |
} | |
for s in $(loginctl | awk '$4 ~ /seat.*/ { print $1 }'); do | |
unset DISPLAY | |
eval $(sesinfo ${s}) | |
if [ -n "${DISPLAY}" ]; then | |
echo "Running display plug event for user ${NAME} on display ${DISPLAY}" | |
# wait some time for monitor to be recognised by DE | |
(sleep 8 && su - ${NAME} -c "DISPLAY=${DISPLAY} "'${HOME}/.local/bin/xrandr-scale.sh') & | |
else | |
echo "NAME==${NAME} DISPLAY==${DISPLAY}" | |
fi | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# set -x | |
getdisphres() { | |
xrandr --current | grep '*' | awk -v line="${1}" 'NR==line{print $1}' | cut -d 'x' -f2 | |
} | |
getnumdisp() { | |
xrandr --current | grep -B1 -A0 '*' | grep connected | wc -l | |
} | |
getnthdispname() { | |
xrandr --current | grep -B1 -A0 '*' | grep connected | cut -d ' ' -f1 | sed "${1}q;d" | |
} | |
y1=$(getdisphres 1) | |
for d in $(seq 2 $(getnumdisp)); do | |
y=$(getdisphres ${d}) | |
n=$(getnthdispname ${d}) | |
f=$(bc -l <<< "scale=2; ${y1} / ${y} / 1.5 * 2.0") | |
xrandr --output ${n} --scale ${f}x${f} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment