diff options
| -rw-r--r-- | X11/openbox/rc.xml | 18 | ||||
| -rwxr-xr-x | bin/unix/timer.sh | 12 |
2 files changed, 19 insertions, 11 deletions
diff --git a/X11/openbox/rc.xml b/X11/openbox/rc.xml index e7736f8..d7c0345 100644 --- a/X11/openbox/rc.xml +++ b/X11/openbox/rc.xml | |||
| @@ -499,15 +499,17 @@ | |||
| 499 | <action name="Execute"> | 499 | <action name="Execute"> |
| 500 | <command> | 500 | <command> |
| 501 | sh -c ' | 501 | sh -c ' |
| 502 | origin=`xdotool getactivewindow`; \ | ||
| 502 | xdotool search --name "TIMER" windowactivate || \ | 503 | xdotool search --name "TIMER" windowactivate || \ |
| 503 | alacritty --title TIMER --hold \ | 504 | alacritty --title TIMER --hold \ |
| 504 | -o "window.dimensions.columns=8" \ | 505 | -o "window.dimensions.columns=8" \ |
| 505 | -o "window.dimensions.lines=1" \ | 506 | -o "window.dimensions.lines=1" \ |
| 506 | -o "window.position.x=-0" \ | 507 | -o "window.position.x=-0" \ |
| 507 | -o "window.position.y=0" \ | 508 | -o "window.position.y=0" \ |
| 508 | -o "window.opacity=0.6" \ | 509 | -o "window.opacity=0.6" \ |
| 509 | -o "font.size=40" \ | 510 | -o "font.size=40" \ |
| 510 | -e ~/helper/bin/unix/timer.sh SIGINT | 511 | -e ~/helper/bin/unix/timer.sh SIGINT \ |
| 512 | "xdotool windowactivate $origin" | ||
| 511 | ' | 513 | ' |
| 512 | </command> | 514 | </command> |
| 513 | </action> | 515 | </action> |
diff --git a/bin/unix/timer.sh b/bin/unix/timer.sh index ca807e8..3abe701 100755 --- a/bin/unix/timer.sh +++ b/bin/unix/timer.sh | |||
| @@ -2,9 +2,11 @@ | |||
| 2 | # Ref: https://superuser.com/questions/611538/611582#611582 | 2 | # Ref: https://superuser.com/questions/611538/611582#611582 |
| 3 | 3 | ||
| 4 | SIGNAL=${1:-SIGTERM} | 4 | SIGNAL=${1:-SIGTERM} |
| 5 | COMMAND="$2" | ||
| 5 | 6 | ||
| 6 | # If SIGNAL is received, switch to next display | 7 | # If SIGNAL is received, switch to next display |
| 7 | trap 'next_display' "$SIGNAL" | 8 | trap 'next_display' "$SIGNAL" |
| 9 | # Use SIGTSTP (Ctrl-Z in most of the cases) to stop/restart timer | ||
| 8 | trap 'toggle_timer' SIGTSTP | 10 | trap 'toggle_timer' SIGTSTP |
| 9 | 11 | ||
| 10 | # Do not print "^C" when SIGINT caught | 12 | # Do not print "^C" when SIGINT caught |
| @@ -14,10 +16,10 @@ stty -ctlecho | |||
| 14 | tput civis | 16 | tput civis |
| 15 | 17 | ||
| 16 | display_list=(STOPWATCH COUNTDOWN PERIOD) | 18 | display_list=(STOPWATCH COUNTDOWN PERIOD) |
| 17 | export DISPLAY=0 | 19 | display=0 |
| 18 | 20 | ||
| 19 | next_display() { | 21 | next_display() { |
| 20 | export DISPLAY=$(( ("$DISPLAY" + 1) %${#display_list[@]} )) | 22 | display=$(( ("$display" + 1) %${#display_list[@]} )) |
| 21 | } | 23 | } |
| 22 | 24 | ||
| 23 | export stop=0 | 25 | export stop=0 |
| @@ -29,6 +31,10 @@ toggle_timer() { | |||
| 29 | read -p '? ' -r input | 31 | read -p '? ' -r input |
| 30 | # Disable input on terminal | 32 | # Disable input on terminal |
| 31 | stty -echo | 33 | stty -echo |
| 34 | # If COMMAND is given, run it after timer is set | ||
| 35 | result="$([ -n "$COMMAND" ] && eval "$COMMAND" 2>&1)" | ||
| 36 | notify-send "$result" &>/tmp/openbox | ||
| 37 | |||
| 32 | 38 | ||
| 33 | # Modify input to fit the format that `date` can read | 39 | # Modify input to fit the format that `date` can read |
| 34 | hour=$(grep -o '[0-9.]\+h' <<<"$input" | tr -d h) | 40 | hour=$(grep -o '[0-9.]\+h' <<<"$input" | tr -d h) |
| @@ -53,7 +59,7 @@ timer() { | |||
| 53 | [ $stop = 1 ] && sleep 0.3 && break | 59 | [ $stop = 1 ] && sleep 0.3 && break |
| 54 | 60 | ||
| 55 | count=$(( count_from + $(date +%s) - start )) | 61 | count=$(( count_from + $(date +%s) - start )) |
| 56 | case ${display_list[$DISPLAY]} in | 62 | case ${display_list[$display]} in |
| 57 | STOPWATCH) | 63 | STOPWATCH) |
| 58 | printf '%s\r' "$(date -u -d @$count +%H:%M:%S)" | 64 | printf '%s\r' "$(date -u -d @$count +%H:%M:%S)" |
| 59 | ;; | 65 | ;; |