Sway

提供: ArchWiki
2021年7月8日 (木) 00:30時点におけるKgx (トーク | 投稿記録)による版 (→‎Idle: 翻訳)
ナビゲーションに移動 検索に移動

関連記事

sway (SirCmpwn's Wayland window manager) は i3 と互換性のある Wayland コンポジタを作成しようという試みです。公式ウェブサイト より:

Sway は Wayland において Xorg の i3 ウィンドウマネージャの代わりとなるウィンドウマネージャです。既存の i3 設定で動作し i3 の機能のほとんどをサポートしています。

インストール

swaysway パッケージでインストールできます。最新の開発版は wlroots-gitAURsway-gitAUR でインストールできます。swaywlroots に緻密に依存しているので、sway 更新時には wlroots も更新するのが望ましいです。

ノート: All proprietary graphics drivers are not supported, including NVIDIA.

また、画面をロックする swaylock や、アイドル時間管理デーモンの swayidle もインストールできます。

デフォルトのアプリケーションランチャーは dmenu であり、ターミナルエミュレータは alacritty です。インストールするか、あるいは設定ファイルで別のアプリケーションに変更するかを、初回起動の前に行なうことが望ましいです。

sway の起動

ヒント: ウィンドウ装飾ライブラリなど設定する必要がある環境変数については Wayland#GUI ライブラリを参照。

ターミナルから

ターミナルに sway と入力すれば sway が起動します。

TTY ログイン時に自動起動

X と同様に、Sway はシェル初期化ファイルに以下を追加することで開始できます。(コマンドシェル#ログインシェルを参照):

if [ -z $DISPLAY ] && [ "$(tty)" == "/dev/tty1" ]; then
  exec sway
fi

詳細については、xinitrc#ログイン時に X を自動起動 を参照してください。

ディスプレイマネージャを使う

ノート: Sway は公式にはディスプレイマネージャをサポートしていません。

sway のセッションは /usr/share/wayland-sessions/sway.desktop にあります。GDMSDDM などのディスプレイマネージャは自動的にセッションを認識します。

あるいは、テキストベースのセッションマネージャを使うこともできます。ディスプレイマネージャ#コンソールを参照してください。

設定

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_LAYOUTXKB_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
ノート: swaybg コマンドの GTK3 フロントエンドに azoteAUR があります。

入力デバイス

特定の入力デバイスの設定を調整することができます。例えば、タッチパッドの 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
ヒント: wevAUR は、Wayland の xorg-xev と同様の機能を提供するツールです。
ノート: systemd は、電源キーやふたの開閉などの特別なキーや、閉じるイベントを処理します。これらは、sway で設定されたものと干渉する可能性があります。systemd での設定方法の詳細については、loginctl(1) および logind.conf(5)} を参照してください。

グラフィカルインジケーターバー

明るさや音量などのパーセント値設定の現在のレベルを、調整時にグラフィックバーで示すことが望ましい場合があります。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'
ノート: systemd も sway で設定されたイベントと競合する可能性のあるアイドルイベントを処理します。構成方法の詳細については、loginctl(1) および logind.conf(5) を参照してください。

Floating windows

To enable floating windows or window assignments, open the application and then use the app_id, the class, the instance and the title attributes to enable floating windows/window assignments. The following command will list the properties of all the open windows.

$ swaymsg -t get_tree

To get only the app_id's of all open windows use:

$ swaymsg -t get_tree | grep "app_id"

To get the app_id of the focused window use:

$ swaymsg -t get_tree | jq -r '..|try select(.focused == true)'

If the app_id happens to be null for some windows, you might have to use the class and/or the instance attributes to enable floating mode/window assignments. You can search the output and create fine grained rules for your windows.

~/.config/sway/config
for_window [app_id="galculator"] floating enable
assign [class="firefox"] -> 3
assign [class="^Urxvt$" instance="^htop$"] -> 9

This is similar to using xorg-xprop to find the class or wm_name attributes in X11.

Clipboard

この記事あるいはセクションは Clipboard と合併することが議論されています。
ノート: Not specific to Sway. (議論: トーク:Sway#)

By default, the clipboard is emptied whenever a window is closed. This can be a surprising default behaviour.

A "clipboard manager" must be installed to make the clipboard's content shared amongst windows.

One example of a clipboard manager, designed for Wayland, is clipman, which can be installed from clipmanAUR or clipman-gitAUR.

To start clipman with Sway, add the following line to your config file:

~/.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
ノート: アプリケーションによっては設定が Wayland ネイティブで動作させることが必要な場合や、大抵のプロプライエタリなアプリケーションなどでは全く Wayland に対応していないことがあります。今のところそのようなアプリケーションが使えるように XWayland は無効化しないことが推奨されます。

ヒントとテクニック

CapsLock/NumLock の有効化

CapsLock や NumLock を有効にするには:

~/.config/sway/config
input * xkb_capslock enable
input * xkb_numlock enable
ノート: Enabling these options may cause Firefox to crash upon reloading your sway config file: Bugzilla 1652820

Current keyboard layout

The current keyboard layout can be retrieved as follows, where kbd_identifier needs to be replaced with your keyboard's identifier:

$ swaymsg -t get_inputs | jq -r '.[] | select(.identifier == "kbd_identifier") | .xkb_active_layout_name'

Backlight toggle

To turn off (and on) your displays with a key (e.g. Pause) bind the following script in your 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

Screen capture and screen sharing

See Screen capture#Wayland.

Color temperature adjustment

See Backlight#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_themeDefault, Adwaita, Simple-and-Soft などに置きかえ、my_cursor_size48 などに置きかえます。 変更を反映させるにはアプリケーションを再起動してください。 さらなる詳細はカーソルテーマsway-input(5) を参照。

ノート: Wayland ではクライアント側でカーソルテーマが決定されます。アプリケーションが$XCURSOR_SIZE, $XCURSOR_THEME 環境変数を参照しないこともありえます。

Manage Sway-specific daemons with systemd

この記事あるいはセクションは systemd/User と合併することが議論されています。
ノート: The graphical-session.target should be described generally on the systemd page. systemd/User#Xorg and systemd is flagged for expansion. (議論: トーク:Sway#)

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

ヒント: Sway's wiki also has a list of known 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 は VirtualBoxVMware 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

これは swaymsgSWAYSOCK のソケットに接続できないことを意味しています。

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 の解像度も変わります)。

参照