line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Gtk3::Helper; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
906
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
90
|
|
10
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
211
|
use Glib; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub add_watch { |
15
|
|
|
|
|
|
|
shift; # lose the class |
16
|
|
|
|
|
|
|
my ($fd, $cond, $callback, $data) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# map 'in' and 'out' to GIO enums |
19
|
|
|
|
|
|
|
$cond = $cond eq 'in' ? 'G_IO_IN' : |
20
|
|
|
|
|
|
|
$cond eq 'out' ? 'G_IO_OUT' : |
21
|
|
|
|
|
|
|
croak "Invalid condition flag. Expecting: 'in' / 'out'"; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# In Gtk 1.x the callback was called also for the eof() / pipe close |
24
|
|
|
|
|
|
|
# events, but Gtk 2.x doesn't. We need to connect to the G_IO_HUP |
25
|
|
|
|
|
|
|
# event also to get this convenient behaviour again. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $tag = { |
28
|
|
|
|
|
|
|
io_id => Glib::IO->add_watch ($fd, $cond, $callback, $data), |
29
|
|
|
|
|
|
|
hup_id => Glib::IO->add_watch ($fd, 'G_IO_HUP', $callback, $data), |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
return $tag; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub remove_watch { |
36
|
|
|
|
|
|
|
shift; # lose the class |
37
|
|
|
|
|
|
|
my ($tag) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $rc_io = Glib::Source->remove ($tag->{io_id}); |
40
|
|
|
|
|
|
|
my $rc_hup = Glib::Source->remove ($tag->{hup_id}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
return ($rc_io && $rc_hup); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |