summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2023-02-01 11:11:24 -0700
committerSean Whitton <spwhitton@spwhitton.name>2023-02-01 12:05:08 -0700
commit41dc871da7633ff1864a2e0e58b2a809f7b2b235 (patch)
tree08751933791b55d76a7b7f47943fb0a30f911436 /scripts
parentd0d5cbdefcaa0f6fccc32c7e162fb977c7e159b7 (diff)
downloaddotfiles-41dc871da7633ff1864a2e0e58b2a809f7b2b235.tar.gz
i3status-wrapper: don't ignore decoding errors in monitoring loop
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/desktop/i3status-wrapper51
1 files changed, 32 insertions, 19 deletions
diff --git a/scripts/desktop/i3status-wrapper b/scripts/desktop/i3status-wrapper
index 97c76034..91f83032 100755
--- a/scripts/desktop/i3status-wrapper
+++ b/scripts/desktop/i3status-wrapper
@@ -60,6 +60,11 @@ unless (fork // die "couldn't fork()!") {
# Read lines forever, ignore a comma at the beginning if it exists.
while (my ($statusline) = (<> =~ /^,?(.*)/)) {
+ # If there is a decoding error, just skip this line, to minimise
+ # status bar freezes. This should be fine here because this filtering
+ # loop is in itself stateless. It's only if the decoding error
+ # involves newlines in the wrong places, or similar, that this skip
+ # could cause us to produce invalid output.
my $blocks = eval { decode_json $statusline } // next;
unshift @$blocks,
@@ -97,26 +102,34 @@ while (@trees) {
}
}
-while (my $event = eval { decode_json <$events> } // next) {
- if ($event->{change} eq "mark") {
- if (grep $_ eq "caffeinated", $event->{container}{marks}->@*) {
- register_caffeinated($event->{container});
- } elsif ($caffeinated_id
- and $caffeinated_id == $event->{container}{id}) {
- clear_caffeinated();
- }
- } elsif ($event->{change} eq "init") {
- ++$workspaces == 2 and wsbuttons("yes");
- } elsif ($event->{change} eq "empty") {
- --$workspaces == 1 and wsbuttons("no");
-
- # For simplicity, only fresh-workspace script calls compact_workspaces
- # atm. For greater consistency we could call it here, too, without
- # supplying a leave_gap argument.
-
- # compact_workspaces;
+# Now loop forever reading events, assuming no exceptions.
+
+eval {
+ while (my $event = decode_json <$events>) {
+ if ($event->{change} eq "mark") {
+ if (grep $_ eq "caffeinated", $event->{container}{marks}->@*) {
+ register_caffeinated($event->{container});
+ } elsif ($caffeinated_id
+ and $caffeinated_id == $event->{container}{id}) {
+ clear_caffeinated();
+ }
+ } elsif ($event->{change} eq "init") {
+ ++$workspaces == 2 and wsbuttons("yes");
+ } elsif ($event->{change} eq "empty") {
+ --$workspaces == 1 and wsbuttons("no");
+ # For simplicity, only fresh-workspace script calls
+ # compact_workspaces atm. For greater consistency we could call
+ # it here, too, without supplying a leave_gap argument.
+ }
}
-}
+};
+
+# Here we give up if there's a decoding error. We can't ignore the problem
+# because we don't want our ideas regarding how many workspaces there are, and
+# whether anything is caffeinated, to get out of sync.
+#
+# The user can use the WM's "reload" command to restart the loop.
+$@ and wsbuttons("yes"), clear_caffeinated();
sub wsbuttons {
return unless $ENV{XDG_CURRENT_DESKTOP} eq "sway";