Skip to content

Xrandr

How to install

Debian/Ubuntu:

$ sudo apt install x11-xserver-utils

Arch

$ sudo pacman -S xorg-xrandr

Tools

arandr
https://christian.amsuess.com/tools/arandr/
xrandr의 GUI 버전.
화면을 설정한 뒤에 Save as…로 셸 스크립트를 저장
해당 스크립트를 시작 프로그램으로 등록하면 항상 원하는 화면으로 시작할 수 있다.
autorandr
https://github.com/phillipberndt/autorandr
하드웨어 자동인식으로 xrandr 실행

X window의 설정 메뉴에 없는 설정으로 화면 해상도를 변경하는 법

설정에 1600x900 해상도가 없어서 직접 추가해보게 되었다. cvt명령으로 원하는 해상도의 modeline을 계산한다.

$ cvt 1600 900

아래와 같은 결과가 출력된다. 이 출력 결과를 잠시 다른 곳에 복사해 둔다.

1600x900 59.95 Hz (CVT 1.44M9) hsync: 55.99 kHz; pclk: 118.25 MHz
Modeline "1600x900_60.00"  118.25  1600 1696 1856 2112  900 903 908 934 -hsync +vsync

modeline에서 각각의 수치는 video timing에 관련된 것이고 아래와 같다.

이름, pixelclock, hdisp, hsync-start, hsync-end, htotal, vdisp, vsync-start, vsync-end, vtotal

관련 내용은 http://www.arachnoid.com/modelines/ 참고. 덧붙여, pixelclock는 초당 뿌려줄 수 있는 픽셀 수.

xrandr명령으로 현재 디스플레이 정보를 본다.

$ xrandr

아래 결과가 출력되는데, xxxx connected라는 부분이 있다. 디스플레이 장치마다 다르게 나오므로 이 부분의 이름을 기억해 둔다.

Screen 0: minimum 320 x 200, current 1360 x 768, maximum 8192 x 8192
xxxx connected primary 1360x768+0+0 (normal left inverted right x axis y axis) 345mm x 194mm
   1920x1080     59.93 +
   1680x1050     59.95    59.88 
   1600x1024     60.17 
   1400x1050     59.98 
   1280x1024     60.02 
   1440x900      59.89 
   1280x960      60.00 
   1360x768      59.80*   59.96 
   1152x864      60.00 
   1024x768      60.00 
   800x600       60.32    56.25 
   640x480       59.94 

xrandr의 newmodeaddmode로 추가한다.

newmode에서 cvt에서 복사한 modeline수치들을 붙여넣는다.

$ xrandr --newmode "1600x900_60.00"  118.25  1600 1696 1856 2112  900 903 908 934 -hsync +vsync

xrandr를 사용한 xxxx connected라는 부분을 아래와 같이 적용한다.

$ xrandr --addmode xxxx 1600x900_60.00

다시 xrandr를 쳐서 확인해 보면 방금 설정한 해상도가 추가되어 있는 것을 볼 수 있다. 해상도를 적용하려면 xwindow의 디스플레이 설정 메뉴에서 설정해도 되고, 터미널에서도 할 수 있다.

$ xrandr --output xxxx --mode 1600x900_60.00

그러니 이 설정은 컴퓨터를 재부팅하면 초기화된다. 아래와 같이 쉘스크립트로 작성해 두고 xwindow시작 시 자동으로 실행되게 하면 편하다. (x 시스템마다 다르므로 별도 설정)

#!/bin/sh
xrandr --newmode "1600x900_60.00"  118.25  1600 1696 1856 2112  900 903 908 934 -hsync +vsync
xrandr --addmode xxxx 1600x900_60.00
xrandr --output xxxx --mode 1600x900_60.00

모니터 추가 방법

xrandr 명령을 입력하면 평소엔, 아래와 같이 출력되다...

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 293mm x 162mm
   1920x1080     60.03*+  48.03  
DP-1 disconnected (normal left inverted right x axis y axis)
DP-2 disconnected (normal left inverted right x axis y axis)

케이블 연결시 아래와 같이 출력된다.

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 293mm x 162mm
   1920x1080     60.03*+  48.03  
DP-1 connected (normal left inverted right x axis y axis)
   1920x1080     60.00 +  50.00    59.94  
   1920x1080i    60.00    50.00    50.00    59.94  
   1600x1200     60.00  
   1680x1050     59.88  
   1280x1024     75.02    60.02  
   1440x900      59.90  
   1280x960      60.00  
   1360x768      60.02  
   1280x800      59.91  
   1152x864      75.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  
DP-2 disconnected (normal left inverted right x axis y axis)

위의 정보로 미루어 보아, DP-1가 연결되었음을 알 수 있다.

아래의 명령을 사용하면 DP-1를 출력하고, 모드는 1920x1080를 사용하며, eDP-1의 오른쪽에 출력한다.

$ xrandr --output DP-1 --mode 1920x1080 --right-of eDP-1

만약 주 모니터로 사용하고 싶다면 --primary플래그를 추가하면 된다.

설정을 해놔도 재부팅 하면 원래대로 돌아간다. 관련 명령어들만 모아서 /etc/rc.local와 같은 파일에 넣어주면 된다.

전체 디스플레이 정보 보기

단순하게 xrandr 명령을 날리면 된다.

해상도 변경

특정 디스플레이를 특정 해상도로 변경하기

  • rate 는 지정안해도 대부분 무관
  • 모니터가 두 대 이상일 때 그냥 해상도만 지정하면 Mirror방식(동일 화면)으로 됨
$ xrandr --output VGA1 --mode 1024x768 --rate 60

디스플레이 끄기

$ xrandr --output VGA1 --off

듀얼 모니터

서로 다른 화면을 보여주는 듀얼 모니터로 만들고자 할 때

# LVDS1(랩탑의 기본 디스플레이) 오른쪽에 위치하는 화면으로 만든다.
xrandr --output VGA1 --mode 1024x768 --right-of LVDS1

# Laptop 화면을 Primary로
xrandr --output LVDS1 --primary

Scale/HiDPI

--scale 2×2 옵션을 사용하면 된다.

xrandr \
  --output DP-4 --primary --pos 0x0 --scale 2x2 \
  --output DP-2 --pos 3840x0 --scale 2x2 \
  --output eDP-1-1 --off

DPI 변경

$ xrandr --dpi 120

The recommended values:

  • 96 (default value)
  • 120 (25% higher)
  • 144 (50% higher)
  • 168 (75% higher)
  • 192 (100% higher)

화면 회전 방법

다음 방법으로 출력 모니터를 확인하다.

xrandr --verbose | awk '/ connected/{print $1}'

LVDS1로 출력되었을 경우 다음 방법으로 회전한다.

xrandr --output LVDS1 --rotate left
xrandr --output LVDS1 --rotate inverted
xrandr --output LVDS1 --reflect x
xrandr --output LVDS1 --reflect xy

잘못건들경우 화면을 정상적으로 되돌리는 방법:

xrandr --output LVDS1 --rotate normal
xrandr --output LVDS1 --reflect normal

(모니터가 하나라면) 한줄로 해결하는 방법

xrandr --output "$(xrandr --verbose | awk '/ connected/{print $1}')" --rotate right

See also

Favorite site