summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2024-01-15 14:26:07 +0000
committerSean Whitton <spwhitton@spwhitton.name>2024-01-16 17:17:31 +0000
commit53adca6f7937d0950a0c3ba1465382a770b7c407 (patch)
tree059f6d5352006508a23ecbf8f8cf63e7487b50eb
parent0a25a48115ed00af486955e16060655cc2fade31 (diff)
downloaddotfiles-53adca6f7937d0950a0c3ba1465382a770b7c407.tar.gz
i3status-wrapper: add new, improved C-i o
-rw-r--r--.config/sway/config3
-rwxr-xr-xscripts/desktop/i3status-wrapper35
2 files changed, 29 insertions, 9 deletions
diff --git a/.config/sway/config b/.config/sway/config
index 8b9a23ab..f83746f6 100644
--- a/.config/sway/config
+++ b/.config/sway/config
@@ -116,6 +116,9 @@ mode "C-i-" {
# bindsym o focus_wrapping workspace, focus parent, focus right, \
# focus_wrapping yes, mode "default"
+ bindsym o exec ~/src/dotfiles/scripts/desktop/i3status-wrapper-msg \
+ other column, mode "default"
+
# switch to workspace
bindsym 1 workspace 1, mode "default"
bindsym 2 workspace 2, mode "default"
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;
}
}