BioErrorLog Tech Blog

試行錯誤の記録

Ubuntuディスプレイ解像度の変更 | 1920x1080

Ubuntuで1920x1080の解像度(or任意の解像度)を設定する手順を整理します。

結論を言うと、次のコマンドの実行で1920x1080の解像度になります。

$ xrandr --newmode "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
$ xrandr --addmode Virtual1 1920x1080_60.00
$ xrandr --output Virtual1 --mode 1920x1080_60.00

これらのコマンド処理をひとつひとつ読み解いていきます。

はじめに

こんにちは、@bioerrorlogです。

最近、Ubuntuをはじめてインストールしてみました。

しかしウィンドウの大きさが小さく、あまり使い勝手がよくありません。

解像度をディスプレイに合わせる操作など簡単かに思えましたが、コマンド操作に慣れていなかったこともあり、なかなか手間取りました。

実行した手順を記録しておきます。

作業環境

Ubuntu18.04.1 LTS を
Windows10の上に、VMwareによって構築した仮想環境で起動しています。
www.bioerrorlog.work

Ubuntuディスプレイ解像度の変更

既存の解像度に設定する

コマンド操作を使わずとも、ディスプレイ解像度を変更することはできます。

左上の「Activities」から「Displays」を検索

「Resolusion」から好きな解像度を選択

ただ、ここで少し手間取いました。 インストール時のデフォルト解像度では、ウィンドウ右上にある「Apply」ボタンがウィンドウ外に見切れていたためです。 落ち着いてDisplaysウィンドウを視野内に移動させれば「Apply」ボタンをクリックできます。

そして、この既存の解像度の中には1920x1080がありません。 とりあえず1680x1050などに設定しておいて、1920x1080を設定する方法を探りました。

調べた結果、次の手順で新しい解像度を追加できることが分かりました:

  1. 追加したい解像度のパラメータを取得する
  2. 取得したパラメータを使って、設定に新しい解像度を追加する

新しい解像度のパラメータを取得する | cvt

cvt というコマンドを使えば、ディスプレイ解像度を設定するための諸々のパラメータを取得できるようです。
さっそくcvtのマニュアルを読んでみます。

$ man cvt
~
NAME
       cvt - calculate VESA CVT mode lines

SYNOPSIS
       cvt [-v|--verbose] [-r|--reduced] h-resolution v-resolution [refresh]

DESCRIPTION
       Cvt  is  a utility for calculating VESA Coordinated Video Timing modes.
       Given the desired  horizontal  and  vertical  resolutions,  a  modeline
       adhering  to the CVT standard is printed. This modeline can be included
       in Xorg xorg.conf(5)
~

好みの解像度を渡してあげることで "VESA Coordinated Video Timing modes" なるものを表示してくれるようです。
しかし、私は"VESA Coordinated Video Timing modes"を知りませんでしたので、調べてみます。

まずは"VESA"について、wikipedia曰く

VESA (/ˈviːsə/), formally known as Video Electronics Standards Association, is a technical standards organization for computer display standards. The organization was incorporated in California in July 1989[1] and has its office in San Jose, California. It claims a membership of over 225 companies.

ディスプレイについて、歴史の長い標準化団体といった感じでしょう。

続いて"Coordinated Video Timing (CVT)"について調べると

Coordinated Video Timings (CVT; VESA-2013-3 v1.2[1]) is a standard by VESA which defines the timings of the component video signal. Initially intended for use by computer monitors and video cards, the standard made its way into consumer televisions.
The parameters defined by standard include horizontal blanking and vertical blanking intervals, horizontal frequency and vertical frequency (collectively, pixel clock rate or video signal bandwidth), and horizontal/vertical sync polarity.

ディスプレイ表示用のシグナルを送るタイミングを制御するパラメータ、みたいなものだそうですが、私はハード面についても詳しくないので、よくわかりません。
あまり深堀せずに先へ行きます。

それではcvtに1920x1080を渡します。

$ cvt 1920 1080
# 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz
Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync

何やら面白そうな文字列がたくさん出てきました。
"Hz", "Modeline", "hsync", "vsync"など、さっきwikipediaで見たような文字列が複数登場しているところを見るに、ちゃんとあるべきパラメータを出力してくれたみたいです。

次は、このパラメータを使って1920x1080解像度を設定に追加します。


[関連記事] Ubuntuディスプレイ解像度を自動で1920x1080に変更させる


取得したパラメータを使って解像度を追加する | xrandr

設定に解像度を追加するには、xrandrコマンドを使うようです。
マニュアルを読みます。

$ man xrandr
~
DESCRIPTION
       Xrandr is used to set the size, orientation and/or  reflection  of  the
       outputs for a screen. It can also set the screen size.
~

まさしく、スクリーン出力をセットするコマンドのようです。
早速使っていきます。

$ xrandr
Screen 0: minimum 1 x 1, current 1680 x 1050, maximum 8192 x 8192
Virtual1 connected primary 1680x1050+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   800x600       60.00 +  60.32
   2560x1600     59.99
   1920x1440     60.00
   1856x1392     60.00
   1792x1344     60.00
   1920x1200     59.88
   1600x1200     60.00
   1680x1050     59.95*
   1400x1050     59.98
   1280x1024     60.02
   1440x900      59.89
   1280x960      60.00
   1360x768      60.02
   1280x800      59.81
   1152x864      75.00
   1280x768      59.87
   1024x768      60.00
   640x480       59.94
Virtual2 disconnected (normal left inverted right x axis y axis)
Virtual3 disconnected (normal left inverted right x axis y axis)
Virtual4 disconnected (normal left inverted right x axis y axis)
Virtual5 disconnected (normal left inverted right x axis y axis)
Virtual6 disconnected (normal left inverted right x axis y axis)
Virtual7 disconnected (normal left inverted right x axis y axis)
Virtual8 disconnected (normal left inverted right x axis y axis)

いまは "Virtual1" というディスプレイが接続されているようです。 仮想環境でUbuntuを起動しているため、このような名前なのでしょう。
そして、"Virtual1"の解像度の中に1920x1080がないことがわかります。

ちなみにディスプレイは潜在的に "Virtual8" までありますね。 8枚まではディスプレイを増やせるということでしょうか。

それでは"Virtual1"に1920x1080を追加します。 このあたりの流れはArchWikiのxrandr解説を参考にしました。

$ xrandr --newmode "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync

ここの--newmodeの後には、先程のcvtコマンド出力を貼り付けています。
このコマンドを実行した後、再びxrandrを実行すると、

$ xrandr
~
Virtual6 disconnected (normal left inverted right x axis y axis)
Virtual7 disconnected (normal left inverted right x axis y axis)
Virtual8 disconnected (normal left inverted right x axis y axis)
  1920x1080_60.00 (0x288) 173.000MHz -HSync +VSync
        h: width  1920 start 2048 end 2248 total 2576 skew    0 clock  67.16KHz
        v: height 1080 start 1083 end 1088 total 1120           clock  59.96Hz

最後尾に解像度1920x1080が追加されています。


[関連記事] 実験 | Ubuntuディスプレイ解像度を"1x1"に設定してみたい


それでは、この1920x1080を"Virtual1"に追加します。

$ xrandr --addmode Virtual1 1920x1080_60.00

このコマンドを実行すると、一旦解像度がデフォルトの小さいサイズに変わりますが、焦る必要はありません。
xrandrコマンドで確認します。

$ xrandr
Screen 0: minimum 1 x 1, current 800 x 600, maximum 8192 x 8192
Virtual1 connected primary 800x600+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   800x600       60.00*+  60.32
   2560x1600     59.99
   1920x1440     60.00
   1856x1392     60.00
   1792x1344     60.00
   1920x1200     59.88
   1600x1200     60.00
   1680x1050     59.95
   1400x1050     59.98
   1280x1024     60.02
   1440x900      59.89
   1280x960      60.00
   1360x768      60.02
   1280x800      59.81
   1152x864      75.00
   1280x768      59.87
   1024x768      60.00
   640x480       59.94
   1920x1080_60.00  59.96
Virtual2 disconnected (normal left inverted right x axis y axis)
Virtual3 disconnected (normal left inverted right x axis y axis)
~

見事、"Virtual1"に解像度1920x1080が追加されました。

あとは1920x1080を選択します。
最初にやったように、

左上の「Activities」から「Displays」を検索

「Resolusion」から1920x1080を選択

で完了です。

あるいはコマンドからも設定できるようです。

$ xrandr --output Virtual1 --mode 1920x1080_60.00

フルスクリーン表示に切り替えれば、画面ぴったりでUbuntuが使えます。


[関連記事] VMware上のUbuntuをマルチディスプレイにする


おわりに

今回は、Ubuntuにおける解像度の設定方法を記録しました。

しかし、今回のやり方は注意が必要で、単純に今回の手順を繰り返すだけだと、一度シャットダウンした時にリセットされてしまいます。
シャットダウンしても解像度が維持されるやり方があるので、別途記録します

なお本題とは関係ありませんが、$ xrandrの出力結果は大変面白そうな香りがしました。
出力をよく見てみると、
Screen 0: minimum 1 x 1, current 800 x 600, maximum 8192 x 8192
とあります。

ここで、maximum 8192 x 8192はまだわかります。
しかし、minimum 1 x 1とは一体どういうことでしょうか。
1x1のディスプレイを設定してしまったら、この先どうやって生きていけばよいのでしょう。

ぜひ試してみたいです。

[関連記事]

www.bioerrorlog.work

www.bioerrorlog.work

www.bioerrorlog.work

参考

Video Electronics Standards Association - Wikipedia

Coordinated Video Timings - Wikipedia

xrandr - ArchWiki