> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/di-15-zhang-ben-di-hua-yu-shu-ru-fa/di-15.4-jie-ibus-shu-ru-fa-kuang-jia.md).

# 15.4 IBus 输入法框架

IBus 即“Intelligent Input Bus”（智能输入总线），是在 Linux 及类 UNIX 系统中广泛应用的输入法框架。

## 安装 IBus 输入法框架

* 使用 pkg 安装：

```sh
# pkg install ibus zh-ibus-libpinyin
```

其中 `zh-ibus-libpinyin` 是智能拼音输入法。

* 或者使用 Ports 安装：

```sh
# cd /usr/ports/textproc/ibus/ && make install clean
# cd /usr/ports/chinese/ibus-libpinyin/ && make install clean
```

可选的输入法包括：

| Port                         | 说明            |
| ---------------------------- | ------------- |
| `chinese/ibus-cangjie`       | 仓颉输入法         |
| `chinese/ibus-chewing`       | 新酷音输入法        |
| `chinese/ibus-rime`          | Rime 输入法引擎    |
| `chinese/ibus-table-chinese` | 包含五笔、仓颉等多种输入法 |

## 配置环境变量

为简体中文 UTF-8 编码设置变量，编辑 **\~/.login\_conf** 文件，加入以下内容：

```ini
me:\
	:lang=zh_CN.UTF-8:\
	:setenv=LC_ALL=zh_CN.UTF-8,LC_COLLATE=zh_CN.UTF-8,LC_CTYPE=zh_CN.UTF-8,LC_MESSAGES=zh_CN.UTF-8,LC_MONETARY=zh_CN.UTF-8,LC_NUMERIC=zh_CN.UTF-8,LC_TIME=zh_CN.UTF-8,XIM=ibus,GTK_IM_MODULE=ibus,QT_IM_MODULE=ibus,XMODIFIERS="@im=ibus",XIM_PROGRAM="ibus-daemon",XIM_ARGS="--daemonize --xim":\
	:charset=UTF-8:
```

其中输入法相关环境变量的含义如下：

| 变量                             | 说明                                                                   |
| ------------------------------ | -------------------------------------------------------------------- |
| `XIM=ibus`                     | 指定 X 输入法（XIM）框架为 IBus                                                |
| `GTK_IM_MODULE=ibus`           | 指定 GTK 应用程序使用 IBus 输入法模块                                             |
| `QT_IM_MODULE=ibus`            | 指定 Qt 应用程序使用 IBus 输入法模块                                              |
| `XMODIFIERS="@im=ibus"`        | 指定 X 应用程序通过 XIM 协议连接 IBus                                            |
| `XIM_PROGRAM="ibus-daemon"`    | 指定 XIM 守护进程的路径                                                       |
| `XIM_ARGS="--daemonize --xim"` | 指定 ibus-daemon 的启动参数，`--daemonize` 表示以后台守护进程模式运行，`--xim` 表示启用 XIM 支持 |

编辑后，需要执行以下命令来更新登录能力数据库：

```sh
$ cap_mkdb ~/.login_conf
```

### Wayland

在 Wayland 下，IBus 的环境变量配置与 X11 有所不同。GNOME 自 3.6 起已集成 IBus，在 GNOME Wayland 下无需手动设置 `GTK_IM_MODULE` 和 `QT_IM_MODULE`。对于其他桌面环境，`GTK_IM_MODULE` 和 `QT_IM_MODULE` 的设置策略与 Fcitx 5 类似（参见 15.3 节 Wayland 部分）。`XIM_PROGRAM` 和 `XIM_ARGS` 仅用于 X11/XWayland 环境，在纯 Wayland 会话中不需要。

## 配置 IBus

完成环境变量配置后，通过以下方式设置 IBus。

IBus 设置工具：

```sh
$ ibus-setup
```

![IBus](/files/jyS9ApffxgzMY4jJbyG7)

## UTF-8 编码

IBus 要求使用 UTF-8 编码，但对区域设置的具体取值（如 `C.UTF-8` 或 `zh_CN.UTF-8`）并无限制。

![IBus](/files/kxesC1Wllumce7Qw4b3g)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/di-15-zhang-ben-di-hua-yu-shu-ru-fa/di-15.4-jie-ibus-shu-ru-fa-kuang-jia.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
