forked from cppvik/teleperl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnyEvTkx.pm
70 lines (54 loc) · 1.55 KB
/
AnyEvTkx.pm
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
package AnyEvTkx;
# FIXME it's a quick hack, inherit most from Impl::Perl
use AnyEvent (); BEGIN { AnyEvent::common_sense }
use AnyEvent::Loop;
use Tkx;
our $VERSION = $AnyEvent::VERSION;
# time() is provided via AnyEvent::Base
*AE::now = \&AnyEvent::Loop::now;
*AE::now_update = \&AnyEvent::Loop::now_update;
*AE::io = \&AnyEvent::Loop::io;
*AE::timer = \&AnyEvent::Loop::timer;
*AE::idle = \&AnyEvent::Loop::idle;
*loop = \&MainLoop; # compatibility with AnyEvent < 6.0
*Tkx::MainLoop = \&MainLoop;
*now_update = \&AnyEvent::Loop::now_update;
sub now { $AnyEvent::Loop::NOW }
sub _poll {
Tkx::i::DoOneEvent(0);
}
my $ae_idle = 0;
sub return_to_perl_event_loop {
Tkx::after(40, \&return_to_perl_event_loop);
$ae_idle = 0;
AnyEvent::Loop::one_event while not $ae_idle;
}
sub MainLoop () {
# don't wait too much in AE's select() if nothing - guard timer
my $ae_interrupt = AnyEvent->timer(
after => 0.2,
interval => 1/20,
cb => sub { 1 },
);
my $ae_to_tk = AnyEvent->idle(
cb => sub {
$ae_idle = 1;
});
Tkx::after(20, \&return_to_perl_event_loop);
while (eval { local $Tkx::TRACE; Tkx::i::call("winfo", "exists", ".") }) {
Tkx::i::DoOneEvent(0);
}
}
sub io {
my (undef, %arg) = @_;
AnyEvent::Loop::io $arg{fh}, $arg{poll} eq "w", $arg{cb}
}
sub timer {
my (undef, %arg) = @_;
AnyEvent::Loop::timer $arg{after}, $arg{interval}, $arg{cb}
}
sub idle {
my (undef, %arg) = @_;
AnyEvent::Loop::idle $arg{cb}
}
1;