先日、ハッカソンに参加しました。
そこで私のPCでプレゼンをしたのですが、PC画面とプロジェクターを同期するのに数十秒かかってしまいました。
最近LTなどプロジェクターを使う機会も増えているのでコマンド一発でミラーリングしたいなーと思い、ツールを作りました。
インストール
go get github.com/pocke/xrandr-mirror
使い方
プロジェクターを繋いで、
$ xrandr-mirror
これだけ!
実装
xrandr
コマンドを引数なしで叩くと、以下のようにつながれているディスプレイの一覧と設定できるサイズを返します。
$ xrandr Screen 0: minimum 8 x 8, current 5040 x 2160, maximum 32767 x 32767 DP1 connected 3840x2160+1200+0 (normal left inverted right x axis y axis) 878mm x 485mm 3840x2160 60.00*+ 30.00 29.98 24.00 2560x1440 59.95 2048x1080 59.99 1920x1080 60.00 60.00 50.00 59.94 1920x1080i 60.00 50.00 59.94 1680x1050 59.95 1280x1024 75.02 60.02 1440x900 74.98 59.89 1280x960 60.00 1280x720 60.00 50.00 59.94 1024x768 75.08 60.00 800x600 75.00 60.32 720x576 50.00 720x480 60.00 59.94 640x480 75.00 72.81 66.67 60.00 59.94 720x400 70.08 DP2 disconnected (normal left inverted right x axis y axis) HDMI1 disconnected (normal left inverted right x axis y axis) HDMI2 disconnected (normal left inverted right x axis y axis) HDMI3 connected 1200x1920+0+0 left (normal left inverted right x axis y axis) 518mm x 324mm 1920x1200 59.95*+ 1920x1080 60.00 1600x1200 60.00 1680x1050 59.88 1600x900 60.00 1280x1024 75.02 60.02 1440x900 59.90 1024x768 75.08 60.00 800x600 75.00 60.32 640x480 75.00 60.00 720x400 70.08 VIRTUAL1 disconnected (normal left inverted right x axis y axis)
そこでこの出力を適当な正規表現でパースして、各ディスプレイに設定できるサイズを取得します。
そしてその中から共通したものを取り出し、それを以下のようなコマンドで全てのディスプレイに適用しています。
xrandr --output HDMI3 --mode 1920x1080 --same-as DP1
これで次にLTする時は素早く出来るぞーーーー