Translate

2021-12-05

Xubuntu/X11 can't remember a dual monitor configuration

(Updates are at the end of the post!) 

As soon as I leave my monitor for a cup of coffee or other everyday activities taking some ten minutes, when I come back my main screen is mirrored onto the secondary one. In the long run it's really irritating. But; this happens only when I'm not actively working. Sometimes I lean back to think and if I takes too long the configuration goes to mirroring.

I found a way to lessen the problem. I used two scripts (which perhaps ought to be merged but for this blog post they are what they are).  I thought I could put the setup script in .profile but I ran into problems, the login prompt didn't come up. I didn't explore that in any depth, I was in no mood to solve anything other that the screen problem.
I'll add one more thing: I run Xubuntu 20.04.02

First I need to know what my monitors are called in the X11 context, using xrandr:

snkdb@bender2:~$xrandr --listmonitors

Monitors: 2
0: +*DisplayPort-0 2560/597x1440/336+0+0  DisplayPort-0
1: +DisplayPort-1 1920/519x1200/324+2560+0  DisplayPort-1

Script "screen_setup.sh":
#!/bin/bash
### setting the correct configuration ###

# I had problems using "-" in the display port names. "DP-0" wasn't accepted.
# there's some confusion here...

DP0=DisplayPort-0
DP1=DisplayPort-1
# main screen: 2560x1440

function setup {
    xrandr --output $DP0 --auto --pos 0x0 --output $DP1 --auto --pos 2560x0
}

setup
# mostly for checking it worked as meant to 
date '+%Y-%m-%d %H:%M:%S' > <path>/screen_setup.sh_last_run.log
# END

Script "screen_setup_run_locally.sh":
#!/bin/bash ### running the configuration script (screen_setup.sh) repeatedly ###

# directions, how to use [in this case setting the wait time to 10s. You may have to experiment here]
if [ "$1" == "" ]; 
 then 
     echo "Pls enter the number of wait time seconds as an argument!"; 
     echo " like: 'screen_setup_run_locally.sh  10'<ENTER>"; 
     exit; 
fi 

# wait 10s
sleep $1 

# start this script in another process with the same wait time
exec $0 $1
#END

Then I created a launcher on the desktop. The command : <path>/screen_setup_run_locally.sh 10. After I have logged in I click it once and then screen_setup_run_locally.sh will stay put and do it's job. You can check it by starting ksysguard, choosing the Process Table tab, entering "screen_setup.sh" in the search line to the right of the "End Process"-button. In my environment it's a line looking:
sh  <your user name> <PID> <IO Write [~4k each 10s]> <Memory [~200k]> <shared Mem. value>


The result is: when I'm gone I won't find the configuration deteriorated as before when I come back after a pause.
The launcher icon on the desktop is possible to drag and drop onto the panel where I prefer to have it.


Update 20211206:
Very strange X11 behavior; setting up the scripts, xrandr --listmonitors resulted in DisplayPort-0 and 
DisplayPort-1. After the nightly backup, my machine shuts down. When I started it, the scripts didn't work, warning that the display ports didn't exist. xrandr --listmonitors  now resulted in ports names like DP-1 and DP-2! The format is changed and they now start at 1 instead of 0. What the f?! Why?
As of now I don't know why. Since the construction of these scripts isn't really my main goal in life I just added a second line to the screen_setup.sh:

xrandr --output $DP0 --auto --pos 0x0 --output $DP1 --auto --pos 2560x0
xrandr --output "DP-1" --auto --pos 0x0 --output "DP-2" --auto --pos 2560x0

One of them will always end up in a warning about not existing ports so the launcher will get an addition: <path>/screen_setup_run_locally.sh 10 &> /dev/null
This will take care about the annoying warning messages.

I'm pleased to present really good example of a kludge!!

















Inga kommentarer:

Skicka en kommentar