kra*_*mir 6 xrandr shell-script
我有两个输出(并排)并且我正在使用 i3-wm。我想创建 shell 脚本脚本,它运行:
# if output <BBB> is connected, but off
xrandr --output <BBB> --right-of <AAA> --mode 1920x1080
# if output <BBB> is connected, and on
xrandr --output <BBB> --off
Run Code Online (Sandbox Code Playgroud)
我正在切换显示器配置以实现更好的游戏性能(FPS 增加约 5-15%)
这应该有效:
xrandr --listactivemonitors | grep <BBB> >/dev/null && xrandr --output <BBB> --off || xrandr --output <BBB> --right-of <AAA> --mode 1920x1080
解释:
xrandr --listactivemonitors仅打印当前打开的监视器。grep <BBB> >/dev/null在先前的输出中搜索我们要切换的监视器的名称。如果找到,grep 将返回 shell 解释为 true 的退出代码。如果没有找到,它将返回 shell 解释为 false 的退出代码。输出被发送到 /dev/null 以避免屏幕混乱。&& xrandr --output <BBB> --off如果 grep 在活动监视器列表中找到监视器,那么它将运行,关闭监视器。但是,如果 grep 以错误的退出代码退出,那么这将不会运行,因为无论它的计算结果是什么,逻辑 and 子句作为一个整体已经知道是错误的。|| xrandr --output <BBB> --right-of <AAA> --mode 1920x1080如果 grep 没有找到它,那么该子句将运行,打开监视器。它运行是因为前一个子句 ( grep ... && xrandr ...) 的计算结果为 false。为了知道这个逻辑 or 子句是否为真,shell 必须计算右侧。另一方面,如果左侧已经计算为 true,则无需计算右侧,因此不会执行。这是关于由逻辑条件介导的控制流的简洁文章。
请检查此链接:
https://faq.i3wm.org/question/5312/how-to-toggle-onoff-external-and-internal-monitors.1.html
该脚本是用 bash 编写的,并给出了如何在 i3 配置文件上设置快捷键。
| 归档时间: |
|
| 查看次数: |
3372 次 |
| 最近记录: |