簡體   English   中英

如何移動工作區以進行監視

[英]How to move workspace to monitor

我經常更改物理設置(在家和辦公室工作),並且需要一種靈活快速的方式來更改工作區形式的監視器以進行監視。

  • 操作系統:拱門
  • Window 經理:i3

我找到了一種適合我需要的方法:

首先,我需要檢測我當前連接的監視器是什么:我將使用xrandr列出所有活動監視器。

樣本 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

然后將 pipe 轉換為 grep 以提取輸出的名稱:

xrandr --listactivemonitors | grep '{{ OUTPUT_NUMBER }}:' | grep -Po '[^ ]*$'
  • 先grep隔離出想要的output線
  • 第二個 grep 只得到 output 名字

然后我將對我的 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綁定(對於風化層用戶,這里是一個很好的例子)。

使用 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"])

有關其他版本,請參閱此要點

使用i3-msgi3.command可能的語法是move workspace to output left|right|down|up|current|primary|<output>

將此添加到您的 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM