summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-08-15 09:19:39 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-08-17 16:18:14 -0700
commit0277189d5fe4ac4a452a2568db4d5ec97c793286 (patch)
treedc100bdb2cf7d1dd8295e3ede11b625ba58238ab
parent0ad52a42d64f91d71f43c47fad87746c1afa6fb4 (diff)
downloaddotfiles-0277189d5fe4ac4a452a2568db4d5ec97c793286.tar.gz
handle workspace_buttons out in i3status-wrapper, compact less often
Even if we were to uncomment the call to compact_workspaces in i3status-wrapper, (the rest of) this change would still mean we would do fewer get_workspaces queries overall.
-rw-r--r--perl5/Local/Desktop.pm7
-rwxr-xr-xscripts/desktop/i3status-wrapper15
2 files changed, 15 insertions, 7 deletions
diff --git a/perl5/Local/Desktop.pm b/perl5/Local/Desktop.pm
index 616ee89e..347495fe 100644
--- a/perl5/Local/Desktop.pm
+++ b/perl5/Local/Desktop.pm
@@ -85,8 +85,7 @@ sub fresh_workspace {
=head compact_workspaces(%opts)
-Rename workspaces so as to remove gaps in the sequence of workspaces, and show
-or hide workspace buttons depending on whether there is >1 workspace.
+Rename workspaces so as to remove gaps in the sequence of workspaces.
If C<$opts{leave_gap}>, ensure there is a gap of one workspace after the
currently focused workspace and return the name of the gap workspace, or just
@@ -98,8 +97,6 @@ sub compact_workspaces {
my %opts = @_;
my @workspaces = @{ decode_json `$wmipc -t get_workspaces` };
@workspaces < @all_workspaces or return;
- my $buttons_cmd
- = "bar bar-0 workspace_buttons " . (@workspaces > 1 ? "yes" : "no");
my ($current_workspace, $gap_workspace);
if ($opts{leave_gap}) {
$_->{focused} and $current_workspace = $_->{name}, last
@@ -119,7 +116,7 @@ sub compact_workspaces {
: unshift @cmds, $pair
}
- wmipc $buttons_cmd, map "rename workspace $_->[0] to $_->[1]", @cmds;
+ wmipc map "rename workspace $_->[0] to $_->[1]", @cmds;
$opts{leave_gap} and $gap_workspace
}
diff --git a/scripts/desktop/i3status-wrapper b/scripts/desktop/i3status-wrapper
index af487b0c..7a9c489b 100755
--- a/scripts/desktop/i3status-wrapper
+++ b/scripts/desktop/i3status-wrapper
@@ -80,6 +80,9 @@ my $caffeinated_id;
open my $events, "-|",
$wmipc, "-t", "subscribe", "-m", '[ "window", "workspace" ]';
+my $workspaces = @{ decode_json `$wmipc -t get_workspaces` };
+$workspaces > 1 or wmipc "bar bar-0 workspace_buttons no";
+
while (my $event = decode_json <$events>) {
if ($event->{change} eq "mark") {
if (grep $_ eq "caffeinated", $event->{container}{marks}->@*) {
@@ -91,7 +94,15 @@ while (my $event = decode_json <$events>) {
undef $caffeinated_id, undef $info{caffeinated_name};
kill USR1 => $i3status;
}
- } elsif ($event->{change} eq "init" or $event->{change} eq "empty") {
- compact_workspaces;
+ } elsif ($event->{change} eq "init") {
+ ++$workspaces == 2 and wmipc "bar bar-0 workspace_buttons yes";
+ } elsif ($event->{change} eq "empty") {
+ --$workspaces == 1 and wmipc "bar bar-0 workspace_buttons 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;
}
}