「Sway」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎XWayland: add === Idle ===, === Floating windows ===, === Clipboard ===, === Xresources === (from English))
(→‎ヒントとテクニック: === ログイン時に自動起動 === を削除)
209行目: 209行目:
   
 
== ヒントとテクニック ==
 
== ヒントとテクニック ==
 
=== ログイン時に自動起動 ===
 
 
tty1 にログインしたときに起動するには、以下を {{ic|.bash_profile}} に追加してください:
 
 
<nowiki>if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
 
exec sway
 
fi</nowiki>
 
   
 
=== CapsLock/NumLock の有効化 ===
 
=== CapsLock/NumLock の有効化 ===

2021年5月11日 (火) 19:10時点における版

関連記事

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%

brightnessctl を使うことで輝度を制御できます。輝度や色補正を制御するユーティリティについてはバックライトを見てください。

.Xresources

sway で使用するには .Xresources.Xdefaults にコピーしてください。

Idle

Sway has a dedicated idle management daemon named swayidle to handle idling sessions. There are different ways to start and parameterize the daemon. The simplest is to use the config of sway itself. swayidle accepts a multitude of arguments to configure events like timeout (a.k.a. idling), resume (resume from sleep), before-sleep etc. See swayidle(1) for more details and further explanations of the events. Each event can then be assigned an action. To assign multiple actions to an event simply repeat the trigger.

The following instructs swayidle to lock the screen after 30 minutes and turn it off five seconds after:

~/.config/sway/config
exec swayidle -w \
	timeout 1800 'swaylock' \
	timeout 1805 'swaymsg "output * dpms off"' \
	resume 'swaymsg "output * dpms on"'

To turn off a locked screen much sooner e.g. after 10 seconds, grep the process list for your locking manager and execute swaymsg "output * dpms off" accordingly like so:

timeout 10 'if pgrep -x swaylock; then swaymsg "output * dpms off"; fi'

In order to lock the screen before suspending and pause any playing media, amend the following instructions to the swayidle command:

before-sleep 'playerctl pause'
before-sleep 'swaylock'
ノート: Systemd too handles some idle events which may conflict with the ones configured in sway. See loginctl(1) and logind.conf(5) for details on how to configure them.

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

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

dmenu 代替

dmenu は XWayland 上で動作するため、フォーカスが他のところへ移るとアプリケーションは反応しなくなります。反応しなくなった dmenu を元に戻すには sway を再起動する必要があります。rofi を使用するという案もありますが、rofi をメニューとして使用するには、urxvt など wayland ネイティブではない仮想端末から起動しなくてはなりません。Sway でメニューとして起動してもメニューにフォーカスが移りません (rofi にマウスを載せないと入力が通りません)。詳しくは https://github.com/swaywm/sway/issues/1367#issuecomment-332910152 を参照。

カーソルテーマとカーソルの大きさ

カーソルテーマ やカーソルの大きさを変更するには:

~/.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 環境変数を参照しないこともありえます。

既知の問題

仮想環境で使う

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 内のターミナルで実行してください。

ディスプレイの解像度が正しくない

output "HDMI-A-1" res 1280x1024 などの設定オプションで解像度が正しく設定できない場合があります。解像度の設定は wlc コンポジタが受け持っており、TTY からディスプレイの解像度を認識します。

video=HDMI-A-1:1280x1024:e などのカーネルパラメータを指定したりカスタム EDID バイナリ (Kernel Mode Setting を参照) を使用することで TTY の解像度を変えられる場合があります (WLC や Sway の解像度も変わります)。

参照