#!/bin/bash


i=2
xset r off
xinput test-xi2 --root 3 | grep -A2 --line-buffered RawKeyRelease | while read -r line;
do
    if [[ $line == *"detail"* ]];
    then
        key=$(echo $line | sed "s/[^0-9]*//g")

        if ([ $key = "43" ] || [ $key = "113" ] || [ $key = "111" ] || [ $key = "44" ]); then
            i=$((i-1))
        elif([ $key = "46" ] || [ $key = "114" ] || [ $key = "116" ] || [ $key = "45" ]); then
            i=$((i+1))
        fi

        if [ $i = 5 ]; then
            i=0
        elif [ $i = -1 ]; then
            i=4
        fi
    fi

    case $i in
        0) dunstify -r 8 -a bottom-center -t 0 -u normal "﫼  LOG OUT" ;;
        1) dunstify -r 8 -a bottom-center -t 0 -u normal "  LOCK" ;;
        2) dunstify -r 8 -a bottom-center -t 0 -u normal "  POWER OFF" ;;
        3) dunstify -r 8 -a bottom-center -t 0 -u normal "ﰇ  REBOOT" ;;
        4) dunstify -r 8 -a bottom-center -t 0 -u normal "  RENEW DWM"  ;;
    esac
done
