Release new version 2.13.0
[grml-scripts.git] / usr_bin / grml-resolution
1 #!/bin/bash
2 # Filename:      grml-resolution
3 # Purpose:       change X resolution via a simple menu frontend
4 # Authors:       Florian Keller <florian.keller@zuerich.ch>, (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 PN=$(basename $0)
10 RESOLUTION=$(mktemp)
11 ERROR=$(mktemp)
12
13 bailout(){
14   rm -f $RESOLUTION $ERROR
15   exit $1
16 }
17
18 trap bailout 1 2 3 15
19
20 main(){
21 # menu
22 COUNTER=0
23 STRING=""
24
25 # current mode
26 CURRENT_NUM=$(xrandr | awk '/\*/ {print $1}' | tr -d '*')
27 CURRENT_RESOLUTION=$(xrandr | awk '/\*/ {print $2 $3 $4}')
28
29 # menu
30 for i in $(xrandr | awk {'print $2$3$4'} | grep "^[0-9]") ; do
31   STRING="$STRING $COUNTER $i"
32   ((COUNTER++))
33 done
34
35 # Menu Tool
36 dialog --title "$PN" --menu "Change X resolution via xrandr (current resolution: $CURRENT_RESOLUTION):" 0 0 0 $STRING 2>$RESOLUTION
37 retval=$?
38 case $retval in
39       (1)   echo "Cancel pressed." ; exit 1 ;;
40       (255) echo "ESC pressed."    ; exit 1 ;;
41 esac
42
43 CHOSE=$(cat $RESOLUTION)
44
45 if [ "$CHOSE" = "$CURRENT_NUM" ] ; then
46    dialog --title "$PN" --msgbox "Chosen resolution corresponds to current resolution. No changes needed." 0 0
47 elif [ -n "$CHOSE" ] ; then
48   xrandr -s $CHOSE 2>$ERROR && \
49   dialog --title "$PN" --msgbox "Running xrandr with resolution was succesful." 0 0 || \
50   dialog --title "$PN" --msgbox "Error when running xrandr with resolution $CHOSE: `cat $ERROR`" 0 0
51 fi
52 }
53
54 while true ; do
55   main
56 done
57
58 bailout
59
60 # EOF #