Using Ubuntu's system settings to configure two screens (desktop monitor and TV via HDMI in my case) is not ergonomic.
Hence I decided to code a handy switcher script which lets me choose between mirrored output ("mirror") and either left screen on/right screen off or left screen off/right screen on ("switch"). It is based on xrandr
.
It works as expected and I like the flexibility when using xrandr
, BUT:
- tearfree setting necessary for TV output is either ignored or ineffective after using my script (Why?)
- system settings are broken after using my script: If I change screen configuration via system settings afterwards, output will be scrambled.
My script must be doing something horribly wrong. How can I make it work correctly?
Script:
#!/bin/bash
DESKTOP="DP1" # desktop monitor
DSIZE="1280x1024"
TVPORT="HDMI1" # connection to TV
TVSIZE="1920x1080"
SCALE="1.5" # e.g. 1920/1280
if xrandr | grep "$TVPORT" | egrep "\)$"
then # TV port is turned OFF => turn it on
selected_mode=`echo -e "mirror\nswitch" | zenity --list --text="Choose Mode:" --column="Mode"`
if test "$selected_mode" = "mirror"
then
xrandr --output "$TVPORT" --auto --left-of "$DESKTOP" --output "$DESKTOP" --panning "$TVSIZE"
xrandr --output "$DESKTOP" --scale "$SCALE"x"$SCALE" --mode "$DSIZE" --fb "$TVSIZE" --panning "$TVSIZE"
fi
if test "$selected_mode" = "switch"
then
xrandr --output "$TVPORT" --auto --output "$DESKTOP" --off
fi
else # TV port is turned ON => turn it off
xrandr --output "$TVPORT" --off --output "$DESKTOP" --mode "$DSIZE" --fb "$DSIZE" --scale 1x1 --panning "$DSIZE"
fi
exit 0
Tearfree which works when using Ubuntu normally, but not after running my script:
$ cat /etc/X11/xorg.conf
Section "Device"
Identifier "Intel Graphics"
Driver "intel"
Option "AccelMethod" "sna"
Option "SwapbuffersWait" "true"
Option "TearFree" "true"
EndSection
0 Answers