]> git.siccegge.de Git - dotfiles/zsh.git/blob - functions/cip/sunray_resolution
Import Desktop zshconfig
[dotfiles/zsh.git] / functions / cip / sunray_resolution
1 #!/usr/bin/zsh
2 # License: GPLv3+
3
4 RES=('1280x1024' '1920x1200')
5
6 if [[ -n ${1} ]]; then
7 typeset -A RESMAP
8 RESMAP=('02.150' '2'
9 '02.133' '2')
10 read -A ROOM <<< $(${HOME}/bin/cipmap.sh -l|grep ${USER})
11 # Note: Alter the number below such that it reflects the
12 # position of the Room-ID in the cipmap.sh output
13 # for your user; counting from right to left.
14 ROOM=${ROOM[-2]}
15
16 NEXT=${RESMAP[${ROOM}]}
17 NEXT=${NEXT:-1}
18 else
19 read -A CURRENT <<< $(grep '*' - < <(xrandr))
20 CURRENT=${CURRENT[1]}
21
22 for INDEX in {1..${#RES}}; do
23 if [[ "${CURRENT}" == "${RES[${INDEX}]}" ]]; then
24 if [[ ${INDEX} -lt ${#RES} ]]; then
25 NEXT=$(( INDEX+1 ))
26 else
27 NEXT=1
28 fi
29 break
30 fi
31 done;
32 fi
33
34 # Try to set new resolution.
35 TRIES=1; RUN=1
36 while [[ ${TRIES} -lt 33 && ${RUN} -eq 1 ]]; do
37 if xrandr -s ${RES[${NEXT}]} > /dev/null; then
38 RUN=0;
39 else
40 print -- 'Error: Failed setting resolution!'
41 print -- " Current: ${CURRENT} - Next: ${RESOLUTIONS[${NEXT}]}"
42 sleep .1
43 (( TRIES++ ))
44 fi
45 done