Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 48 lines (41 sloc) 1.9 KB
# Sets an external monitor with a laptop as discrete (disables laptop monitor
# when external present (also sets correct DPI and text scaling))
# Program(s) required
req_progs=(bc xdpyinfo)
for p in ${req_progs[@]}; do
hash "$p" 2>&- || \
{ echo >&2 " Required program \"$p\" not installed."; exit 1; }
# Names of internal/external monitors (as defined by driver [`xrandr` to show])
#im=eDP; em=HDMI-0 # radeon driver
im=LVDS; em=DFP1 # fglrx driver (catalyst)
# server location (needed for root-run scripts to know location)
# Resolution
reso="auto" # "auto" for 'preferred' resolution, "mode XXXXxYYYY" for specific
# GNOME text scaling has a baseline of 96DPI, adjustment for non-96 DPI monitors
gnome_ts () {
# horizontal DPI, vertical DPI, aggragate DPI, 96/real DPI ratio
m_hd=$(xdpyinfo | grep dots | awk '{print $2}' | cut -d x -f 1)
m_vd=$(xdpyinfo | grep dots | awk '{print $2}' | cut -d x -f 2)
m_ad=$(echo "($m_hd+$m_vd)/2" | bc)
m_ds=$(echo "scale=4;96/$m_ad" | bc)
# set text scaling (only works if GNOME is installed)
[[ -z $(hash gsettings) ]] && \
gsettings set org.gnome.desktop.interface text-scaling-factor $m_ds
# Enable external monitor if present and disable laptop monitor, else vice versa
if [[ -n "$(xrandr | grep $em | grep " connected")" ]]; then
# define physical size from xrandr (xorg detection isn't right)
em_ps=$(xrandr | grep $em | grep -o "[0-9]*mm x [0-9]*" | sed 's/mm x /x/')
xrandr --output $im --off --output $em --"$reso" --fbmm $em_ps
# define physical size from xrandr (xorg detection isn't right)
xrandr --output $em --off
xrandr --output $im --"$reso" # monitor must be on to get display size
im_ps=$(xrandr | grep $im | grep -o "[0-9]*mm x [0-9]*" | sed 's/mm x /x/')
xrandr --output $im --"$reso" --fbmm $im_ps