From 8f17340143c6e259d6344c704426f3249d53b6a0 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 21 Feb 2024 20:24:30 +0800 Subject: i3status-wrapper: factor out ensure_disable_monocle --- scripts/desktop/i3status-wrapper | 19 ++++++++++--------- 1 file 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}) } -- cgit v1.2.3