i3-companion: make Alt-Tab local to a given output

This commit is contained in:
Vincent Bernat 2021-08-03 18:55:21 +02:00
parent 7264c2ead5
commit 7283f44742
2 changed files with 36 additions and 1 deletions

View file

@ -330,6 +330,41 @@ async def workspace_rename(i3, event):
await i3.command(";".join(commands)) await i3.command(";".join(commands))
@on(CommandEvent("previous-workspace"), I3Event.WORKSPACE_FOCUS)
@static(history=collections.defaultdict(list))
async def previous_workspace(i3, event):
"""Go to previous workspace on the same output."""
history = previous_workspace.history
if isinstance(event, i3ipc.WorkspaceEvent) and event.old:
data = event.old.ipc_data
output, num = data["output"], data["num"]
if history[output][-1:] != [num]:
history[output].append(num)
history[output] = history[output][-2:]
logger.debug("on %s, history is %s", output, history[output])
elif event == "previous-workspace":
workspaces = await i3.get_workspaces()
try:
focused = [w for w in workspaces if w.focused][0]
except IndexError:
return
output = focused.output
while True:
try:
previous = history[output].pop()
if [
w
for w in workspaces
if w.num != focused.num and w.num == previous and w.output == output
]:
break
except IndexError:
logger.debug("no previous workspace on %s", output)
return
logger.debug("switching to workspace %d on %s", previous, output)
await i3.command(f"workspace number {previous}")
@on(CommandEvent("new-workspace"), CommandEvent("move-to-new-workspace")) @on(CommandEvent("new-workspace"), CommandEvent("move-to-new-workspace"))
async def new_workspace(i3, event): async def new_workspace(i3, event):
"""Create a new workspace and optionally move a window to it.""" """Create a new workspace and optionally move a window to it."""

2
config
View file

@ -112,7 +112,7 @@ bindsym $mod+7 workspace number $ws7
bindsym $mod+8 workspace number $ws8 bindsym $mod+8 workspace number $ws8
bindsym $mod+9 workspace number $ws9 bindsym $mod+9 workspace number $ws9
bindsym $mod+0 workspace number $ws10 bindsym $mod+0 workspace number $ws10
bindsym $mod+Tab workspace back_and_forth bindsym $mod+Tab nop "previous-workspace"
bindsym $mod+Ctrl+o focus output right bindsym $mod+Ctrl+o focus output right
bindsym $mod+n nop "new-workspace" bindsym $mod+n nop "new-workspace"
focus_wrapping no focus_wrapping no