xrandr
xrandr 是用于与 X RandR 扩展进行交互的命令行工具。它允许对 X server 进行实时配置(即无需重新启动即可使配置生效),xrandr 提供了显示模式(如分辨率、刷新率等)的自动检测,以及动态配置输出(如调整大小、旋转、移动屏幕等)的功能。
作者:炭烤毛蛋 ,点击博主了解更多。
提示:xrandr 需要系统有正常显示才可查看。
文章目录
- xrandr
- 前期准备
- [1. xrandr 测试](#1. xrandr 测试)
-
- [1.1 分辨率调整](#1.1 分辨率调整)
- [1.2 指定屏分辨率设定](#1.2 指定屏分辨率设定)
- [1.3 xrandr 命令详情](#1.3 xrandr 命令详情)
- [2 显示设置](#2 显示设置)
-
- [2.1 交换内外屏](#2.1 交换内外屏)
- [2.2 规避显示 crash问题](#2.2 规避显示 crash问题)
- [3. 添加为检测到分辨率](#3. 添加为检测到分辨率)
-
- [3.1 xrandr 模式设定](#3.1 xrandr 模式设定)
- 结语
前期准备
ubuntu 安装 xrandr 命令,xrandr 安装依赖 x11-xserver-utils。
bash
sudo apt install x11-xserver-utils
1. xrandr 测试
1.1 分辨率调整
- 查看分辨率
bash
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
HDMI-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 527mm x 296mm
1920x1080 60.00*+ 74.97 50.00 59.94
1680x1050 59.88
1280x1024 75.02 60.02
1440x900 59.90
1280x960 60.00
1280x720 60.00 50.00 59.94
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
720x576 50.00
720x480 60.00 59.94
640x480 75.00 72.81 66.67 60.00 59.94
720x400 70.08
HDMI-2 disconnected (normal left inverted right x axis y axis)
- 设置具体分辨率
bash
xrandr -s 1024x768
- 恢复到原来的分辨率
bash
xrandr -s 0
- 旋转屏幕
bash
xrandr -o left # 向左旋转90度
xrandr -o right # 向右旋转90度
xrandr -o inverted # 上下翻转
xrandr -o normal # 回到正常角度
1.2 指定屏分辨率设定
- 设置分辨率(HDMI-1)
bash
xrandr --output HDMI-1 --mode 1920x1080
- 设置分辨率和刷新率(HDMI-1)
bash
xrandr --output HDMI-1 --mode 1920x1080 --rate 60
- 改为自动模式
bash
xrandr --output HDMI-1 --auto
- 关闭显示1,开启显示2
bash
xrandr --output HDMI-1 --off --output HDMI-2 --auto
1.3 xrandr 命令详情
bash
# xrandr --help
usage: xrandr [options]
where options are:
--display <display> or -d <display>
--help
-o <normal,inverted,left,right,0,1,2,3>
or --orientation <normal,inverted,left,right,0,1,2,3>
-q or --query
-s <size>/<width>x<height> or --size <size>/<width>x<height>
-r <rate> or --rate <rate> or --refresh <rate>
-v or --version
-x (reflect in x)
-y (reflect in y)
--screen <screen>
--verbose
--current
--dryrun
--nograb
--prop or --properties
--fb <width>x<height>
--fbmm <width>x<height>
--dpi <dpi>/<output>
--output <output>
--auto
--mode <mode>
--preferred
--pos <x>x<y>
--rate <rate> or --refresh <rate>
--reflect normal,x,y,xy
--rotate normal,inverted,left,right
--left-of <output>
--right-of <output>
--above <output>
--below <output>
--same-as <output>
--set <property> <value>
--scale <x>x<y>
--scale-from <w>x<h>
--transform <a>,<b>,<c>,<d>,<e>,<f>,<g>,<h>,<i>
--off
--crtc <crtc>
--panning <w>x<h>[+<x>+<y>[/<track:w>x<h>+<x>+<y>[/<border:l>/<t>/<r>/<b>]]]
--gamma <r>:<g>:<b>
--brightness <value>
--primary
--noprimary
--newmode <name> <clock MHz>
<hdisp> <hsync-start> <hsync-end> <htotal>
<vdisp> <vsync-start> <vsync-end> <vtotal>
[flags...]
Valid flags: +HSync -HSync +VSync -VSync
+CSync -CSync CSync Interlace DoubleScan
--rmmode <name>
--addmode <output> <name>
--delmode <output> <name>
--listproviders
--setprovideroutputsource <prov-xid> <source-xid>
--setprovideroffloadsink <prov-xid> <sink-xid>
--listmonitors
--listactivemonitors
--setmonitor <name> {auto|<w>/<mmw>x<h>/<mmh>+<x>+<y>} {none|<output>,<output>,...}
--delmonitor <name>
2 显示设置
2.1 交换内外屏
bash
#!/bin/sh
intern=LVDS1
extern=VGA1
if xrandr | grep "$extern disconnected"; then
xrandr --output "$extern" --off --output "$intern" --auto
else
xrandr --output "$intern" --off --output "$extern" --auto
# 接入外平时更换默认配置可以采用如下参数
# xrandr --output "$intern" --primary --auto --output "$extern" --right-of "$intern" --auto
fi
2.2 规避显示 crash问题
- 前置重新连接
休眠唤醒时部分设备掉线,唤醒后可能发生crash问题。可以通过多次查询显示信息规避crash问题。
bash
declare -i count=2
declare -i seconds=1
while ((count)); do
xrandr >/dev/null
sleep $seconds
((count--))
done
当然也可以强制关闭开机某些屏幕
xrasengan --force -on DisplayPort-0 -off HDMI-0
- 重新加载配置
bash
xrasengan --try-reload-active-layout
3. 添加为检测到分辨率
3.1 xrandr 模式设定
显示器有效的分辨率 xrandr 可能未能全部检测 ,可以通过 xrandr 里为显示器添加所需的分辨率。
- 添加未支持的分辨率
bash
xrandr --newmode '1280x720_60' 60.00 1280 1304 1340 1500 720 723 729 758 -hsync -vsync
- 该分辨率添加到当前的输出设备(将其命名为 DisplayPort-1)
bash
xrandr --addmode DisplayPort-1 1280x720_60
- DisplayPort-1 的分辨率设定为刚刚添加模式
bash
xrandr --output DisplayPort-1 --mode 1280x720_60
- 删除 DisplayPort-1 xrandr 模式
bash
xrandr --rmmode 1280x720_60
归档单一表达式
bash
xrandr --newmode '1280x720_60' 60.00 1280 1304 1340 1500 720 723 729 758 -hsync -vsync && sleep 5 && xrandr --addmode DisplayPort-1 1280x720_60 && xrandr --output DisplayPort-1 --mode 1280x720_60
结语
不枉博主详细讲解,欢迎订阅博主--炭烤毛蛋 。