Sway
関連記事
sway (SirCmpwn's Wayland window manager) は i3 と互換性のある Wayland コンポジタを作成しようという試みです。公式ウェブサイト より:
- Sway は Wayland において Xorg の i3 ウィンドウマネージャの代わりとなるウィンドウマネージャです。既存の i3 設定で動作し i3 の機能のほとんどをサポートしています。
目次
- 1 インストール
- 2 sway の起動
- 3 設定
- 4 ヒントとテクニック
- 5 既知の問題
- 6 参照
インストール
sway は sway パッケージでインストールできます。最新の開発版は wlroots-gitAUR と sway-gitAUR でインストールできます。sway は wlroots に緻密に依存しているので、sway 更新時には wlroots も更新するのが望ましいです。
また、画面をロックする swaylock や、アイドル時間管理デーモンの swayidle もインストールできます。
デフォルトのアプリケーションランチャーは dmenu であり、ターミナルエミュレータは alacritty です。インストールするか、あるいは設定ファイルで別のアプリケーションに変更するかを、初回起動の前に行なうことが望ましいです。
sway の起動
ターミナルから
ターミナルに sway と入力すれば sway が起動します。
TTY ログイン時に自動起動
X と同様に、Sway はシェル初期化ファイルに以下を追加することで開始できます。(コマンドシェル#ログインシェルを参照):
if [ -z $DISPLAY ] && [ "$(tty)" == "/dev/tty1" ]; then exec sway fi
詳細については、xinitrc#ログイン時に X を自動起動 を参照してください。
ディスプレイマネージャを使う
sway のセッションは /usr/share/wayland-sessions/sway.desktop にあります。GDM や SDDM などのディスプレイマネージャは自動的にセッションを認識します。
あるいは、テキストベースのセッションマネージャを使うこともできます。ディスプレイマネージャ#コンソールを参照してください。
設定
i3 を既に使っている場合、i3 の設定を ~/.config/sway/config にコピーすればそのまま動作します。i3 を使ったことがない場合は、サンプル設定ファイルを ~/.config/sway/config にコピーしてください。サンプル設定ファイルは /etc/sway/config にあります。ただし DFALLBACK_CONFIG_DIR フラグが設定されている場合は存在しません。設定方法は sway(5) を見てください。
キーマップ
デフォルトでは、sway は US QWERTY キーマップで起動します。キーマップを書き換えるには:
~/.config/sway/config
input * {
xkb_layout "us,de,ru"
xkb_variant "colemak,,typewriter"
xkb_options "grp:win_space_toggle"
}
input <identifier> xkb_model "pc101"
なお、Sway は起動時に XKB_DEFAULT_LAYOUT や XKB_DEFAULT_VARIANT などの環境変数を読み込みますが、環境変数よりも設定ファイルの内容が優先されます。
詳細は sway-input(5) および xkeyboard-config(7) を参照してください。
キーのオートリピート設定
Typematic Delay (オートリピート開始までの時間) と Typematic Rate (1秒間のリピート回数) は、input セクションに以下の行を加えると変更できます。設定項目について詳しくはコンソールでのキーボード設定#typematic delay と rate の調整を参照してください。
~/.config/sway/config
input <identifier> repeat_delay 300 input <identifier> repeat_rate 30
ステータスバー
ステータスバーを表示したいときは i3status プログラムをインストールするのが簡単です。sway の設定の末尾に以下のスニペットを追加するだけで表示できます:
~/.config/sway/config
bar {
status_command i3status
}
i3status をカラー出力させたい場合、i3status の設定の以下の部分を調整してください:
~/.config/i3status/config
general {
colors = true
interval = 5
}
どちらの例でも、システム全体にインストールされた設定ファイルはユーザーディレクトリにコピーされるので、それを修正してください。
壁紙
Sway 1.1 以降、壁紙機能は swaybg に分割され、output コマンドを動作させるのに必要です。
以下の行を sway の設定の最後に追加することで、全ての画面 ("*" という名前にマッチする画面) で背景画像を設定できます:
~/.config/sway/config
output "*" background /path/to/image.jpg fill
ファイルの名前やパスは適当に置き換えて下さい。
また、背景は単一色にもできます:
output * bg #000000 solid_color
入力デバイス
特定の入力デバイスの設定を調整することができます。例えば、タッチパッドの tap-to-click とナチュナルスクロールを有効にするには、以下の input ブロックを追加:
~/.config/sway/config
input "2:14:ETPS/2_Elantech_Touchpad" {
tap enabled
natural_scroll enabled
}
デバイスの識別子は以下のコマンドで確認できます:
$ swaymsg -t get_inputs
上記のコマンドの出力には、"/" などの記号をエスケープするために "\" が付いていることがあります (例: "2:14:ETPS\/2_Elantech_Touchpad")。設定に追加するときはエスケープを取り除いてください。
アクセラレーションなど他のオプションについては sway-input(5) で詳細を確認できます。
HiDPI
設定ファイルの output コマンドでディスプレイのスケールファクタを設定してください。スケールファクタは小数でも指定できます。HiDPI ディスプレイの場合は 2 などに設定してください。
output <name> scale <factor>
ディスプレイの名前は以下のコマンドで確認できます:
$ swaymsg -t get_outputs
カスタムキーバインド
キーボードの特殊なキーを使ってコマンドを実行することができます。例えば、ボリュームや画面の明るさを制御するには:
~/.config/sway/config
bindsym XF86AudioRaiseVolume exec pactl set-sink-volume $(pacmd list-sinks |awk '/* index:/{print $3}') +5%
bindsym XF86AudioLowerVolume exec pactl set-sink-volume $(pacmd list-sinks |awk '/* index:/{print $3}') -5%
bindsym XF86AudioMute exec pactl set-sink-mute $(pacmd list-sinks |awk '/* index:/{print $3}') toggle
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
bindsym XF86MonBrightnessUp exec brightnessctl set +5%
bindsym XF86AudioPlay exec playerctl play-pause
bindsym XF86AudioNext exec playerctl next
bindsym XF86AudioPrev exec playerctl previous
bindsym XF86Search exec bemenu-run
brightnessctl を使うことで輝度を制御できます。輝度や色補正を制御するユーティリティについてはバックライトを見てください。
ロック画面がアクティブなときにキーバインドを実行できるようにするには、--locked パラメーターを bindsym に追加します。
bindsym --locked XF86AudioPlay exec playerctl play-pause
グラフィカルインジケーターバー
明るさや音量などのパーセント値設定の現在のレベルを、調整時にグラフィックバーで示すことが望ましい場合があります。sway でこの機能を提供するための良い選択肢は wobAUR (あるいはwob-gitAUR) で、人気のあるXツール xobAUR の機能のサブセットを提供します、レイヤシェルプロトコルを実装するネイティブの Wayland ユーティリティとして提供する。使用例については、 project website を参照してください。
アイドリング
Sway には、アイドルセッションを処理するための専用のアイドル管理デーモン swayidle があります。デーモンを起動してパラメータ化する方法はいくつかあります。最も簡単な方法は、sway 自体の設定を使用することです。swayidle は、timeout (別名 idling)、resume (resume from sleep) 、before-sleep などのイベントを構成するための多数の引数を受け取ります。イベントの詳細と詳細については、swayidle(1) を参照してください。その後、各イベントにアクションを割り当てることができます。イベントに複数のアクションを割り当てるには、トリガーを繰り返すだけです。
次の例では、swayidle 30分後に画面をロックし、5/2後に画面をオフにします。
~/.config/sway/config
exec swayidle -w \ timeout 1800 'swaylock' \ timeout 1805 'swaymsg "output * dpms off"' \ resume 'swaymsg "output * dpms on"'
ロックされたスクリーンをもっと早く、例えば10秒後にオフにするには、ロックマネージャのプロセスリストを grep し、以下のように swaymsg "output * dpms off" を実行します。
timeout 10 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi'
再生中のメディアを一時停止または一時停止する前に画面をロックするには、swayidle コマンドの次の指示を修正します。
before-sleep 'playerctl pause' before-sleep 'swaylock'
フローティングウィンドウ
フローティングウィンドウまたはウィンドウの割り当てを有効にするには、アプリケーションを開き、app_id、class、instance、および title 属性を使用して、フローティングウィンドウの割り当てを有効にします。次のコマンドは、開いているすべてのウィンドウのプロパティを一覧表示します。
$ swaymsg -t get_tree
開いているすべてのウィンドウの app_id のみを取得するには、次を使用します。
$ swaymsg -t get_tree | grep "app_id"
フォーカスのあるウィンドウの app_id を取得するには、次を使用します。
$ swaymsg -t get_tree | jq -r '..|try select(.focused == true)'
一部のウィンドウで app_id が null になる場合は、class 属性または instance 属性 (あるいはその両方) を使用して、フローティングモード/ウィンドウの割り当てを有効にする必要があります。出力を検索して、ウィンドウの細かいルールを作成できます。
~/.config/sway/config
for_window [app_id="galculator"] floating enable assign [class="firefox"] -> 3 assign [class="^Urxvt$" instance="^htop$"] -> 9
これは、xorg-xprop を使用して X 11 の class または wm_name 属性を検索するのと似ています。
Clipboard
デフォルトでは、ウィンドウを閉じるとクリップボードは空になります。
クリップボードの内容をウィンドウ間で共有するには、 "クリップボードマネージャ" をインストールする必要があります。
Wayland 用に設計されたクリップボードマネージャの一例は、clipmanAUR または clipman-gitAUR からインストールできる clipman です。
Sway で clipman を起動するには、設定ファイルに次の行を追加します。
~/.config/sway/config
exec wl-paste -t text --watch clipman store
Xresources
sway で使用するには .Xresources を .Xdefaults にコピーしてください。
XWayland
"cannot open display" というエラーでプログラムが起動しない場合、X上で動作するプログラムであることが考えられます。XWayland 互換レイヤーを使うと Wayland 上で動作させられます。xorg-server-wayland[リンク切れ: パッケージが存在しません] パッケージをインストールしてください。
一方、XWayland を無効化し、Sway の純粋な Wayland セッションを使うには次のようにします:
~/.config/sway/config
xwayland disable
ヒントとテクニック
CapsLock/NumLock の有効化
CapsLock や NumLock を有効にするには:
~/.config/sway/config
input * xkb_capslock enable input * xkb_numlock enable
現在のキーボードレイアウト
現在のキーボードレイアウトは、次のようにして取得できます。kbd_identifier は、キーボードの識別子で置き換える必要があります。
$ swaymsg -t get_inputs | jq -r '.[] | select(.identifier == "kbd_identifier") | .xkb_active_layout_name'
バックライト切り替え
ディスプレイの電源をオフ (またはオン) にするには (例:Pause)、次のスクリプトを Sway config でバインドします。
#!/bin/sh
read lcd < /tmp/lcd
if [ "$lcd" -eq "0" ]; then
swaymsg "output * dpms on"
echo 1 > /tmp/lcd
else
swaymsg "output * dpms off"
echo 0 > /tmp/lcd
fi
画面キャプチャと画面共有
こちらを参照 スクリーンキャャプチャ#Wayland
色温度調整
こちらを参照 バックライト#Wayland.
Control swaynag with the keyboard
Swaynag, the default warning/prompt program shipped with sway, only supports user interaction with the mouse. A helper program such as swaynagmodeAUR may be used to enable interaction via keyboard shortcuts.
Swaynagmode works by first launching swaynag, then listening for signals which trigger actions such as selecting the next button, dismissing the prompt, or accepting the selected button. These signals are sent by launching another instance of the swaynagmode script itself with a control argument, such as swaynagmode --select right or swaynagmode --confirm.
Swaynagmode by default triggers the sway mode nag upon initialization, followed by default on exit. This makes it easy to define keybindings in your sway configuration:
~/.config/sway/config
set $nag exec swaynagmode
mode "nag" {
bindsym {
Ctrl+d mode "default"
Ctrl+c $nag --exit
q $nag --exit
Escape $nag --exit
Return $nag --confirm
Tab $nag --select prev
Shift+Tab $nag --select next
Left $nag --select next
Right $nag --select prev
Up $nag --select next
Down $nag --select prev
}
}
Note that, beginning in sway version 1.2, mode names are case-sensitive.
You can configure sway to use swaynagmode with the configuration command swaynag_command swaynagmode.
カーソルテーマとカーソルの大きさ
カーソルテーマ やカーソルの大きさを変更するには:
~/.config/sway/config
seat seat0 xcursor_theme my_cursor_theme my_cursor_size
my_cursor_theme は Default, Adwaita, Simple-and-Soft などに置きかえ、my_cursor_size は 48 などに置きかえます。
変更を反映させるにはアプリケーションを再起動してください。
さらなる詳細はカーソルテーマと sway-input(5) を参照。
Manage Sway-specific daemons with systemd
Users may want to start some services/daemons (such as swayidle or kanshi) only when the current window manager is Sway, and they may also want these services to stop when Sway stops. This can be done by creating a sway-session.target and let those daemons/services wanted by sway-session.target. This systemd target should be a user target (see systemd/User). For example:
~/.config/systemd/user/sway-session.target
[Unit] Description=Sway compositor session Documentation=man:systemd.special BindsTo=graphical-session.target Wants=graphical-session-pre.target After=graphical-session-pre.target
Then, add the following line to Sway's config file (for example, append the line to ~/.config/sway/config, or add a new file to /etc/sway/config.d/):
~/.config/sway/config
... ... ... exec_always "systemctl --user import-environment; systemctl --user start sway-session.target"
With the above line in the configuration file, whenever Sway starts, it also activates sway-session.target.
Finally, link the desired services to sway-session.target. For example, adding a kanshi (or kanshi-gitAUR) service:
~/.config/systemd/user/kanshi.service
[Unit] Description=Dynamic output configuration for Wayland compositors Documentation=https://github.com/emersion/kanshi BindsTo=sway-session.target [Service] Type=simple ExecStart=/usr/bin/kanshi [Install] WantedBy=sway-session.target
When this service is enabled (with --user flag), it is only activated when Sway is running and deactivated when Sway stops:
$ systemctl --user enable --now kanshi.service
既知の問題
Application launchers
i3-dmenu-desktop, dmenu, and rofi all function relatively well in Sway, but all run under XWayland and suffer from the same issue where they can become unresponsive if the cursor is moved to a native Wayland window. The reason for this issue is that Wayland clients/windows do not have access to input devices unless they have focus of the screen. The XWayland server is itself a client to the Wayland compositor, so one of its XWayland clients must have focus for it to access user input. However, once one of its clients has focus, it can gather input and make it available to all XWayland clients through the X11 protocol. Hence, moving the cursor to an XWayland window and pressing Escape should fix the issue, and sometimes running pkill does too.
bemenu is a native Wayland dmenu replacement which can optionally be combined with j4-dmenu-desktopAUR to provide a Wayland-native combination for launching desktop files (as i3-dmenu-desktop does):
j4-dmenu-desktop --dmenu='bemenu -i --nb "#3f3f3f" --nf "#dcdccc" --fn "pango:DejaVu Sans Mono 12"' --term='termite'
You may need to set BEMENU_BACKEND environment variable to "wayland" if you choose not to disable XWayland.
You can also build your own with a floating terminal and fzf as discussed in a GitHub issue.
Also krunner binary provided by plasma-workspace package can serve as launcher, offering both XWayland and native Wayland support.
rofi-lbonn-wayland-gitAUR is a fork of rofi that works in Wayland and also has an -x11 flag if you need to launch it in an X11 session.
wofi is a command launcher, that provides some of the same features as rofi but running under Wayland. wofi lacks some features from rofi like an SSH mode and a window-switching mode. It is based on wlroots library and use GTK3 for rendering. It works pretty well with sway.
仮想環境で使う
Sway は VirtualBox や VMware ESXi 上でも動作するものの、場合によっては設定が必要です。
Sway を tty から起動できない
3D アクセラレーションを有効にする必要があります。VMware#Intel と Optimus で 3D グラフィックを有効化 を参照してください。
マウスカーソルが表示されない
VMSVGA グラフィックコントローラーを使うとカーソルが表示されません。Sway 起動時に WLR_NO_HARDWARE_CURSORS 変数を設定すると解決します。詳細は [1] を参照してください。
Sway Socket Not Detected
ターミナルマルチプレクサ (例: GNU Screen や tmux) の中で swaymsg -t get_outputs などのように swaymsg を使ったときに、以下のようなメッセージが返ってくることがあります:
sway socket not detected. ERROR: Unable to connect to
これは swaymsg が SWAYSOCK のソケットに接続できないことを意味しています。
SWAYSOCK の現在の値を確認するには:
$ env | fgrep SWAYSOCK SWAYSOCK=/run/user/1000/sway-ipc.1000.4981.sock
最初の sway ソケットにアタッチしてみて、コマンドを再実行してみてください:
$ export SWAYSOCK=$(ls /run/user/*/sway-ipc.*.sock | head -n 1)
上記のエラーを解決するには、マルチプレクサの外でコマンドを実行する必要があります。
Unable to retrieve socket path
tty から swaymsg -t を実行すると、
Unable to retrieve socket path
というメッセージが表示されます。これは SWAYLOCK 環境変数が Sway 起動後に設定されるためで、swaymsg は Sway 内のターミナルで実行してください。
Keybindings and keyboard layouts
By default, if you are using more than one keyboard layout, e.g. input * xkb_layout "us,ru", bindings may become broken when you switch on some secondary layout.
Thanks to https://github.com/swaywm/sway/pull/3058, all you need is to add --to-code key to sensitive bindsym lines like this:
bindsym --to-code {
$mod+$left focus left
$mod+$down focus down
$mod+$up focus up
$mod+$right focus right
}
Alternatively you can create a variable set $mybind bindsym --to-code and then replace all instances of bindsym with $mybind like so: $mybind $mod+w thing
Java applications
Some Java-based applications will display blank screen when opened, for example any JetBrains editor such as IntelliJ, CLion, or PyCharm. To mitigate this, the application can be started with the _JAVA_AWT_WM_NONREPARENTING environment variable set to 1.
If you start the application from a launcher like rofi or dmenu, you might want to modify the application desktop entry as shown in Desktop entries#Modify environment variables.
Some issues with Java applications have been fixed in OpenJDK 11 and Sway 1.5. However, certain applications require additional configuration to use newer versions of OpenJDK, in the case of Android Studio you must set STUDIO_JDK=/usr/lib/jvm/java-11-openjdk/. [2]
Scroll on border
If using the mouse scroll wheel on an application's border crashes sway, you could use border none for the app_id (e.g. Firefox).
Program cannot open display
If a program crashes on start with the error message "cannot open display", it is likely that the program you are using is an X11 program. You can use the XWayland compatibility layer to run X11 programs under Wayland, see #XWayland for details.
Sway v1.6 shows garbage when using nouveau
If sway displays a corrupted image on one or more displays connected to an Nvidia GPU using nouveau, but starts properly otherwise, try setting WLR_DRM_NO_MODIFIERS=1 before starting sway.
$ WLR_DRM_NO_MODIFIERS=1 sway
The underlying issue relates to outstanding nouveau bugs in Mesa, and should be fixed in a future update. [3]
ディスプレイの解像度が正しくない
output "HDMI-A-1" res 1280x1024 などの設定オプションで解像度が正しく設定できない場合があります。解像度の設定は wlc コンポジタが受け持っており、TTY からディスプレイの解像度を認識します。
video=HDMI-A-1:1280x1024:e などのカーネルパラメータを指定したりカスタム EDID バイナリ (Kernel Mode Setting を参照) を使用することで TTY の解像度を変えられる場合があります (WLC や Sway の解像度も変わります)。