xrandr工具

发布于:2024-05-20 ⋅ 阅读:(157) ⋅ 点赞:(0)
xrandr 是一个用于在Linux系统上配置显示器分辨率和屏幕布局的命令行工具。它提供了灵活而强大的功能,可用于解决多种与显示器和图形环境相关的问题。
以下是一些xrandr的重点:

1、显示器检测: xrandr 可以用于检测并列出连接到计算机的显示器和显示器接口,包括 VGA、HDMI、DisplayPort 等。它会显示显示器的名称、分辨率、刷新率等信息。

2、分辨率设置: 可以使用 xrandr 命令来动态更改显示器的分辨率,以适应不同的需求。这对于多显示器设置、投影仪设置或应对显示器支持的不同分辨率非常有用。

3、分辨率模式: xrandr 允许指定特定的分辨率模式。这是重要的,因为不同的显示器和显卡可能支持不同的分辨率和刷新率模式。可以使用 -mode 选项来指定特定的模式。

4、屏幕布局: xrandr 允许配置多个显示器的位置和布局。可以设置它们的相对位置,使它们成为一个扩展的屏幕或克隆屏幕。这对于多显示器工作环境非常有用。

5、旋转和变换: xrandr 支持屏幕旋转、翻转以及变换操作。这允许根据需要进行显示器方向的更改,例如将显示器旋转为竖屏模式。

6、模式参数: 可以使用 xrandr 来设置和调整模式参数,包括刷新率、频率和位深度。这对于对显示器性能和质量有要求的专业应用程序非常重要。

7、脚本和自动化: xrandr 可以与脚本一起使用,以自动配置显示器和分辨率,适应特定环境或任务。这对于系统管理员和自动化任务非常有用。

8、调试和故障排除: 可以使用 xrandr 来诊断和解决与显示器设置相关的问题,如不正确的分辨率、显示器未识别等。

1、主要参数信息

--auto #以系统最大分辨率输出

--off #指定设备设置为关闭

--output #输出设备

--mode #设置分辨率

--rate #设置刷新率

2、帮助信息

[zhouyong@localhost ~]$ 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>

3、查看显示器
[zhouyong@localhost ~]$ xrandr --current
Screen 0: minimum 16 x 16, current 1718 x 926, maximum 32767 x 32767
XWAYLAND0 connected 1712x926+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1712x926      59.88*+
   1152x864      59.96  
   1024x768      59.92  
   800x600       59.86  
   640x480       59.38  
   320x240       59.52  
   1440x900      59.89  
   1280x800      59.81  
   720x480       59.71  
   640x400       59.95  
   320x200       58.96  
   1600x900      59.95  
   1368x768      59.88  
   1280x720      59.86  
   1024x576      59.90  
   864x486       59.92  
   720x400       59.55  
   640x350       59.77  
[zhouyong@localhost ~]$
4、复制屏幕
#xrandr --output XWAYLAND0 --same-as VGA1
5、扩展屏(auto:最大分辨率)
#xrandr --output XWAYLAND0 auto --output VGA1 auto
6、仅显示一屏
#xrandr --output XWAYLAND0 auto --output VGA1 off
7、设置刷新率(rate)
#xrandr --output XWAYLAND0 --mode 1920x1080 -r 60
8、位置关系
#xrandr --output XWAYLAND0 auto --output VGA1 auto --right-of XWAYLAND0
等价方式
#xrandr --output XWAYLAND0 --mode 1024x768 --pos 0x0 --output VGA1 --mode 1600x1200 --pos 1024x0

--right-of #主显示器右侧 

--left-of #主显示器左侧 

--above #主显示器上方 

--below #主显示器下方

9、启动设置方式 /etc/X11/Xsession.d/45custom_xrandr-settings

# If an external monitor is connected, place it with xrandr

# External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1"

EXTERNAL_OUTPUT="VGA"  //扩展屏

INTERNAL_OUTPUT="LVDS" //主屏

# EXTERNAL_LOCATION may be one of: left, right, above, or below

EXTERNAL_LOCATION="right"

case "$EXTERNAL_LOCATION" in

       left|LEFT)

               EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT"

               ;;

       right|RIGHT)

               EXTERNAL_LOCATION="--right-of $INTERNAL_OUTPUT"

               ;;

       top|TOP|above|ABOVE)

               EXTERNAL_LOCATION="--above $INTERNAL_OUTPUT"

               ;;

       bottom|BOTTOM|below|BELOW)

               EXTERNAL_LOCATION="--below $INTERNAL_OUTPUT"

               ;;

       *)

               EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT"

               ;;esac

xrandr | grep $EXTERNAL_OUTPUT | grep " connected "

if [ $? -eq 0 ]; then

    xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --auto $EXTERNAL_LOCATION

    # Alternative command in case of trouble:

    # (sleep 2; xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --auto $EXTERNAL_LOCATION) &amp;

else

    xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --off

fi


网站公告

今日签到

点亮在社区的每一天
去签到