LoginSignup
1
1

More than 1 year has passed since last update.

[Ubuntu Server 22.04] CLI からデスクトップの解像度を変更する

Last updated at Posted at 2023-01-27

注意事項

リンク先に記載

[Ubuntu Server 22.04] 個人的初期設定 覚書

「目次」

CLI からデスクトップの解像度を変更する
  説明
  前提
  解像度変更のやり方
    0.GNOME Desktop を起動しておく
    1.ディスプレイ名を取得
    2.変更可能な解像度一覧を取得
    3.実際に設定する
    備考
  引用元、参照元、参考先

「説明」

 Ubuntu 22.04 における GNOME Desktop の解像度変更方法です。

「前提」

 Wayland であること

解像度変更のやり方

以下の記事からスクリプトを利用させていただきました。

0.GNOME Desktop を起動しておく

sudo systemctl start gdm3
※一度、RDP でも コンソール でも良いですが、デスクトップの画面を表示させといた方が良さそうです。

1.ディスプレイ名を取得
bash
gdbus call --session \
           --dest org.gnome.Mutter.DisplayConfig \
           --object-path /org/gnome/Mutter/DisplayConfig \
           --method org.gnome.Mutter.DisplayConfig.GetResources \
          | tr -s '>,' '\n' \
          | grep 'display-name' \
          | awk -F "[\\\\'<]*" '{$1=""; print $0}'
2.変更可能な解像度一覧を取得
bash
# tail に指定する行番号は、各自調整してください。
gdbus call --session \
           --dest org.gnome.Mutter.DisplayConfig \
           --object-path /org/gnome/Mutter/DisplayConfig \
           --method org.gnome.Mutter.DisplayConfig.GetResources \
          | tr -d '\n' \
          | sed 's/'\),'/'\)\\n'/g' \
          | tail -n +4 \
          > resolution_list.txt

# "横 縦 フレームレート" で表示されます。
sort -t "," -k 3 -k 4 -n resolution_list.txt | awk -F ', ' '{print $3,$4,$5}'
3.実際に設定する

 ※フレームレートが 60.0 等の小数点以下が 0 の場合には、小数点以下を省略してください。
フレームレートの例)
resolution="1600x900@60"
resolution="1280x720@60"
resolution="640x480@59.940475463867188"

bash
‘’display_name="ディスプレイ名"
‘’resolution=" 横 x 縦 @ フレームレート "

例)
display_name="HDMI"
resolution="1280x720@60"

serial="$(gdbus call \
    --session \
    --dest org.gnome.Mutter.DisplayConfig \
    --object-path /org/gnome/Mutter/DisplayConfig \
    --method org.gnome.Mutter.DisplayConfig.GetResources | awk '{print $2}' | tr -d ',')"
echo $serial

gdbus call --session \
           --dest org.gnome.Mutter.DisplayConfig \
           --object-path /org/gnome/Mutter/DisplayConfig \
           --method org.gnome.Mutter.DisplayConfig.ApplyMonitorsConfig \
          $serial 1 "[(0, 0, 1, 0, true, [('$display_name', '$resolution', [] )] )]" "[]"
備考

・設定した解像度の確認
 cat ~/.config/monitors.xml
・うまくいかない場合は、RDP 接続した状態でコマンドを実行するか、
 接続先の ターミナル アプリ から実行してみてください。

引用元、参照元、参考先

Wayland でのコマンドラインによる解像度変更
https://smile-jsp.hateblo.jp/entry/2021/05/04/223356
HiDPI
https://wiki.archlinux.jp/index.php/HiDPI

awk: warning: escape sequence `]' treated as plain `]'
https://stackoverflow.com/questions/25867060/awk-warning-escape-sequence-treated-as-plain/25867768#25867768
Bashコマンドawkで全てのカラムを出力
https://yuis-programming.com/?p=1305
sed コマンドで改行コードを置換したり削除する方法
https://webbibouroku.com/Blog/Article/sed-crlf-lf
sortコマンドについて詳しくまとめました 【Linuxコマンド集】
https://eng-entrance.com/linux-command-sort

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1