-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotify.pl
71 lines (59 loc) · 1.47 KB
/
notify.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#This Code is Licenced under the Perl Artistic License
#you might have been able to get this License if you got this Code
use 5.01;
use Desktop::Notify;
my ($watch, $prefix, $notify_daemon) =
("", 'activityWatcher-');
sub on_start{
my ($t) = @_;
$t->parse_keysym("M-C-a", "perl:$prefix"."activity");
$t->parse_keysym("M-C-i", "perl:$prefix"."inactivity");
$notify_daemon = Desktop::Notify->new();
()
}
sub on_user_command {
my($term, $string) = @_;
if($string =~ /$prefix(.*)$/){
if($watch eq $1){
$watch = '';
delete $term->{activity_ov};
delete $term->{inactivity_timer};
} else {
$watch = $1;
$term->{activity_ov} = $term->overlay_simple(-1, 0, $watch);
if($watch eq 'inactivity'){
$term->{inactivity_timer} = urxvt::timer
-> new
-> after(2)
-> cb(sub{
my_notify('inactive');
$watch = "";
delete $term->{activity_ov};
delete $term->{inactivity_timer};
});
}
}
}
()
}
sub on_add_lines {
if($watch eq 'activity'){
my_notify('active');
$watch = "";
delete $term->{activity_ov};
}
elsif($watch eq 'inactivity'){
$term->{inactivity_timer}->after(2);
}
()
}
sub my_notify {
my($what) = @_;
warn "my notify called whith: @_)";
$notify_daemon->create(summary => "Shell was $what",
timeout => 5000,
body => <<BODY )
You requested to be notified, when the shell goes $what.
BODY
->show();
}