How to dynamically manage the display resolution, orientation, and refresh rate in Ubuntu

List the resolutions and frequencies supported by the current environment

neardi@LPA3588:~$ xrandr 
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) 0mm x 0mm
   1920x1080     60.00*+  60.00    50.00    30.00    24.00  
   4096x2160     24.00  
   3840x2160     30.00    25.00    24.00  
   1920x1080i    60.00    50.00  
   1280x720      60.00    60.00    50.00    50.00    30.00    24.00  
   720x576       50.00    50.00  
   720x576i      50.00    50.00  
   720x480       59.94    59.94    59.94  
   720x480i      59.94    59.94  
HDMI-2 disconnected (normal left inverted right x axis y axis)
DSI-1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1920x1080     60.00*+
DP-1 disconnected (normal left inverted right x axis y axis)
DP-2 disconnected (normal left inverted right x axis y axis)

1920x1080 is your current resolution. You can see from the output of xrandr that HDMI-1 is your primary display and its current mode is 1920x1080 and its refresh rate is 60.00.

Change resolution

Only one display is connected, no need to switch resolution with parameters

$ xrandr -s 1280x720

You can use the --output option to specify the output to operate, the --mode option to specify the mode to set, the --rate option to specify the refresh rate to set, the --auto option to enable output and set the optimal mode, and the --off option to turn off output. For example:

$ xrandr --output HDMI-1 --mode 1280x720 --rate 60
$ xrandr --output DSI-1 --off
$ xrandr --output DP-1 --auto

Switch dual screen resolution

  • Same display: Set the mode of DSI-1 output (usually the built-in display) to the same as that of HDMI-1 output (usually the external monitor), and overlap the positions of the two outputs to form a mirror display.
$ xrandr --output DSI-1 --same-as HDMI-1 --auto
  • Different display: Set the VGA output (usually an external monitor) to the best mode and place it to the right of the LVDS output (usually a built-in display) to form an extended display.
$ xrandr --output VGA --right-of LVDS --auto
  • Turn off VGA output and only keep the display of other outputs.
$ xrandr --output VGA --off
  • Set the VGA output mode to the best mode and turn off the LVDS output, leaving only the VGA output display.
$ xrandr --output VGA --auto --output LVDS --off
  • Turn off the VGA output and set the LVDS output mode to the best mode, leaving only the LVDS output display.
$ xrandr --output VGA --auto --output LVDS --off

Set contrast

  • Checking HDMI-1 supported properties
$ xrandr --verbose

Check if there are any contrast-related settings. If it is not in the list, your driver does not support this feature.
Normal return example:

HDMI-1 connected primary 1920x1080+0+0 (0x4a) normal (normal left inverted right x axis y axis) 0mm x 0mm
        contrast: 50 
	range: (0, 100)

HDMI-1 supports a contrast property with a range of (0, 100). The current setting shows a contrast of 50.

  • Set HDMI-1 Contrast 80
$ xrandr --output HDMI-1 --set contrast 80

Set home screen

  • Set LVDS as main screen
$ xrandr --output LVDS --primary

Rotate screen

  • Rotate 90 degrees clockwise
$ xrandr --output <display_name> --rotate right
  • Rotate 90 degrees counterclockwise
$ xrandr --output <display_name> --rotate left
  • Rotate 180 degrees
$ xrandr --output <display_name> --rotate inverted
  • Return to normal (no rotation)
$ xrandr --output <display_name> --rotate normal

Set to take effect at startup

Add the corresponding xrandr command to ~/.profile and reboot.