aboutsummaryrefslogtreecommitdiff
path: root/xres
blob: 90aff6b3eb9b910115682d8896533875c63c49a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
#
# Wrapper around xrandr to set screen resolution.
#

# Parameters
BASENAME="`basename $0`"
X="$1"
Y="$2"
INTERFACE="$3"

# Check
if [ -z "$Y" ]; then
  echo "usage: $BASENAME <x-res> <y-res> <interface>"
  exit 1
elif ! which cvt &> /dev/null; then
  echo "please install cvt from xserver-xorg-core"
  exit 1
elif ! which xrandr &> /dev/null; then
  echo "please install xrandr from x11-xserver-utils"
  exit 1
fi

# Get modeline and interface
MODELINE="`cvt $X $Y | grep -v '^#' | sed -e 's/^Modeline //'`"
NAME="`echo $MODELINE | cut -d ' ' -f 1 | sed -e 's/"//g'`"

# Fallback to the first connected interface found
if [ -z "$INTERFACE" ]; then
  INTERFACE="`xrandr | grep " connected" | cut -d ' ' -f 1 | head -1`"
fi

# Apply
xrandr --newmode $MODELINE &> /dev/null
xrandr --addmode $INTERFACE $NAME
xrandr --output  $INTERFACE --mode $NAME