diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2024-01-15 11:24:34 +0000 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2024-01-16 17:17:31 +0000 |
commit | 19b116160ed48149424524ae00020d97e7fc059a (patch) | |
tree | 29bd569ed1ee38607776fe4fb862dfea1c94cb57 /scripts | |
parent | 14b917b5779e350a10db2397ff4da788a0945dcc (diff) | |
download | dotfiles-19b116160ed48149424524ae00020d97e7fc059a.tar.gz |
i3status-wrapper: use IPC::Shareable locking
Diffstat (limited to 'scripts')
-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"; |