diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2024-01-15 11:37:25 +0000 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2024-01-16 17:17:31 +0000 |
commit | ccb5894f525fc0076e5f643cbef299dd81090f08 (patch) | |
tree | 948b1c64f4a29f808d96959ff7db402c32ba73a3 /scripts | |
parent | 2300bb5ba817c8e3aba8d276fa05f43d97f472e1 (diff) | |
download | dotfiles-ccb5894f525fc0076e5f643cbef299dd81090f08.tar.gz |
i3status-wrapper: add workspaces & workspace columns status display
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/desktop/i3status-wrapper | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/scripts/desktop/i3status-wrapper b/scripts/desktop/i3status-wrapper index 3b7ca7ad..b4e90dd9 100755 --- a/scripts/desktop/i3status-wrapper +++ b/scripts/desktop/i3status-wrapper @@ -78,7 +78,8 @@ unless (fork // warn "couldn't fork monitoring loop") { if ($node->{type} eq "workspace" && grep $_ eq $node->{name}, @all_workspaces) { my $entry = $info{paper_ws}{$node->{id}} - //= { off_left => [], off_right => [] }; + //= { name => ws_name($node), + off_left => [], off_right => [] }; sync_cols($node => $entry); $entry->{ncols} = max 2, scalar $entry->{cols}->@*; } elsif (grep $_ eq "caffeinated", $node->{marks}->@*) { @@ -111,6 +112,7 @@ unless (fork // warn "couldn't fork monitoring loop") { && $e->{container}{type} ne "floating_con") { # A container stopped floating -- it's as though it's new. normalise_ws_cols(); + kill USR1 => $i3status; } # Other container changes @@ -128,6 +130,7 @@ unless (fork // warn "couldn't fork monitoring loop") { # container has gone. Or a focus change might be due to a new # container, in which case we might need to push one off. normalise_ws_cols(); + kill USR1 => $i3status; } # Ticks @@ -148,14 +151,21 @@ unless (fork // warn "couldn't fork monitoring loop") { # in our absence. normalise_ws_cols() if exists $info{paper_ws}{$info{focused_ws}}; + kill USR1 => $i3status; } elsif ($e->{change} && $e->{change} eq "init" && $e->{current} && grep $_ eq $e->{current}{name}, @all_workspaces) { $info{paper_ws}{$e->{current}{id}} - = { off_left => [], off_right => [], - ncols => 2, cols => [] }; + = { name => ws_name($e->{current}), ncols => 2, cols => [], + off_left => [], off_right => [], }; + } elsif ($e->{change} && $e->{change} eq "rename" + && exists $info{paper_ws}{$e->{current}{id}}) { + $info{paper_ws}{$e->{current}{id}}{name} + = $e->{current}{name}; + kill USR1 => $i3status; } elsif ($e->{change} && $e->{change} eq "empty" && $e->{current}) { delete $info{paper_ws}{$e->{current}{id}}; + kill USR1 => $i3status; } # Mark changes @@ -263,6 +273,8 @@ print scalar <>; # The second line contains the start of the infinite array. print scalar <>; +wsbuttons("no"); + # 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 @@ -274,6 +286,36 @@ while (my ($statusline) = (<> =~ /^,?(.*)/)) { tied(%info)->lock(LOCK_SH); + if ($info{focused_ws} + && $info{paper_ws} && keys $info{paper_ws}->%* > 1) { + my @disp; + my @keys = + sort { $info{paper_ws}{$a}{name} cmp $info{paper_ws}{$b}{name} } + keys $info{paper_ws}->%*; + foreach my $key (@keys) { + push @disp, + sprintf +($info{focused_ws} == $key ? "<b>%s</b>" : "%s"), + $info{paper_ws}{$key}{name}; + } + unshift @$blocks, + { name => "ws", markup => "pango", full_text => join " ", @disp }; + } + + if ($info{focused_ws} && exists $info{paper_ws}{ $info{focused_ws} }) { + sub nwin { join " ", ("\x{2021}")x$_[0] } + + my $ws = $info{paper_ws}{ $info{focused_ws} }; + my $left = $ws->{off_left}->@*; + my $right = $ws->{off_right}->@*; + + my $disp = sprintf "<b>%s</b>", nwin($ws->{ncols}); + $disp = sprintf "%s %s", nwin($left), $disp if $left; + $disp = sprintf "%s %s", $disp, nwin($right) if $right; + + unshift @$blocks, + { name => "cols", markup => "pango", full_text => $disp }; + } + unshift @$blocks, { name => "caffeinated", @@ -385,3 +427,8 @@ sub hide_con { sub show_con { sprintf "[con_id=%s] move container to workspace current, focus", $_[0] } + +sub ws_name { + my ($before, $after) = split /:/, shift->{name}; + $after // $before +} |