Skip to content

Instantly share code, notes, and snippets.

Last active January 8, 2024 23:28
  • Star 97 You must be signed in to star a gist
  • Fork 23 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wvengen/178642bbc8236c1bdb67 to your computer and use it in GitHub Desktop.
Extend non-HiDPI external display above HiDPI internal display
# extend non-HiDPI external display on DP* above HiDPI internal display eDP*
# see also
# you may run into
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 | 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/^-//'`
xrandr --output "${INT}" --auto --pos ${off_w}x${ext_h} --scale 1x1 --output "${EXT}" --auto --scale 2x2 --pos 0x0
Copy link

anidel commented Jun 13, 2018

It's wierd. I seem to have a similar setup as many, a Surface Pro with a res of 2736x1824 and an external display in FHD, yet, if I run it as it is, the external display windows look very small. I want its scale to be 1 and the internal display to look better to the eye (i.e. scale of 0.5), this seems to do the opposite?

If I try to set the correct scaling, it looks weird, I guess I am not getting the formula, maybe I have to multiply by 2 rather than divide in the offset calculation?

Copy link

pulsation commented Jul 28, 2018

Thanks a lot for this script! To have the full external screen area usable, I had to add theses bits :

Get internal screen height,

int_h=`xrandr | sed 's/^'"${INT}"' [^0-9]* [0-9]\+x\([0-9]\+\).*$/\1/p;d'` 

Calculate total width calculation,

tot_w=$(( $ext_w+$int_w ))

And at last, append this option to the final xrandr command.

xrandr [...] --fb ${tot_w}x${int_h}

Copy link

I have an easy to modify python script here with arguably more options:

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