dav*_*les 8 emacs multiple-monitors
我在办公桌上的笔记本电脑上使用 Ubuntu 14.04 和第二台显示器。当我与第二台显示器断开连接时---没有失败---我的 Emacs 窗口移出屏幕。
我可以 Alt-TAB 使 Emacs 成为活动窗口,然后盲目地停止 Emacs 以便我可以重新启动它,这会导致它重新出现在屏幕上。但是,在我看来,Ubuntu 中应该有一种方法可以将屏幕外窗口重新显示到屏幕上。在那儿?
当然,更好的解决方案是防止窗口因显示器断开连接而离开屏幕,我会接受该问题的解决方案。
更新:
xrandr
连接到第二台显示器时的输出:
Screen 0: minimum 320 x 200, current 3200 x 1080, maximum 32767 x 32767
eDP1 connected primary 1920x1080+1280+0 (normal left inverted right x axis y axis) 382mm x 215mm
1920x1080 60.0*+ 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
VGA1 connected 1280x1024+0+0 (normal left inverted right x axis y axis) 376mm x 301mm
1280x1024 60.0*+ 75.0
1280x960 60.0
1152x864 75.0
1024x768 75.1 70.1 60.0
832x624 74.6
800x600 72.2 75.0 60.3 56.2
640x480 75.0 72.8 66.7 60.0
720x400 70.1
HDMI1 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)
xrandr
与第二台显示器断开连接后的输出:
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 32767 x 32767
eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 382mm x 215mm
1920x1080 60.0*+ 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
VGA1 disconnected (normal left inverted right x axis y axis)
HDMI1 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)
此外,我尝试交换终端窗口和 Emacs 窗口的左右位置,然后断开连接。这允许 Emacs 窗口在与第二台显示器断开连接后仍保留在屏幕上。并且终端窗口在淘汰 Emacs 的位置上幸存下来。因此,应用程序似乎与此有关。
根据评论中的建议/要求,下面的脚本会将所有“正常”窗口移动到当前工作区的可见区域。
解决方法是一种解决方法;考虑到xrandr
断开连接前后的输出差异,屏幕信息已正确更新。窗户不自行移动的原因(目前)是未知的,除非另一个答案解决了这个问题。
#!/usr/bin/env python3
import subprocess
# get the resolution of the screen (+0+0)
res = [
int(n) for n in [
s.split("+")[0].split("x")\
for s in subprocess.check_output(["xrandr"]).decode("utf-8").split()\
if "+0+0" in s][0]
]
# create list of windows
w_list = [w.split() for w in subprocess.check_output(["wmctrl", "-lG"]).decode("utf-8").splitlines()]
# filter only "normal" ones
valid = [
w for w in w_list if "_NET_WM_WINDOW_TYPE_NORMAL" in\
subprocess.check_output(["xprop", "-id", w[0]]).decode("utf-8")
]
# get the number of valid windows and calculate a targeted position
# the targeted position is a hunch, it will be exact if the window fits completely inside the resolution
# it will work anyway
parts = len(valid)+2
positions = [(int(n*res[0]/parts), int(n*res[1]/parts)) for n in list(range(parts))[1:-1]]
# unmaximaize, move the windows to the visible area (current workspace)
for i, w in enumerate(valid):
subprocess.Popen(["wmctrl", "-ir", w[0], "-b", "remove,maximized_vert,remove,maximized_horz"])
# weird, but sometimes wmctrl refuses to move a window if it is not resized first (?)
subprocess.Popen(["wmctrl", "-ir", w[0], "-e", "0,200,200,200,200"])
subprocess.Popen(["wmctrl", "-ir", w[0], "-e", (",").join(["0", str(positions[i][0]), str(positions[i][1]),w[4],w[5]])])
Run Code Online (Sandbox Code Playgroud)
脚本需要wmctrl
:
sudo apt-get install wmctrl
Run Code Online (Sandbox Code Playgroud)将脚本复制到一个空文件中,将其保存为 move_windows.py
试运行:打开多个窗口,将它们放置在不同的工作区等,或尝试断开第二台显示器的连接。然后运行命令:
python3 /path/to/move_windows.py
Run Code Online (Sandbox Code Playgroud)
所有“普通”窗口都应移动到当前工作区的可见区域。
如果一切正常,请将其添加到快捷键:选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。单击“+”并添加命令:
python3 /path/to/move_windows.py
Run Code Online (Sandbox Code Playgroud)现在您应该可以使用快捷键将所有窗口移动到当前工作区的可见区域中。
归档时间: |
|
查看次数: |
3429 次 |
最近记录: |