diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2024-02-21 20:24:30 +0800 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2024-02-21 21:21:36 +0800 |
commit | 8f17340143c6e259d6344c704426f3249d53b6a0 (patch) | |
tree | 9138d2169181e7390f4755d558c368c40b30ef39 | |
parent | a3114123727162db8ffa2be533f938cd6ba658bb (diff) | |
download | dotfiles-8f17340143c6e259d6344c704426f3249d53b6a0.tar.gz |
i3status-wrapper: factor out ensure_disable_monocle
-rwxr-xr-x | scripts/desktop/i3status-wrapper | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/scripts/desktop/i3status-wrapper b/scripts/desktop/i3status-wrapper index 4e0ddca9..22f01015 100755 --- a/scripts/desktop/i3status-wrapper +++ b/scripts/desktop/i3status-wrapper @@ -324,10 +324,7 @@ unless (fork // warn "couldn't fork command pipe reader") { $mv->($i-1); } } elsif ($cmd eq "monocle toggle\n") { - if (my $m = $ws->{monocle}) { - undef $ws->{monocle}; - normalise_ws_cols(abs ++$m); - } else { + unless (ensure_disable_monocle($ws)) { $ws->{monocle} = -$i-1; normalise_ws_cols(); } @@ -671,11 +668,7 @@ sub fresh_workspace { # its monocle mode container, then that workspace will get an empty # event, and we'll lose track of any windows pushed off to the sides. # So turn off monocle mode first. - my $ws = $info{paper_ws}{$info{focused_ws}}; - if (my $m = $ws->{monocle}) { - undef $ws->{monocle}; - normalise_ws_cols(abs ++$m); - } + ensure_disable_monocle(my $ws = $info{paper_ws}{$info{focused_ws}}); # We need to ensure that the monitoring loop doesn't process the move # event before it knows about the workspace change. Otherwise, that @@ -757,6 +750,14 @@ sub node_first_child { return $child_id; } +sub ensure_disable_monocle { + my $ws = shift; + my $m = $ws->{monocle} or return 0; + undef $ws->{monocle}; + normalise_ws_cols(abs ++$m); + return 1; +} + sub sorted_paper_ws { sort { ws_num($info{paper_ws}{$a}{name}) <=> ws_num($info{paper_ws}{$b}{name}) } |