Dir*_*tel 6 mouse keyboard shortcut-keys multiple-monitors unity
在家和工作中享受多显示器设置,但想知道如何在没有鼠标的情况下在各个显示器(即“屏幕”)之间移动焦点?
键盘快捷键非常适合切换虚拟桌面,我查看了各种选项,ccsm但没有想到。
我还查看了其他问题,例如在单独的 X 屏幕之间切换焦点或指向dualscreenmouseutils和switchscreen 的链接,但所有这些似乎都与每个xorg.conf. 这些天,Unity“只适用于”多台显示器(通过显示端口),所以有点尴尬。
但是任何有关如何在单个(虚拟)Unity 显示中导航多个(物理)屏幕的提示都将非常受欢迎。
如果两个屏幕或多或少居中或顶部对齐,并且或多或少具有相同的垂直分辨率,则下面的脚本将在左右屏幕之间切换(和“聚焦”)。
我假设在左/右屏幕设置的几乎所有情况下它都可以工作。
#!/usr/bin/env python3
import subprocess
# just a helper function
get = lambda cmd: subprocess.check_output(cmd).decode("utf-8")
# get the current mouse position
current = [int(n) for n in [it.split(":")[1] for it in get(["xdotool", "getmouselocation"]).split()[:2]]]
# get the x/y size of the left screen
screendata = [(s.split("x")[0], s.split("x")[1].split("+")[0]) for s in get(["xrandr"]).split() if "+0+0" in s ][0]
xy = [int(n) for n in screendata]
# see if the mouse is on the left- or right screen
if current[0] < xy[0]:
# if the mouse currently is on the left screen, move it to the right (from the middle of the left screen)
command = ["xdotool", "mousemove", "--sync", str(current[0]+xy[0]), str(xy[1]/2)]
else:
# if the mouse currently is on the left screen, move it to the right (from the middle of the left screen)
command = ["xdotool", "mousemove", "--sync", str(current[0]-xy[0]), str(xy[1]/2)]
subprocess.Popen(command)
# optional: click after the mouse move: comment out if not needed / wanted
subprocess.Popen(["xdotool", "click", "1"])
Run Code Online (Sandbox Code Playgroud)
需要xdotool安装脚本(!)
sudo apt-get install xdotool
Run Code Online (Sandbox Code Playgroud)将脚本复制到一个空文件中,另存为 toggle_screenloc.py
通过以下命令测试运行它:
python3 /path/to/toggle_screenloc.py
Run Code Online (Sandbox Code Playgroud)如果一切正常,请将其添加到快捷键:选择:系统设置>“键盘”>“快捷方式”>“自定义快捷方式”。单击“+”并添加命令:
python3 /path/to/toggle_screenloc.py
Run Code Online (Sandbox Code Playgroud)如果脚本运行,它:
xrandr命令的输出中导出(左)屏幕的大小 (x/y) 。它通过检查 ( xdotool) 命令来查看鼠标是在左屏幕还是右屏幕上:
xdotool getmouselocation
Run Code Online (Sandbox Code Playgroud)如果鼠标指针位于左侧屏幕上:
如果鼠标指针在右侧屏幕上:
随后,鼠标单击一次以将焦点设置在(可能的)全屏应用程序(可选)上。