Create a gist now

Instantly share code, notes, and snippets.

@wvengen /extend.sh
Last active Aug 17, 2018

Embed
What would you like to do?
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 | 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
@JherezTaylor

This comment has been minimized.

Show comment
Hide comment
@JherezTaylor

JherezTaylor Apr 28, 2016

How do you change this to be right of the main display? eDP1

JherezTaylor commented Apr 28, 2016

How do you change this to be right of the main display? eDP1

@zekefast

This comment has been minimized.

Show comment
Hide comment
@zekefast

zekefast Jul 11, 2016

@JherezTaylor add ``--right-of eDP1to the end of finalxrandr`

zekefast commented Jul 11, 2016

@JherezTaylor add ``--right-of eDP1to the end of finalxrandr`

@a123qwertz567

This comment has been minimized.

Show comment
Hide comment
@a123qwertz567

a123qwertz567 Nov 10, 2016

Hello,
I came here by the ArchWiki article "HiDPI". Maybe you can help me...I came here to ask because I am not sure to which forum I should go. If I get a hint I will post at another place....

Your script isn't really working for me now but this (from the wiki) works for me:
xrandr --output eDP-1 --auto --output HDMI-1 --auto --panning 3840x2160+3840+0 --scale 2x2 --right-of eDP-1
BUT my hardware setup would need a --left-of. But with by replacing right with left I get a non-good result. I am not sure if it is a panning thing. Still not sire how this works. I think --left-of doesn't make a big difference.

EDIT: Specify "non-good": HiDPI screen fine all the time. LowDPI(FullHD) screen is broken. It is like the screen 4k in the "background". When I go over to the screen around the mouse it is like a zoom rectangle of the size 1920x1080 on the 4k "bachground"....This is difficult to discribe or so screenshot.... :(

a123qwertz567 commented Nov 10, 2016

Hello,
I came here by the ArchWiki article "HiDPI". Maybe you can help me...I came here to ask because I am not sure to which forum I should go. If I get a hint I will post at another place....

Your script isn't really working for me now but this (from the wiki) works for me:
xrandr --output eDP-1 --auto --output HDMI-1 --auto --panning 3840x2160+3840+0 --scale 2x2 --right-of eDP-1
BUT my hardware setup would need a --left-of. But with by replacing right with left I get a non-good result. I am not sure if it is a panning thing. Still not sire how this works. I think --left-of doesn't make a big difference.

EDIT: Specify "non-good": HiDPI screen fine all the time. LowDPI(FullHD) screen is broken. It is like the screen 4k in the "background". When I go over to the screen around the mouse it is like a zoom rectangle of the size 1920x1080 on the 4k "bachground"....This is difficult to discribe or so screenshot.... :(

@raininja

This comment has been minimized.

Show comment
Hide comment
@raininja

raininja Jan 4, 2017

I also get a "bad" result on my Asus 1920x1080 device. . . I also require a "left of" configuration. . . looking at these sed scripts. . . I wonder if there is a cleaner method. . .

raininja commented Jan 4, 2017

I also get a "bad" result on my Asus 1920x1080 device. . . I also require a "left of" configuration. . . looking at these sed scripts. . . I wonder if there is a cleaner method. . .

@krizajb

This comment has been minimized.

Show comment
Hide comment
@krizajb

krizajb Nov 8, 2017

Same thing is happening to me as for @a123qwertz567. Did you guys figure something out?

krizajb commented Nov 8, 2017

Same thing is happening to me as for @a123qwertz567. Did you guys figure something out?

@luispabon

This comment has been minimized.

Show comment
Hide comment
@luispabon

luispabon Dec 7, 2017

This works well for my current set up where I have a 4K laptop (XPS 9560) beneath a FHD external display, but I have to run it twice: first time the external monitor has a big chunk of whatever's on the 4K monitor, and the second time it goes in fine.

On Unity, connect first the external monitor, and on display config make sure the scale factor for both screens is 2. Then run the script, perhaps twice.

The downside of this approach is however the FHD monitor is a scaled down version of 4K, so your computer is in fact driving 2x4K monitors (plus the overhead of resampling) and this is very resource intensive. The image quality on the FHD monitor is not great.

luispabon commented Dec 7, 2017

This works well for my current set up where I have a 4K laptop (XPS 9560) beneath a FHD external display, but I have to run it twice: first time the external monitor has a big chunk of whatever's on the 4K monitor, and the second time it goes in fine.

On Unity, connect first the external monitor, and on display config make sure the scale factor for both screens is 2. Then run the script, perhaps twice.

The downside of this approach is however the FHD monitor is a scaled down version of 4K, so your computer is in fact driving 2x4K monitors (plus the overhead of resampling) and this is very resource intensive. The image quality on the FHD monitor is not great.

@msammarco

This comment has been minimized.

Show comment
Hide comment
@msammarco

msammarco Dec 29, 2017

I see the same as above with gnome 3. Unfortunately sometimes it doesn't seem to actually work on the second run

msammarco commented Dec 29, 2017

I see the same as above with gnome 3. Unfortunately sometimes it doesn't seem to actually work on the second run

@PizzaBrandon

This comment has been minimized.

Show comment
Hide comment
@PizzaBrandon

PizzaBrandon May 17, 2018

Thanks for this script! I typically have to run it twice, as well, but I'll take that over the alternative!

PizzaBrandon commented May 17, 2018

Thanks for this script! I typically have to run it twice, as well, but I'll take that over the alternative!

@anidel

This comment has been minimized.

Show comment
Hide comment
@anidel

anidel 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?

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?

@pulsation

This comment has been minimized.

Show comment
Hide comment
@pulsation

pulsation 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}

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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment