[solved] initiate xrandr configurations on login screen
Tofloor
poster avatar
barthodian
deepin
2016-03-02 02:07
Author
Edited by barthodian at 2016-3-3 09:44

Thread summary
Find the configuration file that loads on login screen
  • /etc/rc.local
  • ~/.bashrc
  • ~/.xprofile

My choice is 3 for order and readability.

Setup script to detect device and change resolution
  1. #!/bin/bash
  2. #
  3. # display-find.sh - Script to find a specific connected dislay
  4. # and apply configuration settings to it.

  5. # Customize the display to find with the name and model and the
  6. # first 16 bytes of your display EDID. That's the first line of
  7. # the displays EDID you may find with the shell command: xrandr.
  8. DISPLAY_NAME="Display brand and model name"
  9. DISPLAY_EDID="00ffffffffffff004861000000000000"

  10. # Customize the action to apply to the display
  11. DISPLAY_ACTION=("setting resolution to 1080i" "--mode 1920x1080i")

  12. # Runtime: do not edit the following unless you know what you're doing. :)

  13. # Find connected display outputs
  14. OUTPUTS=($(xrandr | grep " connected" | cut -f 1 -d " "))
  15. OUTPUTS_COUNT=${#OUTPUTS[*]}

  16. # If no connected display is found exit with error
  17. if [ $OUTPUTS_COUNT -eq 0 ]; then
  18.   echo "display-find: error! no display was found, check your cables, exiting..."
  19.   exit 1 # Exit error 1: no displays found
  20. fi

  21. # Echo found connected displays
  22. echo "display-find: found $OUTPUTS_COUNT displays connected at outputs: ${OUTPUTS[*]}"

  23. # Find each connected display's EDID first 16 bytes
  24. OUTPUTS_EDID=($(xrandr --prop | grep -A 1 "EDID:" | cut -f 1 -d "-" | cut -f 2 -d ":"))

  25. # For each found EDID check if matches the display to find then
  26. # apply action and exit, else exit with error
  27. COUNTER=0
  28. for EDID in ${OUTPUTS_EDID[*]}; do
  29.   if [ $EDID == $DISPLAY_EDID ]; then
  30.     DISPLAY_OUTPUT=${OUTPUTS[COUNTER]}
  31.     echo "display-find: found match at $DISPLAY_OUTPUT: $DISPLAY_EDID"
  32.     echo "display-find: found $DISPLAY_NAME"
  33.     echo "display-find: ${DISPLAY_ACTION[0]}"
  34.     sleep 1
  35.     xrandr --output $DISPLAY_OUTPUT ${DISPLAY_ACTION[1]}
  36.     if [ $? -eq 0 ]; then
  37.       echo "display-find: done! exiting..."
  38.       exit 0 # Exit error 0: Ok
  39.     else
  40.       echo "display-find: error! applying settings failed. exiting..."
  41.       exit 2 # Exit error 2: settings failed
  42.     fi
  43.   else
  44.     ((COUNTER++))
  45.     if [ $COUNTER -eq $OUTPUTS_COUNT ]; then
  46.       echo "display-find: sorry, no match found for EDID: $DISPLAY_EDID. exiting..."
  47.       exit 3 # Exit error 3: no match found
  48.     fi
  49.   fi
  50. done
  51. exit 4 # Exit error 4: abnormal error
Copy the Code

I posted a code of my own but with all honesty, the code above by @jotapesse is far more superior.


Original post:
I'm trying to figure out where the login script file is placed so I can go ahead and add a xrandr script upon start up. Since my TV connected with HDMI does not automatically switches to the compatible resolution (The TV does not support native 1080p but does work with 1080i) I'm trying to add a startup script to solve the problem. Where do I find this?

Thanks.


Reply Favorite View the author
All Replies
dance707
deepin
2016-03-02 02:25
#1
I had experimented with a login script for my Quad Monitor Display. What work best for me was to simply place a script in the home folder.
Reply View the author
tristar
deepin
2016-03-02 02:26
#2
You can do it like:

  1. /etc/rc.local
Copy the Code


or

  1. /home/user/.bashrc
Copy the Code

Reply View the author
dance707
deepin
2016-03-02 02:31
#3
Edited by dance707 at 2016-3-1 03:35
https://bbs.deepin.org/post/30786
I had experimented with a login script for my Quad Monitor Display. What work best for me was to sim ...

If i remember right     ~/.xprofile  
containing your commands

I stop using it because my hardware needs to sync slowly and I did not know how to put a delay in the xrandr commands
Reply View the author
dance707
deepin
2016-03-02 02:56
#4
https://bbs.deepin.org/post/30786
If i remember right     ~/.xprofile  
containing your commands

Here are the notes my notes I found on that method :


BY SESSION WITH .XPROFILE

Use your favorite editor to create ~/.xprofile containing something like:

xrandr --output VGA1 --mode 1024x768 --rate 60
Now that command will be run every time your start your Xsession. You can force it to run by logging out and logging back in or by executing ~/.xprofile from your terminal.
Reply View the author
barthodian
deepin
2016-03-02 03:06
#5
Edited by barthodian at 2016-3-1 19:07
https://bbs.deepin.org/post/30786
Here are the notes my notes I found on that method :

Thanks for that one. I need a script that dynamically identifies the specific device and set the resolution for it. So far a little wiki at archlinux.org is providing something I can use. Gotta find a way to "grep" the EDID properly which seems to be a problem still since
  1. xrandr --prop
Copy the Code
doesn't display the EDID in a fetchible printout.
Reply View the author
barthodian
deepin
2016-03-02 03:23
#6

That second method probably runs after login in to the user's account, which is not intended. But I like it better since touching the files outside the home folder is something I tend to avoid unless absolutely required. I gotta go with dance707's ~/.xprofile for clear seperated scripts.
Reply View the author
dance707
deepin
2016-03-02 03:35
#7
https://bbs.deepin.org/post/30786
Thanks for that one. I need a script that dynamically identifies the specific device and set the re ...

here are some EDID commands have no idea if they can be used in a script

http://unix.stackexchange.com/qu ... or-a-single-monitor
Reply View the author
barthodian
deepin
2016-03-02 03:58
#8
Edited by barthodian at 2016-3-1 20:03
https://bbs.deepin.org/post/30786
here are some EDID commands have no idea if they can be used in a script

http://unix.stackexchang ...

They're separate programs to do those things. I was trying to get as close to vanilla Deepin as possible without installing anything else so next time around after reinstallation it's only a matter of applying the script. Besides, it would be better if my end script will become "universal" for those who have the same issue.

Thanks for trying, but that was pretty much one of the first thing I found in Google's search results. Still lookin.

By the way, I used
  1. xrandr --prop | grep -A 16 "EDID"
Copy the Code
Which will print out 16 lines after the "EDID" line. Trying to work this in the bash script like so:

  1. if (xrandr --prop | grep -A 16 "EDID" == "Matching strings"); then

  2. etc, etc
Copy the Code
Of course this script is still not working so I'm looking for that at the moment.
Reply View the author
barthodian
deepin
2016-03-02 17:42
#9
Okay so I have a working script so far:

  1. #!/bin/bash

  2. out=$(xrandr --prop | grep " connected" | awk '{print $1;}')
  3. edid='        EDID:
  4.                 00ffffffffffff004861000000000000
  5.                 2b12010380502d780a0dc9a057479827
  6.                 12484c21080031404540614081c09500
  7.                 b300d1c00101011d007251d01e206e28
  8.                 550020c23100001e662156aa51001e30
  9.                 468f330020c23100001e000000fc0052
  10.                 5339350a2020202020202020000000fd
  11.                 003b3d0f460f000a2020202020200121
  12.                 02031e714b8408090510030207062001
  13.                 230907018301000065030c001000011d
  14.                 8018711c1620582c250020c23100009e
  15.                 023a801871382d40582c250020c23100
  16.                 001e8c0ad08a20e02d10103e960020c2
  17.                 310000188c0aa01451f01600267c4300
  18.                 20c2310000988c0aa01451f01600267c
  19.                 430058c22100009800000000000000ab'

  20. if [ "$(xrandr --prop | grep -A 16 'EDID')" = "$edid" ]; then
  21.         echo "Set resolution to 1080i"
  22.         xrandr --output $out --mode 1920x1080i
  23.         exit 1;
  24. else
  25.         echo "Video-out is not available."
  26. fi
Copy the Code

Notice that there are still quite a few things wrong with it and it only specifically addresses my device. However, by changing the string of $edid you could specify your own device. I'm still trying to polish up the script to make it work more correctly.
Reply View the author
dance707
deepin
2016-03-02 17:52
#10
https://bbs.deepin.org/post/30786
Okay so I have a working script so far:

Very interesting
Reply View the author
barthodian
deepin
2016-03-03 14:25
#11

To be honest, when you mentioned you've stopped using the script, I was somewhat hoping my script would be able to help you improve on your previous problem. I'm working on a definitive version now with easy modification in case you or someone else wants to easily modify to their own use (it's too much of a hassle as of now to create a fully functioning script and there are probably good ones already out there).

Expect update soon.
Reply View the author
dance707
deepin
2016-03-03 14:28
#12
https://bbs.deepin.org/post/30786
To be honest, when you mentioned you've stopped using the script, I was somewhat hoping my script  ...

Thanks I saw some of your links gave me some ideas. My script is very simple I just need a 5 second delay in between commands.

xrandr --setprovideroutputsource 1 0
xrandr --output DVI-1-2 --auto --right-of DVI-1
xrandr --output DVI-1-3 --auto --right-of DVI-1-2
Reply View the author
dance707
deepin
2016-03-03 14:42
#13
https://bbs.deepin.org/post/30786
Thanks I saw some of your links gave me some ideas. My script is very simple I just need a 5 secon ...

there would need to be an appropriate delay to make sure the hardware was done initializing before xrandr returns, or I would have to add in a sleep statement between commands ?
Reply View the author
barthodian
deepin
2016-03-03 15:19
#14
Edited by barthodian at 2016-3-3 07:20
https://bbs.deepin.org/post/30786
there would need to be an appropriate delay to make sure the hardware was done initializing before ...

What I am assuming is that you want the command to be executed with a delay of 5 seconds. Which I think should be easily done using a timeout function if there is any. From what I found on http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/ is just putting the
  1. sleep 5s
Copy the Code
before you execute the command. That code seems to work in my terminal and should work in your script too. Shouldn't take to long to confirm wether or not it actually works in practice, could you let me know if it is actually as simple as that?
UPDATE:
I dont know if I was clear enough. Just put the code in between the executed codes for example to let them wait 5 seconds for each execution.
Reply View the author
dance707
deepin
2016-03-03 15:33
#15
https://bbs.deepin.org/post/30786
What I am assuming is that you want the command to be executed with a delay of 5 seconds. Which I t ...

Yes it worked thank you very much, I was not aware of the sleep command.
Reply View the author
jotapesse
deepin
2016-03-03 15:37
#16
Edited by jotapesse at 2016-3-3 00:35
https://bbs.deepin.org/post/30786
Okay so I have a working script so far:

Ok, I have a worked out a more friendly script for you. It works for me although I haven't fully tested it. Tell me if it works for you.
A few notes: if your displays EDID is correctly constructed, you only require the first 16 bytes (first string line in xrandr EDID result), as per specification it includes the Manufacturer code, Product code and Serial number. It should be enough to uniquely identify displays, even if they are from the same manufaturer and same model. The remaining EDID strings address settings and other information.

Edit: removed previous script, corrected an error. Here it is:
http://ideone.com/GGnXo6
Reply View the author
barthodian
deepin
2016-03-03 16:52
#17
https://bbs.deepin.org/post/30786
Ok, I have a worked out a more friendly script for you. It works for me although I haven't fully te ...

There appears to be a syntax error on line 13:
  1. test.sh: 13: test.sh: Syntax error: "(" unexpected
Copy the Code


However, from the look of it, this is exactly what I was tryin' to create on my own. My goodness, it almost seems like you did all this in 20 minutes while I'm sitting here just figuring things out. Gawddamn. Much appreciated man! Almost too much effort there... What's your game!?


I'm looking at the syntax error right now...
Reply View the author
barthodian
deepin
2016-03-03 17:04
#18
Sorry, my bad. Didn't set file permission to +x
  1. chmod +x test.sh
Copy the Code

did the job.

Everything works excellent. Thank you very much
Reply View the author
jotapesse
deepin
2016-03-04 01:26
#19
Edited by jotapesse at 2016-3-3 20:01
https://bbs.deepin.org/post/30786
Sorry, my bad. Didn't set file permission to +x

did the job.

Glad it worked for you. Actually it took me a few hours, I haven't played with bash for a while. I like challenges. It's fun. :-)
Reply View the author