目次: Linux
Raspberry Pi 3 Model B (以降RasPi 3B)のHDMI出力の解像度はFull HDがデフォルト設定です。今日日のディスプレイで困ることはほぼありませんが、古いアスペクト比4:3のディスプレイなど、Full HD以外の解像度で出力してほしいときが稀にあります。
RasPi 3Bに限りませんけど、X Window Systemはxrandrコマンドで解像度を手軽に変更できます。しかし解像度の設定は保存されず、セッションを終了したり再起動すると元のFull HD出力に戻ります。まあ、これはこれで誤った設定のまま固定されないというありがたい面もあるものの、普通は再起動後も解像度を維持してほしいです。
調べるとX Window Systemの設定ファイルを変更するか、autorandrコマンドで解像度を維持できるみたいです(autorandrのソースコード)。例として1024x768 60Hzの解像度で維持するやり方を挙げます。
$ apt-get install autorandr $ xrandr -s 1024x768 --rate 60 $ autorandr --save (profile名)
設定は~/.config/autorandr/(profile名)/というディレクトリに保存されます。
起動時に解像度を変更している方法が気になったので調べると、XDG autostart(Desktop Application Autostart Specification)を使って実現していました。
Linuxのデスクトップ環境は実装ごとに自動起動の方法が違いますが、XDG autostartは多数のデスクトップ環境が対応している自動起動の仕組みのようです。私が使っている64bit版Raspberry Pi OSはデスクトップ環境としてLXDE (Lightweight X11 Desktop Environment)を採用していて、LXDEもXDG autostartに対応しています。
XDG autostartはデスクトップ表示の際に/etc/xdg/autostart/ディレクトリの下の設定を全部実行します。autorandrの設定は/etc/xdg/autostart/autorandr.desktopにありました。
[Desktop Entry] Name=Autorandr Comment=Automatically select a display configuration based on connected devices Type=Application Exec=/usr/bin/autorandr -c --default default X-GNOME-Autostart-Phase=Initialization
実行されるコマンドラインのうちオプション-cはchangeの意味で、最初に見つけたprofileの解像度に変更します。オプション--defaultはdefaultという名のprofileを使うように変更する指令らしいのですが、効き目が良くわかりません。
もし複数のprofileが存在していた場合にどれが選ばれるのか気になるので、デバッグオプションを付けて実行してみましょう。
$ autorandr -c --default default --debug fullhd (detected) (1st match) (current) xga (detected) (2nd match) | Differences between the two profiles: | [Output HDMI-1] Option --mode (= `1920x1080') is `1024x768' in the new configuration \- Config already loaded $ autorandr -l xga $ autorandr -c --default default --debug xga (detected) (1st match) (current) fullhd (detected) (2nd match) | Differences between the two profiles: | [Output HDMI-1] Option --mode (= `1024x768') is `1920x1080' in the new configuration \- Config already loaded
こんな動作をしました。最後に利用もしくは保存したprofileが使われるみたいですね。
< | 2024 | > | ||||
<< | < | 03 | > | >> | ||
日 | 月 | 火 | 水 | 木 | 金 | 土 |
- | - | - | - | - | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | - | - | - | - | - | - |
合計:
本日: