#!/usr/bin/perl -w # tea timer for wmii # Copyright (C) 2007 Christoph Berg # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. use strict; use POSIX ":sys_wait_h"; my $timeout = 300; my $timer = $timeout; my $run; sub update { $| = 1; printf "%s\%d:\%02d", $timer < 0 ? "-" : "", abs($timer) / 60, abs($timer) % 60 or exit 1; } sub startstop { $run = !$run; $timer = $timeout; $SIG{PWR} = \&startstop; } $SIG{PWR} = \&startstop; sub dec { $timeout -= 30; if (!$run) { $timer = $timeout; } $SIG{USR1} = \&dec; } $SIG{USR1} = \&dec; sub inc { $timeout += 30; if (!$run) { $timer = $timeout; } $SIG{USR2} = \&inc; } $SIG{USR2} = \&inc; sub child { if ($run) { startstop; } waitpid(-1, WNOHANG); $SIG{CHLD} = \&child; } $SIG{CHLD} = \&child; while (1) { while ($run) { $timer--; sleep 1; update if $run; if ($run and $timer == 0) { if (!fork) { system "xmessage 'READY.'"; exit; } } } update; sleep 10000000; }