-
Notifications
You must be signed in to change notification settings - Fork 0
/
i3quit.pl
executable file
·58 lines (49 loc) · 952 Bytes
/
i3quit.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
#!/usr/bin/perl
use AnyEvent;
use AnyEvent::I3;
# data variables
#
my $clients_no = 0;
#
print "Trying to connect to i3\n";
my $i3 = i3();
if($i3->connect->recv)
{
print "Connected to i3\n";
}
if($i3->subscribe({
window => sub {
my ($c) = @_;
if($c->{'change'} eq "new")
{
$clients_no += 1;
print "Window created: $clients_no\n";
}
elsif($c->{'change'} eq "close")
{
$clients_no -= 1;
print "Window closed: $clients_no\n";
}
},
binding => sub {
my ($msg) = @_;
if($msg->{'binding'}->{'command'} eq "nop exit")
{
if($clients_no <= 0)
{
system("i3-msg exit");
} else {
system("i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'");
}
}
},
_error => sub {
my ($msg) = @_;
print "Sorry, but: $msg";
}
})->recv->{success})
{
print "Subscribed\n";
}
AE::cv->recv;
# vim:ts=3:sw=3:noet