Meh*_*hdi 7 window-manager multiple-monitors screen
我有一台笔记本电脑和一个 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)
Run Code Online (Sandbox Code Playgroud)
该脚本假定屏幕具有相同的垂直分辨率,并且左侧屏幕是主要屏幕。脚本会搜索两个屏幕的水平分辨率。
需要wmctrl
安装脚本:
sudo apt-get install wmctrl
Run Code Online (Sandbox Code Playgroud)
swap_windows
在~/.bin
. 如果目录不存在,则创建该目录,并使脚本可执行。~/bin
(它还不存在),请注销/登录或在终端中运行:source ~/.profile
。使用以下命令测试运行脚本:
swap_windows
Run Code Online (Sandbox Code Playgroud)如果一切正常,请添加快捷键;选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。单击“+”并添加命令
sudo apt-get install wmctrl
Run Code Online (Sandbox Code Playgroud)
下面的脚本将双显示器设置中的窗口从一个屏幕移动到另一个屏幕,或者:
从左到右显示器 -->
或者
从右到左监视器 <--
根据您使用 (left
或right
)运行它的参数
该脚本(再次)假定屏幕具有相同的垂直分辨率,并且左侧屏幕是主要屏幕。脚本会搜索两个屏幕的水平分辨率。
需要wmctrl
安装脚本:
sudo apt-get install wmctrl
Run Code Online (Sandbox Code Playgroud)
shift_windows
在~/.bin
. 如果目录不存在,则创建该目录,并使脚本可执行。~/bin
(它还不存在),请注销/登录或在终端中运行:source ~/.profile
。使用命令测试运行脚本
shift_windows right
Run Code Online (Sandbox Code Playgroud)
和: shift_windows 左
在第一种情况下,左侧屏幕上的窗口应该移动到右侧屏幕,在第二种情况下反之亦然。
swap_windows
Run Code Online (Sandbox Code Playgroud)
虽然不是字面上的问题,只需多几行,您就可以将所有窗口从一个屏幕移动到另一个屏幕,也可以使用组合键将单个窗口(最前面)移动到另一个屏幕。
使用下面的脚本,您可以使用以下命令移动所有窗口:
shift_windows right
Run Code Online (Sandbox Code Playgroud)
或使用以下命令移动单个窗口:
shift_windows right s
Run Code Online (Sandbox Code Playgroud)
设置与上面的脚本几乎相同(不要忘记安装wmctrl
)
#!/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()
Run Code Online (Sandbox Code Playgroud)