---
title: "在Wayland模式的VSCode中使用fcitx5输入中文"
description: "注意：我使用的是 GNOME48 桌面，不保证本文内容对其他桌面环境有效。"
canonical_url: "https://yangqiuyi.com/blog/linux/zai-wayland-mo-shi-de-vscode-zhong-shi-yong-fcitx-5-shu-ru-zhong-wen"
---

> Index of every page on this site: [llms.txt](https://yangqiuyi.com/llms.txt)

# 在Wayland模式的VSCode中使用fcitx5输入中文

**注意**：我使用的是 GNOME48 桌面，不保证本文内容对其他桌面环境有效。

基于 Electron 开发的 VSCode 目前默认运行在 XWayland 下。可能是由于我的 GNOME 桌面使用 125% 的缩放，导致字体变得模糊，总之，我决定将切换到 Wayland 模式。

首先解决如何将 Electron 软件运行在 Wayland 模式。

只需要在运行时加上参数即可<sup>

[1](#user-content-fn-fcitx5-issue)

</sup>

，这里还是以启动 VSCode 为例：

```sh
code --ozone-platform-hint=auto
```

还有一种方法就是使用环境变量：

```sh
ELECTRON_OZONE_PLATFORM_HINT=auto code
```

通过这两种方法启动的 VSCode 都是运行在 Wayland 模式中的，所以字体会清晰不少。

但此时我们的 fcitx5 是无法输入中文的。这是由于软件（例如VSCode）需要将输入事件重定向到输入法，才能使用输入法，软件和输入法中间需要约定一个协议，Xorg 的协议叫做 XIM， Wayland 的协议叫做 text-input，这里我们添加一个参数，指定使用 text-input 协议：

```sh
code --ozone-platform-hint=auto --enable-wayland-ime
```

然而，事情远没有那么简单。text-input 协议虽好，但他要求 Wayland 合成器和客户端使用相同版本的协议<sup>

[2](#user-content-fn-archwiki-fcitx5)

</sup>

，GNOME 只支持 input-text-v3，而 Chromium 默认使用 text-input-v1，所以我们还需要通过一个参数来指定协议版本。

于是，有了最终的指令：

```sh
code --ozone-platform-hint=auto --enable-wayland-ime --wayland-text-input-version=3
```

至此，我终于能在 Wayland 模式使用 VSCode 了。

我使用的是 [visual-studio-code-bin](https://aur.archlinux.org/packages/visual-studio-code-bin)，因此可以新建一个文件 `~/.config/code-flags.conf`，将参数写进去，文件内容如下：

```text
--ozone-platform-hint=auto
--enable-wayland-ime
--wayland-text-input-version=3
```

<section className="footnotes" dataFootnotes="">

## Footnotes

1. [https://github.com/fcitx/fcitx5/issues/1013#issuecomment-2042668469](https://github.com/fcitx/fcitx5/issues/1013#issuecomment-2042668469) [↩](#user-content-fnref-fcitx5-issue)
2. [https://wiki.archlinux.org/title/Fcitx5#Wayland](https://wiki.archlinux.org/title/Fcitx5#Wayland) [↩](#user-content-fnref-archwiki-fcitx5)

</section>

## Sitemap

See the full [sitemap](https://yangqiuyi.com/sitemap.md) for all pages.
