【发布时间】:2022-06-16 10:15:38
【问题描述】:
我会定期更改设置(一天几次),并且需要一种灵活快速的方式将工作区从监视器更改为监视器。
- 操作系统:Arch
- 窗口管理器:i3
【问题讨论】:
我会定期更改设置(一天几次),并且需要一种灵活快速的方式将工作区从监视器更改为监视器。
【问题讨论】:
我找到了一种适合我需要的方法:
首先我需要检测我当前连接的显示器是什么:
我将使用xrandr 列出所有活动监视器。
样本输出:
$ 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
然后通过管道将其输入 grep 以提取输出名称:
xrandr --listactivemonitors | grep '{{ OUTPUT_NUMBER }}:' | grep -Po '[^ ]*$'
然后我会在我的 i3 配置文件中进行一些脏复制/粘贴。
# 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 '[^ ]*$')"
当我连接到一组新的监视器时,配置文件的简单重新加载将更新绑定。
PS:这当然可以改进,但它是一种满足我需要的快速有效的方法。
【讨论】:
有很多方法可以做到这一点。
使用命令行:
$ 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}]
根据其他答案在您的 i3 配置文件中添加 bindsym 绑定(对于风化层用户来说,这里是一个很好的 example)。
使用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"])
其他版本请参见gist。
当使用i3-msg 或i3.command 时,可能的语法是move workspace to output left|right|down|up|current|primary|<output>。
【讨论】: