| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Event::ScreenSaver::Unix; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Created on: 2009-07-08 05:33:45 |
|
4
|
|
|
|
|
|
|
# Create by: Ivan Wills |
|
5
|
|
|
|
|
|
|
# $Id$ |
|
6
|
|
|
|
|
|
|
# $Revision$, $HeadURL$, $Date$ |
|
7
|
|
|
|
|
|
|
# $Revision$, $Source$, $Date$ |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
3352
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use warnings; |
|
11
|
|
|
|
|
|
|
use version; |
|
12
|
|
|
|
|
|
|
use Carp; |
|
13
|
|
|
|
|
|
|
use List::MoreUtils qw/any/; |
|
14
|
|
|
|
|
|
|
use Data::Dumper qw/Dumper/; |
|
15
|
|
|
|
|
|
|
use English qw/ -no_match_vars /; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = version->new('0.0.5'); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has start => ( |
|
20
|
|
|
|
|
|
|
is => 'rw', |
|
21
|
|
|
|
|
|
|
isa => 'CodeRef', |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
has stop => ( |
|
24
|
|
|
|
|
|
|
is => 'rw', |
|
25
|
|
|
|
|
|
|
isa => 'CodeRef', |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
has type => ( |
|
28
|
|
|
|
|
|
|
is => 'rw', |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub run { |
|
32
|
|
|
|
|
|
|
my ($self) = @_; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if ( !$self->type ) { |
|
35
|
|
|
|
|
|
|
eval { require X11::Protocol }; |
|
36
|
|
|
|
|
|
|
$self->type( $EVAL_ERROR ? 'DBus' : 'X11' ); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
if ( $self->type eq 'X11' ) { |
|
40
|
|
|
|
|
|
|
$self->_run_x11(); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
elsif ( $self->type eq 'DBus' ) { |
|
43
|
|
|
|
|
|
|
$self->_run_dbus(); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _run_dbus { |
|
50
|
|
|
|
|
|
|
my ($self) = @_; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
eval { require Net::DBus::Reactor }; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
die "You need to install eather Net::DBus or X11::Protocol\n" if $EVAL_ERROR; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $reactor = Net::DBus::Reactor->main(); |
|
57
|
|
|
|
|
|
|
my $change = sub { |
|
58
|
|
|
|
|
|
|
my $active = shift; |
|
59
|
|
|
|
|
|
|
my $stop; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
if ($active) { |
|
62
|
|
|
|
|
|
|
$stop = $self->start->($self) if $self->start; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
else { |
|
65
|
|
|
|
|
|
|
$stop = $self->stop->($self) if $self->stop; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$reactor->shutdown if $stop; |
|
69
|
|
|
|
|
|
|
}; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $bus = Net::DBus->find; |
|
72
|
|
|
|
|
|
|
my $screensaver = $bus->get_service("org.gnome.ScreenSaver"); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $screensaver_object = $screensaver->get_object("/org/gnome/ScreenSaver", "org.gnome.ScreenSaver"); |
|
75
|
|
|
|
|
|
|
$screensaver_object->connect_to_signal( 'ActiveChanged', $change ); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$reactor->run(); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _run_x11 { |
|
83
|
|
|
|
|
|
|
my ($self) = @_; |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
eval { require X11::Protocol::Ext::DPMS }; |
|
86
|
|
|
|
|
|
|
die "You need to install eather Net::DBus or X11::Protocol\n" if $EVAL_ERROR; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $x = X11::Protocol->new(); |
|
89
|
|
|
|
|
|
|
$x->init_extension('DPMS'); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $power_level = ''; |
|
92
|
|
|
|
|
|
|
while (1) { |
|
93
|
|
|
|
|
|
|
my $old_pl = $power_level; |
|
94
|
|
|
|
|
|
|
($power_level, undef) = $x->DPMSInfo(); |
|
95
|
|
|
|
|
|
|
my $stop; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
if( $old_pl eq 'DPMSModeOn' && $power_level ne 'DPMSModeOn' ) { |
|
98
|
|
|
|
|
|
|
$stop = $self->start->($self) if $self->start; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
elsif ( $power_level eq 'DPMSModeOn' && $old_pl ne 'DPMSModeOn' ) { |
|
101
|
|
|
|
|
|
|
$stop = $self->stop->($self) if $self->stop; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
last if $stop; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sleep 60; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
return; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Event::ScreenSaver::Unix - Provides the Unix & Unix like screen saver |
|
119
|
|
|
|
|
|
|
monitoring code. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 VERSION |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This documentation refers to Event::ScreenSaver::Unix version 0.0.5. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
use Event::ScreenSaver::Unix; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# create the screen saver object |
|
130
|
|
|
|
|
|
|
my $ss = Event::ScreenSaver::Unix->new(); |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# add functions to events |
|
133
|
|
|
|
|
|
|
$ss->start( sub {print "The screen saver started\n" } ); |
|
134
|
|
|
|
|
|
|
$ss->stop( sub { print "The screen saver stopped\n" } ); |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# run the event handler |
|
137
|
|
|
|
|
|
|
$ss->run(); |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This library provides an easy way to hook to the starting and stopping of |
|
142
|
|
|
|
|
|
|
the screen saver (currently only in Unix like environments). |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
The call back functions are passed the current event object. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 C<start ( [$sub] )> |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Param: C<$sub> - sub - The starting call back function |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Return: sub - The currently set starting function |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Description: Sets/Gets the function that will be called when the screen |
|
155
|
|
|
|
|
|
|
saver is started. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 C<stop ( [$sub] )> |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Param: C<$sub> - sub - The stopping call back function |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Return: sub - The currently set stopping function |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Description: Sets/Gets the function that will be called when the screen |
|
164
|
|
|
|
|
|
|
saver is stopped. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 C<run ()> |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This function starts the process for listening for screen saver events. |
|
169
|
|
|
|
|
|
|
It does not return. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 INCOMPATIBILITIES |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
There appears to be an issue with L<Net::DBus> where if the code calling this module |
|
182
|
|
|
|
|
|
|
also uses Net::DBus the L<Net::DBus::Reactor> will not run. |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Please report problems to Ivan Wills (ivan.wills@gmail.com). |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Patches are welcome. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 AUTHOR |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Ivan Wills - (ivan.wills@gmail.com) |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Copyright (c) 2009 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). |
|
195
|
|
|
|
|
|
|
All rights reserved. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under |
|
198
|
|
|
|
|
|
|
the same terms as Perl itself. See L<perlartistic>. This program is |
|
199
|
|
|
|
|
|
|
distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|
200
|
|
|
|
|
|
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
|
201
|
|
|
|
|
|
|
PARTICULAR PURPOSE. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=cut |