i3 has a
to enable going back and forth between workspaces. Once enabled, if you are on
workspace 1 and switch to workspace 2 and then just press
mod+2 again to
switch to workspace 2, you will go back to workspace 1.
However, this feature is quite limited as it does not remember more than one
previous workspace. For example, say you are on workspace 1, switch to
workspace 2 and then to workspace 3. Then, typing
mod+3 will send you back
to workspace 2 as expected. But then, typing
mod+2 will send you back to
workspace 3 whereas one may have expected it to switch to workspace 1 (as does
Weechat with buffers switch for instance).
This can be solved by wrapping around the workspace switching in the i3 config. I wrote this small script to handle it.
Basically, you have to start the script when you start i3 by putting
exec_always --no-startup-id "python PATH_TO_/workspace_back_and_forth_enhanced.py"
Then, you can replace your
bindsym commands to switch workspaces, calling
the same script:
bindsym $mod+agrave exec "echo 10 | socat - UNIX-CONNECT:$XDG_RUNTIME_DIR/i3/i3-back-and-forth-enhanced.sock"
/tmp if this environment variable is not
defined on your system.)
This script does maintain a queue of 20 previously seen workspaces (so you can
go back 20 workspaces ago in your history). This can be increased by editing
WORKSPACES_STACK = deque(maxlen=20) line according to your needs.
Hope this helps! :)