diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2024-01-15 14:26:07 +0000 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2024-01-16 17:17:31 +0000 |
commit | 53adca6f7937d0950a0c3ba1465382a770b7c407 (patch) | |
tree | 059f6d5352006508a23ecbf8f8cf63e7487b50eb /scripts | |
parent | 0a25a48115ed00af486955e16060655cc2fade31 (diff) | |
download | dotfiles-53adca6f7937d0950a0c3ba1465382a770b7c407.tar.gz |
i3status-wrapper: add new, improved C-i o
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/desktop/i3status-wrapper | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/scripts/desktop/i3status-wrapper b/scripts/desktop/i3status-wrapper index 2431e74c..ffc910c2 100755 --- a/scripts/desktop/i3status-wrapper +++ b/scripts/desktop/i3status-wrapper @@ -204,16 +204,19 @@ unless (fork // warn "couldn't fork command pipe reader") { while (my $cmd = <$cmdpipe_r>) { tied(%info)->lock; + my $ws = $info{paper_ws}{$info{focused_ws}}; my $cols = $ws->{cols}; - - if ($cmd =~ /^(focus|move) (left|right)$/) { - my $i = first { $cols->[$_] == $ws->{focused_col} } 0..$#$cols; - my $move = $1 eq "move"; - $2 eq "right" ? $i++ : $i--; - if (@$cols > $i >= 0) { - $wmipc->cmd($cmd); - } elsif ($i == @$cols && $ws->{off_right}->@*) { + my $i = first { $cols->[$_] == $ws->{focused_col} } 0..$#$cols; + state $last_dir = 1; + + my $mv = sub { + my ($j, $move) = @_; + if (@$cols > $j >= 0) { + $wmipc->cmd(sprintf "%s %s", + $move ? "move" : "focus", + $j > $i ? "right" : "left"); + } elsif ($j == @$cols && $ws->{off_right}->@*) { with_ignored_events { my $pushed = shift @$cols; my $pulled = pop $ws->{off_right}->@*; @@ -231,7 +234,7 @@ unless (fork // warn "couldn't fork command pipe reader") { $wmipc->cmd(@cmds, hide_con($pushed)); }; kill USR1 => $i3status; - } elsif ($i == -1 && $ws->{off_left}->@*) { + } elsif ($j == -1 && $ws->{off_left}->@*) { with_ignored_events { my $pushed = pop @$cols; my $pulled = pop $ws->{off_left}->@*; @@ -252,12 +255,26 @@ unless (fork // warn "couldn't fork command pipe reader") { }; kill USR1 => $i3status; } + $last_dir = $j > $i ? 1 : -1; + }; + + # Command dispatch + if ($cmd =~ /^(focus|move) (left|right)$/) { + $mv->($2 eq "right" ? $i+1 : $i-1, $1 eq "move"); } elsif ($cmd =~ /^cols (incr|decr)$/) { $info{paper_ws}{$info{focused_ws}}{ncols} += $1 eq "incr" ? 1 : -1; normalise_ws_cols(); kill USR1 => $i3status; + } elsif ($cmd =~ /^other column$/) { + # This is meant to be similar to my custom Emacs C-x o. + if ($i == 0 || $last_dir == -1 && $i < $#$cols) { + $mv->($i+1); + } elsif ($i == $#$cols || $last_dir == 1) { + $mv->($i-1); + } } + tied(%info)->unlock; } } |