Skip to content

Instantly share code, notes, and snippets.

@ompugao
Forked from wvengen/extend.sh
Last active February 6, 2017 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ompugao/4274d9efe8af47071ae18acbe82146c3 to your computer and use it in GitHub Desktop.
Save ompugao/4274d9efe8af47071ae18acbe82146c3 to your computer and use it in GitHub Desktop.
Extend non-HiDPI external display above HiDPI internal display
#!/bin/sh
# extend non-HiDPI external display on DP* above HiDPI internal display eDP*
# see also https://wiki.archlinux.org/index.php/HiDPI
# you may run into https://bugs.freedesktop.org/show_bug.cgi?id=39949
# https://bugs.launchpad.net/ubuntu/+source/xorg-server/+bug/883319
EXT=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v '^eDP' | head -n 1`
INT=`xrandr --current | sed 's/^\(.*\) connected.*$/\1/p;d' | grep -v '^DP' |grep -v 'HDMI' | head -n 1`
ext_w=`xrandr | sed 's/^'"${EXT}"' [^0-9]* \([0-9]\+\)x.*$/\1/p;d'`
ext_h=`xrandr | sed 's/^'"${EXT}"' [^0-9]* [0-9]\+x\([0-9]\+\).*$/\1/p;d'`
int_w=`xrandr | sed 's/^'"${INT}"' [^0-9]* \([0-9]\+\)x.*$/\1/p;d'`
off_w=`echo $(( ($int_w-$ext_w)/2 )) | sed 's/^-//'`
# extend non-HiDPI external display on DP* above HiDPI internal display eDP*
#xrandr --output "${INT}" --auto --pos ${off_w}x${ext_h} --scale 1x1 --output "${EXT}" --auto --scale 2x2 --pos 0x0
# extend non-HiDPI external display on DP* left-of HiDPI internal display eDP*
xrandr --output "${EXT}" --auto --scale 2x2 --pos 0x0 --output "${INT}" --auto --pos ${ext_w}x0 --scale 1x1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment