I regularly change physical setup (work from home and office) and need a flexible and quick way of changing workspace form monitor to monitor.
I found a way to do that that fits my needs:
First I need to detect what are the monitors I currently have connected: I'll use xrandr
to list all active monitors.
Sample output:
$ xrandr --listactivemonitors
Monitors: 3
0: +*HDMI-1 1920/531x1080/299+0+0 HDMI-1
1: +eDP-1 1280/301x800/188+3840+280 eDP-1
2: +DP-2 1920/595x1080/336+1920+0 DP-2
and then pipe that into grep to extract the names of the outputs:
xrandr --listactivemonitors | grep '{{ OUTPUT_NUMBER }}:' | grep -Po '[^ ]*$'
And then I'll do some dirty copy/past into my i3 config file.
# move focused container to workspace
bindsym $mod+$alt+1 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '0:' | grep -Po '[^ ]*$')"
bindsym $mod+$alt+2 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '1:' | grep -Po '[^ ]*$')"
bindsym $mod+$alt+3 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '2:' | grep -Po '[^ ]*$')"
bindsym $mod+$alt+4 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '3:' | grep -Po '[^ ]*$')"
bindsym $mod+$alt+5 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '4:' | grep -Po '[^ ]*$')"
bindsym $mod+$alt+6 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '5:' | grep -Po '[^ ]*$')"
bindsym $mod+$alt+7 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '6:' | grep -Po '[^ ]*$')"
bindsym $mod+$alt+8 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '7:' | grep -Po '[^ ]*$')"
bindsym $mod+$alt+9 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '8:' | grep -Po '[^ ]*$')"
bindsym $mod+$alt+0 exec "i3-msg move workspace to output $(xrandr --listactivemonitors| grep '9:' | grep -Po '[^ ]*$')"
A simple reload of the configuration file will update the binding when I'm connected to a new set of monitors.
PS: this could surely be improved but it's a quick and efficient way of doing it that fits my needs.
There are a number of ways to do this.
Use the command line:
$ i3-msg move workspace to output left
[{"success":true}]
$ i3-msg move workspace to output right
[{"success":true}]
$ i3-msg move workspace to output next
[{"success":true}]
Add bindsym
binds in your i3 config file as per other answers (for regolith users here is a good example ).
Use python:
#!/usr/bin/env python3
# pip install --user i3-py rich
import i3
import rich
DEBUG = False
outputs = i3.get_outputs()
workspaces = i3.get_workspaces()
focused_workspace = [w for w in workspaces if w["focused"] == True][0]
active_outputs = [o for o in outputs if o["active"] == True]
other_output = [o for o in active_outputs if o["name"] != focused_workspace["output"]][
0
]
if DEBUG:
print("outputs:")
rich.print(outputs)
print("workspaces:")
rich.print(workspaces)
print("focused_workspace:")
rich.print(focused_workspace)
print("active_outputs:")
rich.print(active_outputs)
print("other_workspace:")
rich.print(other_output)
# Send current workspace to other output
i3.command("move", "workspace to output " + other_output["name"])
See this gist for other versions.
When using i3-msg
or i3.command
possible syntax is move workspace to output left|right|down|up|current|primary|<output>
.
Add this to your i3config
bindsym $mod+Ctrl+Shift+Left move workspace to output left
bindsym $mod+Ctrl+Shift+Right move workspace to output right
bindsym $mod+Ctrl+Shift+Up move workspace to output up
bindsym $mod+Ctrl+Shift+Down move workspace to output down
bindsym $mod+Ctrl+Shift+h move workspace to output left
bindsym $mod+Ctrl+Shift+l move workspace to output right
bindsym $mod+Ctrl+Shift+k move workspace to output up
bindsym $mod+Ctrl+Shift+j move workspace to output down
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.