From ff3dfc91aebd454323a25baf6ffd8c9145747564 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 6 Apr 2023 17:25:36 +0800 Subject: WIP --- X11/openbox/rc.xml | 16 +--------------- X11/show_timer.sh | 17 +++++++++++++++++ bin/unix/timer.sh | 5 +++++ 3 files changed, 23 insertions(+), 15 deletions(-) create mode 100755 X11/show_timer.sh diff --git a/X11/openbox/rc.xml b/X11/openbox/rc.xml index f08a79c..7b923cd 100644 --- a/X11/openbox/rc.xml +++ b/X11/openbox/rc.xml @@ -514,21 +514,7 @@ - - sh -c ' - origin=`xdotool getactivewindow`; \ - xdotool search --name "TIMER" windowactivate || \ - alacritty --title TIMER --hold \ - -o "window.dimensions.columns=8" \ - -o "window.dimensions.lines=1" \ - -o "window.position.x=-0" \ - -o "window.position.y=0" \ - -o "window.opacity=0.6" \ - -o "font.size=40" \ - -e ~/helper/bin/unix/timer.sh SIGINT \ - "xdotool windowactivate $origin" - ' - + ~/helper/X11/show_timer.sh diff --git a/X11/show_timer.sh b/X11/show_timer.sh new file mode 100755 index 0000000..6ff405a --- /dev/null +++ b/X11/show_timer.sh @@ -0,0 +1,17 @@ +#! /bin/sh + +export origin=`xdotool getactivewindow`; \ + +# If timer is set, focus to it +xdotool search --name "TIMER" windowactivate && exit 0 + +# Add new window for a timer +# Use SIGINT +alacritty --title TIMER --hold \ + -o "window.dimensions.columns=8" \ + -o "window.dimensions.lines=1" \ + -o "window.position.x=-0" \ + -o "window.position.y=0" \ + -o "window.opacity=0.6" \ + -o "font.size=40" \ + -e sh -c '~/helper/bin/unix/timer.sh SIGINT "xdotool windowactivate $origin"' diff --git a/bin/unix/timer.sh b/bin/unix/timer.sh index 3abe701..152d828 100755 --- a/bin/unix/timer.sh +++ b/bin/unix/timer.sh @@ -1,6 +1,9 @@ #! /bin/bash # Ref: https://superuser.com/questions/611538/611582#611582 +exec 3>&1 +exec 1>/dev/tty + SIGNAL=${1:-SIGTERM} COMMAND="$2" @@ -75,6 +78,8 @@ timer() { done } +trap 'exec 1>&3; echo $count; send-notify foo' EXIT KILL TERM STOP + while [ $count -lt $SET ]; do [ $stop = true ] && sleep 0.3 && continue timer -- cgit v1.2.3-70-g09d2