Welcome
Welcome to refracta

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!

fixdisplay.sh - xrandr scripted

Stuff that has not yet gone into the official build.

fixdisplay.sh - xrandr scripted

Postby fsmithred » Mon Oct 28, 2013 4:49 pm

Here's another one. This one uses cvt to get a modeline and then uses xrandr to set the screen resolution.
Code: Select all
#!/usr/bin/env bash

echo "
Run this script with no options for 1280x1024.
For any other resolutions, put the horizontal and vertical
sizes on the command line.

Example:
      fixdisplay 1400 900
"

# Get the modeline from the command:
#   cvt 1280 1024
#

# Use default display resolution if they
# aren't given in the command arguments.
if [[ $1 ]] ; then
   horiz_res="$1"
else
   horiz_res="1280"
fi

if [[ $2 ]] ; then
   vert_res="$2"
else
   vert_res="1024"
fi


list=$(cvt $horiz_res $vert_res | awk '/Modeline/ { print  $3 " " $4 " " $5 " " $6 " " $7 " " $8 " " $9 " " $10 " " $11 }')
modeline="$list"
echo -e "\nModeline for $horiz_res x $vert_res"
echo "${modeline[0]}"

all_outputs=$(xrandr | awk '/ connected/ { print $1 }')

echo "
If all_outputs = default (see below) then this script
probably won't work. You can try it, or you can abort by
pressing ctrl-c
"
echo -e "\tall_outputs = $all_outputs"
#if $(echo $all_outputs | grep -q ^default) ; then
#   echo "Exit due to error."
#   exit 1
#fi
#sleep 2
#echo " Enter an output from this list:
#$all_outputs
#: "
#read output

echo -e "\nSelect a video output from the list:"
select output in "$all_outputs" ; do
   echo "$output"
   break
done


xrandr --newmode disp$horiz_res ${modeline[@]}
sleep 2
echo "1111"
xrandr --addmode "$output" disp$horiz_res
sleep 2
echo "2222"
xrandr --output "$output" --mode disp$horiz_res
echo "3333"

exit 0


Edit: got rid of the -e in the tests for $1 and $2. For some reason, that doesn't seem to work for me lately. This has happened in a couple of scripts. No idea what's up with that.

N.B. This script only works with some monitors, and it doesn't work with my dual monitor setup. Seems like the main problem is how the output gets listed. Names like VGA-1, DVI-blah work better. If you try it, please share the output from xrandr run in a terminal. Thanks.
User avatar
fsmithred
 
Posts: 2101
Joined: Wed Mar 09, 2011 9:13 pm

Return to Experimental

Who is online

Users browsing this forum: No registered users and 0 guests

cron
suspicion-preferred