然而提供的答案是使用
- Ctrl++ Alt(NUMPAD 4左边缘)
- Ctrl++ Alt(NUMPAD 6右边缘)
不适用于三显示器设置,因为跳转会跳过中间的屏幕并转到最左边或最右边的屏幕。
另一个答案推荐放置 Windows 扩展,但它的键绑定对我来说似乎不起作用,因为它处于活动状态,但快捷方式根本不起作用。
如何使用 gnome-shell 将窗口移动到使用两个以上显示器的特定屏幕?
我的输出xrandr
:
Screen 0: minimum 8 x 8, current 5760 x 1080, maximum 32767 x 32767
eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 309mm x 174mm
1920x1080 60.0*+ 59.9 48.0
1680x1050 60.0 59.9
1600x1024 60.2
1400x1050 60.0
1600x900 60.0
1280x1024 60.0
1440x900 59.9
1280x960 60.0
1368x768 60.0
1360x768 59.8 60.0
1152x864 60.0
1280x720 60.0
1024x768 60.0
1024x576 60.0
960x540 60.0
800x600 60.3 56.2
864x486 60.0
640x480 59.9
720x405 60.0
640x360 60.0
DP1 disconnected (normal left inverted right x axis y axis)
DP1-1 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 477mm x 268mm
1920x1080 60.0*+
1680x1050 59.9
1600x900 60.0
1280x1024 75.0 60.0
1280x800 59.9
1152x864 75.0
1280x720 60.0
1024x768 75.1 60.0
832x624 74.6
800x600 75.0 60.3
640x480 75.0 60.0
720x400 70.1
DP1-2 connected 1920x1080+3840+0 (normal left inverted right x axis y axis) 477mm x 268mm
1920x1080 60.0*+
1680x1050 59.9
1600x900 60.0
1280x1024 75.0 60.0
1280x800 59.9
1152x864 75.0
1280x720 60.0
1024x768 75.1 60.0
832x624 74.6
800x600 75.0 60.3
640x480 75.0 60.0
720x400 70.1
DP1-3 disconnected (normal left inverted right x axis y axis)
HDMI1 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
好消息是,所有屏幕的 y 分辨率都相同,并且屏幕垂直对齐,因此我们不需要担心可能的 y 位置冲突,例如这里。
使用屏幕作为参数,在多个屏幕之间移动窗口
下面的脚本提供了三个(用于三个屏幕)快捷键。通过按下这些键,您可以将窗口移动到屏幕 1、2 或 3。该脚本计算窗口位于哪个屏幕上,以及窗口需要移动的距离。
剧本
#!/usr/bin/env python3
import subprocess
import sys
target = int(sys.argv[1])
# --- for Unity, there is a deviation in the y coordinate of the wmctrl -command
# --- for Unity, set: deviation = -28
deviation = 0
# ---
# get the (sorted) x resolution of the screens as a list
screens = [int(s.split("+")[-2]) for s in subprocess.check_output(
["xrandr"]).decode("utf-8").split() if (s).count("+") == 2]
screens.sort()
# get the frontmost window and its coordinates
frontmost = [l.split("#")[-1].strip() for l in subprocess.check_output([
"xprop", "-root"]).decode("utf-8").splitlines() if "_NET_ACTIVE_WINDOW(WINDOW)" in l][0]
active = frontmost[:2]+(10-len(frontmost))*"0"+frontmost[2:]
windata = [l.split() for l in subprocess.check_output(
["wmctrl", "-lG"]).decode("utf-8").splitlines() if active in l][0]
# get the current screen the window is on, and (thus) the x-position (of the screen)
currscreen = len([cr for cr in screens if cr <= int(windata[2])])
currpos = sum([item for item in screens[:currscreen]])
# calculate the target position/the distance to move the window
target_pos = screens[target-1]
move = target_pos-currpos
command = ["wmctrl", "-ir", active, "-e", "0,"+(",").join(
[str(int(windata[2])+move), str(int(windata[3])-28), windata[4], windata[5]])]
# move the window to the targeted screen
subprocess.Popen(command)
如何使用
该脚本需要
wmctrl
:sudo apt-get install wmctrl
将脚本复制到一个空文件中,另存为
move_window.py
使用以下命令在终端窗口中运行该脚本进行测试:
python3 /path/to/move_window.py 1
要将活动窗口移至屏幕 1,
python3 /path/to/move_window.py 2
要将活动窗口移至屏幕 2,
python3 /path/to/move_window.py 3
将活动窗口移至屏幕 3
由于终端是你的积极的窗口,它应该在命令上在屏幕上移动。
- 将其添加到三个不同的快捷键,例如Ctrl+ Alt+1、2 和 3:选择:系统设置 > “键盘” > “快捷键” > “自定义快捷键”。单击“+”并添加命令
笔记
- 问题出在 Gnome 上,但该脚本应该也适用于(至少)Unity。然而,在 Unity 上使用时会出现偏差,如脚本的头部部分所述,这里。
- 由于脚本从 获取屏幕信息
xrandr
,因此它也应该适用于 2、3、4 或任意数量的屏幕。