# 6.5.Sway 混成器

Sway 合成器是款平铺合成器，旨在替代 i3 窗口管理器。它应当可以与用户当前的 i3 配置兼容，但某些新功能可能需要额外的设置。

在开始安装 Sway 之前，请确保安装并正确配置了显卡（GPU）。请参考 [图形硬件驱动](https://docs.freebsd.org/en/books/handbook/x11/#x-graphic-card-drivers) 部分进行指导。这一步对于 Sway 合成器的正常工作至关重要。

以下示例假定进行的是一次全新安装，而没有迁移任何 i3 配置。要安装 Sway 和相关组件，请以 root 用户身份执行以下命令：

```sh
# pkg install sway swayidle swaylock-effects alacritty dmenu-wayland dmenu
```

为了获得一个基本的配置文件，执行以下命令并在复制后编辑配置文件：

```sh
% mkdir ~/.config/sway
% cp /usr/local/etc/sway/config ~/.config/sway
```

基本的配置文件包含了许多默认设置，这对大多数用户来说已经足够。以下是需要做的一些重要更改：

```ini
# Logo 键。使用 Mod1 作为 Alt 键。
input * xkb_rules evdev
set $mod Mod4
# 设置你喜欢的终端仿真器
set $term alacritty
set $lock swaylock -f -c 000000
output "My Workstation" mode 1366x768@60Hz position 1366 0
output * bg ~/wallpapers/mywallpaper.png stretch
### 空闲配置
exec swayidle -w \
          timeout 300 'swaylock -f -c 000000' \
          timeout 600 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"' \
          before-sleep 'swaylock -f -c 000000'
```

在上面的例子中，加载了 `evdev(4)` 事件的 `xkb` 规则，并将 $mod 键设置为 Windows 键，以便进行键绑定。接下来，设置了终端仿真器为 `alacritty`，并定义了屏幕锁定命令（稍后会详细介绍）。`output` 关键字定义了显示模式、位置，背景墙纸也被设置并指示 Sway 拉伸墙纸以填充屏幕。最后，`swayidle` 被设置为守护进程，并在 300 秒后锁定屏幕，在 600 秒后进入休眠模式。黑色的锁定背景色（000000）也在这里定义。使用 swaylock-effects，还可以使用 `--clock` 参数在锁屏时显示时钟。请参阅手册页获取更多选项。有关自定义输出选项的更多信息，请查看 [sway-output(5)](https://man.freebsd.org/cgi/man.cgi?query=sway-output\&sektion=5\&format=html) 手册页。

在 Sway 中，按住 Windows 键（mod 键）并按下 <kbd>d</kbd> 键，可以打开应用程序菜单。可以使用键盘上的箭头键进行导航。还有一种方法可以操作条形布局并添加托盘；有关更多信息，请阅读 [sway-bar(5)](https://man.freebsd.org/cgi/man.cgi?query=sway-bar\&sektion=5\&format=html) 手册页。默认配置会将日期和时间添加到右上角。有关示例，请参阅配置文件中的 `Bar` 部分。默认情况下，配置文件没有包含锁定屏幕功能，除了上面示例中启用的锁定定时器。要创建锁定键绑定，需要在 `Key bindings` 部分添加以下行：

```ini
# 手动锁定屏幕
bindsym $mod+Shift+Return exec $lock
```

现在，可以使用 Windows 键+Shift 键+回车键组合来锁定屏幕。无论是通过软件包还是 FreeBSD Ports 安装 Sway，都会安装一个默认的 pam.d 文件。默认配置对大多数用户来说是可以接受的，但也提供了更多高级选项。有关更多信息，请阅读 PAM 文档。

最后，要退出 Sway 并返回到 shell，按住 Windows 键、Shift 键并按 <kbd>e</kbd> 键。将显示一个提示，提供退出 Sway 的选项。在迁移过程中，Sway 可以通过终端仿真器在 X11 桌面环境中启动，例如 Plasma。这样可以在完全迁移到该合成器之前，测试不同的更改和键绑定。要启动 Sway，请执行以下命令：

```sh
% sway -c ~/.config/sway/config
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://handbook.bsdcn.org/di-6-zhang-freebsd-zhong-de-wayland/6.5.sway-hun-cheng-qi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
