line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flower::Chronos::Tracker; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
28390
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
476
|
use Flower::Chronos::X11; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
590
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
10
|
|
|
10
|
0
|
8095
|
my $class = shift; |
10
|
10
|
|
|
|
|
21
|
my (%params) = @_; |
11
|
|
|
|
|
|
|
|
12
|
10
|
|
|
|
|
16
|
my $self = {}; |
13
|
10
|
|
|
|
|
17
|
bless $self, $class; |
14
|
|
|
|
|
|
|
|
15
|
10
|
|
100
|
|
|
54
|
$self->{idle_timeout} = $params{idle_timeout} || 300; |
16
|
10
|
|
100
|
|
|
38
|
$self->{flush_timeout} = $params{flush_timeout} || 300; |
17
|
10
|
|
|
|
|
19
|
$self->{applications} = $params{applications}; |
18
|
10
|
|
|
|
|
17
|
$self->{on_end} = $params{on_end}; |
19
|
|
|
|
|
|
|
|
20
|
10
|
|
|
|
|
27
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub track { |
24
|
18
|
|
|
18
|
0
|
13951
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
18
|
100
|
|
|
|
63
|
if ($self->_is_time_to_flush) { |
27
|
2
|
50
|
|
|
|
3
|
if (%{$self->{prev} || {}}) { |
|
2
|
50
|
|
|
|
11
|
|
28
|
|
|
|
|
|
|
$self->{prev}->{_end} = |
29
|
2
|
|
|
|
|
6
|
$self->{prev}->{_start} + $self->{flush_timeout}; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
5
|
$self->{on_end}->($self->{prev}); |
32
|
2
|
|
|
|
|
8
|
$self->{prev} = {}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
18
|
|
66
|
|
|
69
|
my $x11 = $self->{x11} ||= $self->_build_x11; |
37
|
|
|
|
|
|
|
|
38
|
18
|
|
|
|
|
411
|
my $info; |
39
|
18
|
50
|
|
|
|
135
|
if ($x11->idle_time > $self->{idle_timeout}) { |
40
|
0
|
|
|
|
|
0
|
$info = {idle => 1, category => ''}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
18
|
|
|
|
|
825
|
$info = $x11->get_active_window; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
18
|
|
100
|
|
|
643
|
my $prev = $self->{prev} ||= {}; |
47
|
18
|
|
|
|
|
42
|
my $time = $self->_time; |
48
|
|
|
|
|
|
|
|
49
|
18
|
50
|
|
|
|
188
|
$self->_run_applications($info) unless $info->{idle}; |
50
|
|
|
|
|
|
|
|
51
|
18
|
|
100
|
|
|
212
|
$info->{$_} //= '' for (qw/id name role class/); |
52
|
18
|
|
100
|
|
|
60
|
$info->{application} //= 'other'; |
53
|
18
|
|
50
|
|
|
65
|
$info->{category} //= 'other'; |
54
|
|
|
|
|
|
|
|
55
|
18
|
50
|
100
|
|
|
81
|
if ( !$prev->{id} |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
56
|
|
|
|
|
|
|
|| $info->{id} ne $prev->{id} |
57
|
|
|
|
|
|
|
|| $info->{name} ne $prev->{name} |
58
|
|
|
|
|
|
|
|| $info->{role} ne $prev->{role} |
59
|
|
|
|
|
|
|
|| $info->{class} ne $prev->{class}) |
60
|
|
|
|
|
|
|
{ |
61
|
17
|
100
|
|
|
|
37
|
if (%$prev) { |
62
|
5
|
|
|
|
|
11
|
$prev->{_end} = $time; |
63
|
5
|
|
|
|
|
16
|
$self->{on_end}->($prev); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
17
|
|
66
|
|
|
85
|
$info->{_start} ||= $time; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
18
|
|
|
|
|
30
|
$self->{prev} = $info; |
70
|
18
|
|
100
|
|
|
47
|
$self->{prev}->{_start} ||= $time; |
71
|
|
|
|
|
|
|
|
72
|
18
|
|
|
|
|
41
|
return $self; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _run_applications { |
76
|
18
|
|
|
18
|
|
23
|
my $self = shift; |
77
|
18
|
|
|
|
|
26
|
my ($info) = @_; |
78
|
|
|
|
|
|
|
|
79
|
18
|
|
|
|
|
24
|
foreach my $application (@{$self->{applications}}) { |
|
18
|
|
|
|
|
44
|
|
80
|
9
|
|
|
|
|
11
|
local $@; |
81
|
9
|
|
|
|
|
16
|
my $rv = eval { $application->run($info) }; |
|
9
|
|
|
|
|
22
|
|
82
|
9
|
100
|
|
|
|
61
|
next if $@; |
83
|
|
|
|
|
|
|
|
84
|
8
|
100
|
|
|
|
26
|
last if $rv; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _is_time_to_flush { |
89
|
18
|
|
|
18
|
|
24
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
18
|
|
100
|
|
|
112
|
$self->{flush_time} //= $self->_time; |
92
|
|
|
|
|
|
|
|
93
|
18
|
100
|
|
|
|
117
|
if ($self->_time - $self->{flush_time} > $self->{flush_timeout}) { |
94
|
2
|
|
|
|
|
16
|
$self->{flush_time} = $self->_time; |
95
|
2
|
|
|
|
|
11
|
return 1; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
16
|
|
|
|
|
202
|
return 0; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _build_x11 { |
102
|
0
|
|
|
0
|
|
0
|
return Flower::Chronos::X11->new; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
43
|
|
|
43
|
|
103
|
sub _time { time } |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |