-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi3-wsbar
executable file
·119 lines (98 loc) · 2.36 KB
/
i3-wsbar
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env perl
use strict;
use warnings;
use Pod::Usage;
use IPC::Run qw(start pump);
use AnyEvent::I3;
use AnyEvent;
use v5.10;
my $dmplex = "";
if ($#ARGV >= 0) {
$dmplex = $ARGV[0] . " ";
}
my $i3 = i3;
my $workspaces = [];
# Disable buffering
$| = 1;
# Wait a short amount of time and try to connect to i3 again
sub reconnect {
my $timer;
my $c = sub {
$timer = AnyEvent->timer(
after => 0.01,
cb => sub { $i3->connect->cb(\&connected) }
);
};
$c->();
}
# Connection attempt succeeded or failed
sub connected {
my ($cv) = @_;
if (!$cv->recv) {
reconnect();
return;
}
$i3->subscribe({
workspace => \&ws_change,
_error => sub { reconnect() }
});
ws_change();
}
# Called when a ws changes
sub ws_change {
# Request the current workspaces and update the output afterwards
$i3->get_workspaces->cb(
sub {
my ($cv) = @_;
$workspaces = $cv->recv;
update_output();
}
);
}
sub update_output {
my $dzen_bg = "#111111";
my $out;
my $width = "1366";
#$out = qq|spotlight$dmplex|;
$out = qq|^pa(;0)|;
my @works = @{$workspaces};
my $lastitem = $works[$#works];
my $last = 0;
for my $ws (@{$workspaces})
{
$last = 0;
if ($lastitem == $ws) {
$last = 1;
}
my ($bg, $fg) = qw(333333 888888);
($bg, $fg) = qw(4c7899 ffffff) if $ws->{visible};
($bg, $fg) = qw(900000 ffffff) if $ws->{urgent};
my $cmd = q|i3-msg "workspace | . $ws->{num} . q|"|;
my $name = $ws->{name};
# Begin the clickable area
# $out .= qq|^bg(#$bg)|;
$out .= qq|^ca(1,$cmd)|;
# Draw the rest of the bar in the background color, but
# don’t move the "cursor"
$out .= qq|^p(_LOCK_X)^fg($dzen_bg)^r(${width}x20)^p(_UNLOCK_X)|;
# Draw the name of the workspace without overwriting the
# background color
$out .= qq|^p(+4;)^fg(#$fg)^ib(1)$name^ib(0)^p(+5;)|;
# Draw the rest of the bar in the normal background color
# without moving the "cursor"
if ($lastitem != $ws) {
$out .= qq|^fg(#111111)^r(5x20)^fg(#$fg)^fg(#111111)^r(5x20)|;# if !$ws->{visible};
}
# End the clickable area
$out .= qq|^ca()|;
# Move to the next rect, reset Y coordinate
$out .= qq|^p(0)^pa(;0)|;
}
$out .= qq|^p(+5)|;
$out .= qq|^bg($dzen_bg)|;
$out .= "\n";
print $out;
}
$i3->connect->cb(\&connected);
# let AnyEvent do the rest ("endless loop")
AnyEvent->condvar->recv