在双屏模式下在屏幕之间移动窗口

我有一台笔记本电脑和一台27英寸的显示器。 我在一台显示器上运行Qt,在另一台显示器上运行Pycharm。 有没有办法使一个组合键交换两个屏幕之间的所有窗口。 原因是我只想在大屏幕上编程。 我已经有4个工作区,所有工作区都已经使用过。

xrandr的输出:

Screen 0: minimum 320 x 200, current 3840 x 1080, maximum 32767 x 32767 eDP1 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 344mm x 193mm 1920x1080 60.2*+ 59.9 1680x1050 60.0 59.9 1600x1024 60.2 1400x1050 60.0 1280x1024 60.0 1440x900 59.9 1280x960 60.0 1360x768 59.8 60.0 1152x864 60.0 1024x768 60.0 800x600 60.3 56.2 640x480 59.9 HDMI1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 597mm x 336mm 1920x1080 60.0*+ 50.0 59.9 1920x1080i 60.1 50.0 60.0 1600x1200 60.0 1680x1050 59.9 1280x1024 75.0 60.0 1440x900 59.9 1280x960 60.0 1366x768 59.8 1152x864 75.0 1280x720 60.0 50.0 59.9 1024x768 75.1 70.1 60.0 832x624 74.6 800x600 72.2 75.0 60.3 56.2 720x576 50.0 720x480 60.0 59.9 640x480 75.0 72.8 66.7 60.0 59.9 720x400 70.1 DP1 disconnected (normal left inverted right x axis y axis) HDMI2 disconnected (normal left inverted right x axis y axis) VIRTUAL1 disconnected (normal left inverted right x axis y axis) 

1.从屏幕1 – >屏幕2交换所有窗口的脚本,反之亦然

该脚本假定屏幕具有相同的垂直分辨率,左侧屏幕是主屏幕。 脚本搜索两个屏幕的水平分辨率。

如何设置

该脚本需要安装wmctrl

 sudo apt-get install wmctrl 
  1. 将下面的脚本复制到一个空文件中,将其保存为~/.bin swap_windows (无扩展名)。 如果目录尚不存在,请创建该目录, 并使该脚本可执行
  2. 如果您刚刚创建了目录~/bin (它还不存在),请注销/运行或在终端中运行: source ~/.profile
  3. test使用以下命令运行脚本:

     swap_windows 
  4. 如果一切正常,请添加短键; 选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。 单击“+”并添加命令

剧本

 #!/usr/bin/env python3 import subprocess import sys def get(cmd): return subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8") def get_shiftright(xr_output): lines = [l for l in xr_output.splitlines() if "+0+0" in l][0].split() return int([it for it in lines if "x" in it][0].split("x")[0]) def get_shiftleft(xr_output): lines = [l for l in xr_output.splitlines() if "+0" in l and not "+0+0" in l][0].split() return -int([it for it in lines if "x" in it][0].split("x")[0]) def swap_windows(): xr_output = get("xrandr") shift_r = get_shiftright(xr_output) shift_l = get_shiftleft(xr_output) w_data = [l.split() for l in get("wmctrl -lG").splitlines()] for w in w_data: props = get("xprop -id "+w[0]) if any(["_TYPE_NORMAL" in props, "TYPE_DIALOG" in props]): if 0 < int(w[2]) < shift_r: shift = shift_r elif shift_r-shift_l > int(w[2]) >= shift_r: shift = -shift_r else: shift = 0 command = "wmctrl -ir "+w[0]+" -e 0,"+(",").join([str(int(w[2])+shift), str(int(w[3])-28), w[4], w[5]]) subprocess.Popen(["/bin/bash", "-c", command]) swap_windows() 


2.将(所有)窗口从一个监视器移动到另一个监视器的脚本

下面的脚本将双显示器设置中的窗口从一个屏幕移动到另一个屏幕:

  • 从左到右监视器 – >

    要么

  • 从右到左监视器< -

根据您使用( leftright )运行它的参数

脚本(再次)假设屏幕具有相同的垂直分辨率,左侧屏幕是主屏幕。 脚本搜索两个屏幕的水平分辨率。

如何设置

该脚本需要安装wmctrl

 sudo apt-get install wmctrl 
  1. 将下面的脚本复制到一个空文件中,将其保存为~/.bin shift_windows (无扩展名)。 如果目录尚不存在,请创建该目录, 并使该脚本可执行
  2. 如果您刚刚创建了目录~/bin (它还不存在),请注销/运行或在终端中运行: source ~/.profile
  3. test使用命令运行脚本

     shift_windows right 

    并且:shift_windows离开了

    在第一种情况下, 左侧屏幕上的窗口应该移动到右侧屏幕,而在第二种情况下,窗口应该移动到右侧屏幕。

  4. 如果一切正常,请将脚本添加到两个快捷键组合中:选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。 单击“+”并按上述说明添加命令。

剧本

 #!/usr/bin/env python3 import subprocess import sys vec = sys.argv[1] def get(cmd): return subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8") def get_shiftright(xr_output): lines = [l for l in xr_output.splitlines() if "+0+0" in l][0].split() return int([it for it in lines if "x" in it][0].split("x")[0]) def get_shiftleft(xr_output): lines = [l for l in xr_output.splitlines() if "+0" in l and not "+0+0" in l][0].split() return -int([it for it in lines if "x" in it][0].split("x")[0]) def shift_windows(): xr_output = get("xrandr") shift_r = get_shiftright(xr_output) shift_l = get_shiftleft(xr_output) w_data = [l.split() for l in get("wmctrl -lG").splitlines()] for w in w_data: props = get("xprop -id "+w[0]) if vec == "right": check = (0 < int(w[2]) < shift_r, "_TYPE_NORMAL" in props, "TYPE_DIALOG" in props).count(True) shift = shift_r if vec == "left": check = (shift_r-shift_l > int(w[2]) >= shift_r , "_TYPE_NORMAL" in props, "TYPE_DIALOG" in props).count(True) shift = -shift_r if check == 2: command = "wmctrl -ir "+w[0]+" -e 0,"+(",").join([str(int(w[2])+shift), str(int(w[3])-28), w[4], w[5]]) subprocess.Popen(["/bin/bash", "-c", command]) shift_windows() 


3.将一个窗口从一个屏幕移动到另一个屏幕

虽然不是字面上你的问题,只需几行,你可以将所有窗口从一个屏幕移动到另一个屏幕,但也可以将一个窗口(最前面的)与一个组合键移动。

使用下面的脚本,您可以使用以下命令移动所有窗口:

 shift_windows right 

或使用以下命令移动单个窗口:

 shift_windows right s 

设置与上面的脚本几乎相同(不要忘记安装wmctrl

剧本

 #!/usr/bin/env python3 import subprocess import sys vec = sys.argv[1] try: n = sys.argv[2] except IndexError: n = "a" def get(cmd): return subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8") def get_shiftright(xr_output): lines = [l for l in xr_output.splitlines() if "+0+0" in l][0].split() return int([it for it in lines if "x" in it][0].split("x")[0]) def get_shiftleft(xr_output): lines = [l for l in xr_output.splitlines() if "+0" in l and not "+0+0" in l][0].split() return -int([it for it in lines if "x" in it][0].split("x")[0]) def shift_windows(): xr_output = get("xrandr") shift_r = get_shiftright(xr_output) shift_l = get_shiftleft(xr_output) w_data = [l.split() for l in get("wmctrl -lG").splitlines()] if n == "s": frontmost = [l for l in get("xprop -root").splitlines() if "_NET_ACTIVE_WINDOW(WINDOW)" in l][0].split()[-1] frontmost = frontmost[:2]+"0"+frontmost[2:] w_data = [l for l in w_data if frontmost in l] for w in w_data: props = get("xprop -id "+w[0]) if vec == "right": check = (0 < int(w[2]) < shift_r, "_TYPE_NORMAL" in props, "TYPE_DIALOG" in props).count(True) shift = shift_r if vec == "left": check = (shift_r-shift_l > int(w[2]) >= shift_r , "_TYPE_NORMAL" in props, "TYPE_DIALOG" in props).count(True) shift = -shift_r if check == 2: command = "wmctrl -ir "+w[0]+" -e 0,"+(",").join([str(int(w[2])+shift), str(int(w[3])-28), w[4], w[5]]) subprocess.Popen(["/bin/bash", "-c", command]) shift_windows()