Skip to content

Instantly share code, notes, and snippets.

@nemasu
Last active November 8, 2016 04:46
Show Gist options
  • Save nemasu/3974d1ab20e6ccc9dc14 to your computer and use it in GitHub Desktop.
Save nemasu/3974d1ab20e6ccc9dc14 to your computer and use it in GitHub Desktop.
xrandr force custom resolution
#!/bin/bash
#Usage: xrandr_force.sh <width>x<height>
#Eg: ./xrander_force.sh 1920x1080
#Just some random defaults
WIDTH=1300
HEIGHT=750
if [ -n "$1" ]; then
WIDTH=`echo $1 | sed -e 's/x.*//'`
HEIGHT=`echo $1 | sed -e 's/.*x//'`
fi
#First Screen
S=`xrandr | head -n2 | tail -n1 | sed -e 's/ connected.*//'`
#Generate modeline
L=`cvt ${WIDTH} ${HEIGHT} 60`
NEW_MODE=`echo $L | sed 's/.* Modeline //g' | sed 's/"//g'`
#New Width
NW=`echo $NEW_MODE | awk '{print $3;}'`
#New Height
NH=`echo $NEW_MODE | awk '{print $7;}'`
#Check if mode exists already
let M=`xrandr | grep "${NW}x${NH}_60.00" | wc -l`
if [ $M -eq 0 ]; then
xrandr --newmode $NEW_MODE
fi
#Add mode to screen
xrandr --addmode $S ${NW}x${NH}_60.00
#Set resolution
xrandr -s ${NW}x${NH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment