如何在启动器上创建图标以禁用键盘+旋转屏幕?
我有2合1的Ubuntu。 我想知道是否有办法编写一个打开和关闭内部键盘的命令,并将屏幕向左(或向右)旋转90度,并将其放在左侧的启动器上。 有没有办法做到这一点?
如果我可以点击它来禁用键盘(+触摸板)并将屏幕旋转90度,再点击一次以使用function键盘(+触摸板)返回正确的方向,那就太好了。
脚本+启动器可以一步旋转屏幕并切换键盘
下面的脚本都是
- 旋转(切换)您的屏幕(左侧或右侧)
-
禁用(切换)您定义为禁用的键盘
剧本
#!/usr/bin/env python3 import subprocess # --- set the name of the screen, and the rotate direction and the id of your keyboard below screen = "DVI-I-1" rotate = "left" disable = ["9", "14"] # --- matchline = [ l.split() for l in subprocess.check_output(["xrandr"]).decode("utf-8").splitlines()\ if l.startswith(screen) ][0] s = matchline[ matchline.index([s for s in matchline if s.count("+") == 2][0])+1 ] newset = ["normal", "1"] if s == rotate else [rotate, "0"] subprocess.call(["xrandr", "--output", screen, "--rotate", newset[0]]) for item in disable: subprocess.call(["xinput", "set-prop", item, "Device Enabled", newset[1]])
如何使用
- 将脚本复制到空文件中,将其另存为
rotate.py
-
将下面的启动器复制到一个空文件中,将其另存为
rotate.desktop
[Desktop Entry] Exec=python3 /path/to/rotate.py Icon=preferences-desktop-keyboard Name=Rotate & Disable Keyboard Type=Application
在
Exec=
行中,将/path/to/rotate.py
替换为rotate.py
脚本的实际路径。 使.desktop
文件可执行 。 它会显示一个图标,如: -
现在你必须找出两件事:
一个。 屏幕名称(您想要旋转的名称):在终点中运行:
xrandr
在其中查找“已连接”的行。 第一个字符串是屏幕名称,类似于脚本中的示例。 (也可能是
VGA-1
或类似的东西)湾 键盘的
id
,即要禁用的键盘。 在终端中运行命令:xinput -list
如本答案所述 。
-
在脚本的头部输入找到的项目:
# --- set the name of the screen, and the rotate direction and the id of your keyboard below screen = "DVI-I-1" rotate = "left" disable = ["9"] # ---
现在你已经完成了,或者直接从你的桌面使用.desktop
文件,或者将它移动到~/.local/share/applications
并将它从Dash拖到启动器。
如果您执行后者,请注意在旋转屏幕后,图标将无法响应appr。 7秒
玩得开心!