#!/bin/bash ### Configuration LID="/proc/acpi/button/lid/LID" # lid status path SPOOL_FILE="/var/spool/rotate-screen/rotation" # 'rotate-screen' command run-file ### ROTATED=0 while inotifywait "$SPOOL_FILE"; do # get current rotation state from run file if it exists DISPLAY="$(cat $SPOOL_FILE | cut -d' ' -f2)" XAUTH="$(cat $SPOOL_FILE | cut -d' ' -f3)" ROTATION="$(XAUTHORITY=$XAUTH DISPLAY=$DISPLAY xrandr --query --verbose | grep " connected" | cut -d' ' -f5)" LID_STATE="$(cat $LID/state | awk '{print $2}')" HIBERNATING=$(ps aux | grep '[h]ibernate') if [ $ROTATED = 0 -a x"$LID_STATE" = x"closed" -a ! x"$ROTATION" = x"normal" -a x"$HIBERNATING" = x ]; then # commands to run when transitionaing to tablet mode ln -sf ~/.xmonad/xmonad-tablet.hs ~/.xmonad/xmonad.hs ln -sf ~/.xmonad/xmonad-tablet-i386-linux ~/.xmonad/xmonad-i386-linux xmonad --restart ROTATED=1 elif [ $ROTATED = 1 -a x"$LID_STATE" = x"open" -a x"$ROTATION" = x"normal" ]; then # commands to run when transitionaing to laptop mode dzen-pager stop ln -sf ~/.xmonad/xmonad-laptop.hs ~/.xmonad/xmonad.hs ln -sf ~/.xmonad/xmonad-laptop-i386-linux ~/.xmonad/xmonad-i386-linux xmonad --restart ROTATED=0 fi done