From The Compiler, 6 Years ago, written in Bash.
Embed
  1. #!/bin/bash
  2. # vim: set fileencoding=utf-8 ts=4 sts=4 sw=4 tw=80 expandtab :
  3.  
  4. # Copyright (C) 2012 Florian Bruhin <me@the-compiler.org>
  5.  
  6. # xrotate is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # xrotate is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with xrotate  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. wacomdevices=('Wacom ISDv4 E6 '{'Pen stylus','Pen eraser','Finger touch'})
  20. areadevices=('Wacom ISDv4 E6 '{'Pen stylus','Pen eraser'})
  21. user=florian
  22.  
  23. rotate() {
  24.     # Set parameters based on rotation direction
  25.     case "$1" in
  26.         normal) xrandr=normal; wacom=none; herbstluft=1366x768; subpixel=rgb;
  27.                 min_x=105; min_y=55; max_x=27553; max_y=15556 ;;
  28.         inverted) xrandr=inverted; wacom=half; herbstluft=1366x768;
  29.                   subpixel=bgr; min_x=105; min_y=55; max_x=27553; max_y=15556
  30.                   ;;
  31.         right) xrandr=right; wacom=cw; herbstluft=768x1366; subpixel=vrgb;
  32.                min_x=133; min_y=54; max_x=27554; max_y=15616 ;;
  33.         left) xrandr=left; wacom=ccw; herbstluft=768x1366; subpixel=vbgr;
  34.               min_x=133; min_y=54; max_x=27554; max_y=15616 ;;
  35.     esac
  36.     # Rotate the display
  37.     if [[ $2 != noxrandr ]]; then
  38.         xrandr --output LVDS1 --rotate "$xrandr" &
  39.     fi
  40.     # Tell the windowmanager to adjust its windows
  41.     herbstclient move_monitor 0 "$herbstluft" &
  42.     # Rotate window splits
  43.     [[ $2 == rotate ]] && herbstclient rotate &
  44.     # Rotate touchscreen
  45.     for device in "${wacomdevices[@]}"; do
  46.         xsetwacom --set "$device" Rotate "$wacom" &
  47.     done
  48.     # Set calibration
  49.     for device in "${areadevices[@]}"; do
  50.         xsetwacom --set "$device" Area "$min_x" "$min_y" "$max_x" "$max_y" &
  51.     done
  52.     # Adjust the font rendering
  53.     gconftool-2 -t string -s /desktop/gnome/font_rendering/rgba_order \
  54.         $subpixel &
  55.     # Hide and re-show Onboard
  56.     /home/$user/bin/onboardctl rotate &
  57.     # Hide and re-show trayer
  58.     killall trayer
  59.     /home/$user/bin/panel2/tray.sh &
  60. }
  61.  
  62. case $1 in
  63.     normal|inverted|right|left) rotate "$1" "$2" ;; # absolute rotation
  64.     *) # Relative rotation, so we need to know the current rotation
  65.         currot=$(xrandr --verbose -q -o normal --dryrun | \
  66.                  sed -n 's/^Current rotation - //p')
  67.         # Clockwise
  68.         [[ $1 == cw     && $currot == normal   ]] && rotate right rotate
  69.         [[ $1 == cw     && $currot == left     ]] && rotate normal rotate
  70.         [[ $1 == cw     && $currot == inverted ]] && rotate left rotate
  71.         [[ $1 == cw     && $currot == right    ]] && rotate inverted rotate
  72.         # Counter-clockwise
  73.         [[ $1 == ccw    && $currot == normal   ]] && rotate left rotate
  74.         [[ $1 == ccw    && $currot == left     ]] && rotate inverted rotate
  75.         [[ $1 == ccw    && $currot == inverted ]] && rotate right rotate
  76.         [[ $1 == ccw    && $currot == right    ]] && rotate normal rotate
  77.         # Toggle between left/normal
  78.         [[ $1 == toggle && $currot == left     ]] && rotate normal rotate
  79.         [[ $1 == toggle && $currot == normal   ]] && rotate left rotate
  80.     ;;
  81. esac