diff options
-rwxr-xr-x | scripts/desktop/i3status-wrapper | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/scripts/desktop/i3status-wrapper b/scripts/desktop/i3status-wrapper index 7fe552a9..429af7b0 100755 --- a/scripts/desktop/i3status-wrapper +++ b/scripts/desktop/i3status-wrapper @@ -25,7 +25,7 @@ use lib "$ENV{HOME}/src/dotfiles/perl5"; use JSON; use Local::Desktop; use IO::Pipe; -use IPC::Shareable; +use IPC::Shareable ":lock"; use Local::Desktop::WMIPC; use Sys::Hostname; use POSIX "floor", "mkfifo"; @@ -61,6 +61,7 @@ unless (fork // warn "couldn't fork monitoring loop") { # Determine the initial state -- the WM might just have been reloaded. # Move any previously-hidden containers to a fresh workspace for perusal. + tied(%info)->lock; my @old_ids; for ($wmipc->get_workspaces->@*) { $info{focused_ws} = $_->{id} if $_->{focused}; @@ -86,12 +87,14 @@ unless (fork // warn "couldn't fork monitoring loop") { unshift @trees, $node; } } + tied(%info)->unlock; # Now loop forever reading events, assuming no exceptions. eval { while (my $e = <$events>) { state $last_e; + tied(%info)->lock; # New containers if ($last_e && $last_e->{change} && $last_e->{change} eq "new") { @@ -164,6 +167,8 @@ unless (fork // warn "couldn't fork monitoring loop") { clear_caffeinated(); } } + + tied(%info)->unlock; } }; @@ -188,6 +193,7 @@ unless (fork // warn "couldn't fork command pipe reader") { open my $cmdpipe_w, ">", $cmdpipe; while (my $cmd = <$cmdpipe_r>) { + tied(%info)->lock; my $ws = $info{paper_ws}{$info{focused_ws}}; my $cols = $ws->{cols}; @@ -237,6 +243,7 @@ unless (fork // warn "couldn't fork command pipe reader") { kill USR1 => $i3status; } } + tied(%info)->unlock; } } @@ -265,12 +272,16 @@ while (my ($statusline) = (<> =~ /^,?(.*)/)) { # invalid output. my $blocks = eval { decode_json $statusline } // next; + tied(%info)->lock(LOCK_SH); + unshift @$blocks, { name => "caffeinated", full_text => "Caffeinated: " . $info{caffeinated_name} } if $info{caffeinated_name}; + tied(%info)->unlock; + unshift @$blocks, $hostinfo; print encode_json($blocks) . ",\n"; |