aboutsummaryrefslogtreecommitdiff
path: root/xres
blob: 273e2eeda5e7aecb22ac77684bfbdb59c22a3c5a (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
#
# Wrapper around xrandr to set screen resolution.
#

# Parameters
BASENAME="`basename $0`"
RESOLUTION="$1"
INTERFACE="$2"
#XRES="$1"
#YRES="$2"
#INTERFACE="$3"

# Check
#if [ -z "$Y" ]; then
if [ -z "$RESOLUTION" ]; then
  #echo "usage: $BASENAME <x-res> <y-res> <interface>"
  echo "usage: $BASENAME <x-res>x<y-res> <interface>"
  echo "example:"
  echo ""
  echo "  $BASENAME HDMI-2 1680x1050"
  echo ""
  echo "for simpler usage, try xrandr directly, like:"
  echo  ""
  echo "  xrandr --output HDMI-2 --mode 1680x1050"
  echo ""
  echo "Available screens and resolutions"
  echo "---------------------------------"
  echo ""
  xrandr
  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

# Parse resolution
XRES="`echo $RESOLUTION | cut -d 'x' -f 1`"
YRES="`echo $RESOLUTION | cut -d 'x' -f 2`"

# Check resolution
if [ -z "$XRES" ]; then
  echo "$BASENAME: invalid value for x-res"
  exit 1
elif [ -z "$YRES" ]; then
  echo "$BASENAME: invalid value for y-res"
  exit 1
fi

# Get modeline and interface
MODELINE="`cvt $XRES $YRES | 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