Last active 1740032542

set-resolution.sh Raw
1#!/bin/bash
2#########################################################################
3# #
4# Set display resolution #
5# #
6# Author: Anthony Axenov (Антон Аксенов) #
7# Version: 1.0 #
8# License: WTFPL #
9# #
10#########################################################################
11# #
12# Using this script you can change your display resolution #
13# to any one you need. Just adjust some vars below and run script #
14# (chmod +x needed). #
15# #
16#########################################################################
17
18# Set display name to work with. You can get it via 'xrandr --listactivemonitors'
19display="HDMI-2"
20# Set width of this display in px
21width=1600
22# Set height of this display in px
23height=900
24
25# Sometimes cvt and gtf generates different modelines.
26# You can play around and look which of them gives best result:
27modeline=$(cvt ${width} ${height} | grep "Modeline")
28# modeline=$(gtf ${width} ${height} 60 | grep "Modeline")
29
30# Some important data needed to xrandr:
31modename="${width}x${height}_my"
32params=$(echo "$modeline" | sed "s|^\s*Modeline\s*\"[0-9x_.]*\"\s*||")
33
34echo "Set resolution ${width}x${height} on display $display:"
35echo "$modename $params"
36
37# Simple logic:
38# 1. Switch display to safe mode which always exists (I believe) to avoid errors
39xrandr --output $display --mode 640x480
40# 2. If display aready have our mode -- we must delete it to avoid errors
41if $(xrandr | grep -q "$modename"); then
42 # 2.1. Detach mode from display
43 xrandr --delmode $display $modename
44 # 2.2. Remove mode itself
45 xrandr --rmmode $modename
46fi
47# 3. Create new mode with freshly generated parameters
48xrandr --newmode $modename $params
49# 4. Attach mode to our display
50xrandr --addmode $display $modename
51# 5. Switch display to this mode immidiately
52xrandr --output $display --mode $modename