秋逸

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

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

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

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

只需要在运行时加上参数即可1,这里还是以启动 VSCode 为例:

code --ozone-platform-hint=auto

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

ELECTRON_OZONE_PLATFORM_HINT=auto code

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

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

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

然而,事情远没有那么简单。text-input 协议虽好,但他要求 Wayland 合成器和客户端使用相同版本的协议2,GNOME 只支持 input-text-v3,而 Chromium 默认使用 text-input-v1,所以我们还需要通过一个参数来指定协议版本。

于是,有了最终的指令:

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

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

我使用的是 visual-studio-code-bin,因此可以新建一个文件 ~/.config/code-flags.conf,将参数写进去,文件内容如下:

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

Footnotes

  1. https://github.com/fcitx/fcitx5/issues/1013#issuecomment-2042668469

  2. https://wiki.archlinux.org/title/Fcitx5#Wayland

在Wayland模式的VSCode中使用fcitx5输入中文
: 杨秋逸
https://yangqiuyi.com/blog/linux/在wayland模式的vscode中使用fcitx5输入中文/
© 2025 杨秋逸 . All rights reserved.