Difference between revisions of "Setup Fcitx 5/zh-cn"

From Fcitx
Jump to navigation Jump to search
(Created page with "此配置将在您首次用户会话登录时应用,并在之后持续存在,除非您手动停止 systemd 用户。因此,修改此配置后,使其生效的最简单...")
(Created page with "语法与 shell 类似,但不需要 <code>export</code>。例如,您可以创建一个包含以下内容的文件 <code>~/.config/environment.d/im.conf</code>: <nowiki>...")
Line 84: Line 84:
 
此配置将在您首次用户会话登录时应用,并在之后持续存在,除非您手动停止 systemd 用户。因此,修改此配置后,使其生效的最简单方法是重新启动系统。
 
此配置将在您首次用户会话登录时应用,并在之后持续存在,除非您手动停止 systemd 用户。因此,修改此配置后,使其生效的最简单方法是重新启动系统。
  
The syntax is similar to shell, but no <code>export</code> is required. For example, you can create a file <code>~/.config/environment.d/im.conf</code> with following content:
+
语法与 shell 类似,但不需要 <code>export</code>。例如,您可以创建一个包含以下内容的文件 <code>~/.config/environment.d/im.conf</code>
 
  <nowiki>
 
  <nowiki>
 
XMODIFIERS=@im=fcitx
 
XMODIFIERS=@im=fcitx

Revision as of 03:20, 18 March 2024

Other languages:
English • ‎中文(中国大陆)‎

开机自启动

特定发行版中的工具

特定的发行版可能会提供一些用于自动启动 Fcitx 的工具,并且这些工具通常也会设置环境变量。

im-config (Debian/Debian-based/Ubuntu)

这是一个用于 Debian 和 Debian-based 发行版的工具。在登录到 GUI 之后,从命令行执行 im-config,应该会弹出一个向导程序,在其中选择 fcitx5 即可。

imsettings (Fedora)

这是一个与 im-config 类似的程序,它也提供了 GUI 来选择要使用的输入法框架。imsettings 应该是被默认安装的,如果没有,你可以手动安装它。imsettings 可以设置环境变量并且启动相应的输入法,它还提供了一个图形化的前端用于修改配置。你需要做的就是简单地执行im-chooser,log-out 然后再次 log-in。

针对 Fedora 36 KDE 的操作说明。 这个操作说明应该适用于除 GNOME 外的 XDG 兼容桌面。

fcitx5-autostart (Fedora)

这是一个 [fedora package],打包了一个用于设置环境变量和 XDG autostart file 的 /etc/profile.d 脚本,可用于自启动。

XDG Autostart

特定的发行版可能没有提供这个文件,如未提供,你可以直接复制 /usr/share/applications/org.fcitx.Fcitx5.desktop~/.config/autostart

mkdir -p ~/.config/autostart && cp /usr/share/applications/org.fcitx.Fcitx5.desktop ~/.config/autostart

KWin Wayland 5.24+

如果你只使用 Gtk/Qt/Xwayland 应用,那么你不需要这里的操作。如果你希望使用支持 text-input-v3 的原生 wayland 应用,则需要让 KWin 将输入法作为一个特殊的客户端启动。

打开 systemsettings,转到 "Virtual Keyboard" 部分,将输入法从 "None" 改为 "Fcitx 5"

非 XDG 兼容的窗口管理器/Wayland Compoistor

在不支持 XDG Autostart 的场景中,请检查你的窗口管理器的手册中关于如何在系统启动时自动运行应用程序的方法。

Weston

Weston 是一个 wayland compositor 的参考实现,并不是普通用户的常规配置。

如果你希望使用 westons zwp_input_method_v1 实现,你需要确保以下内容存在 ~/.config/weston.ini 文件中(如果路径不是 /usr/bin/fcitx5 请做相应修改)。

[input-method]
path=/usr/bin/fcitx5

如果你已经在同一个会话中运行 fcitx5,当你为了调试和 fcitx5 尝试在 nested mode 中使用 weston 时,会存在特定的问题。

如果你出于调试目的只在 X11 中运行 weston,最简单的方法是在启动 weston 前退出 fcitx5.

另请注意,weston 有一个 bug,在首次运行时不会正确设置 DISPLAY 为输入法。您可能需要终止 fcitx5 一次才能使其正确设置 DISPLAY,或使用 OpenX11Connection dbus 调用来连接 fcitx。

环境变量

由于许多地方都处于过渡阶段,因此没有适合所有人的完美解决方案。请根据您的环境选择适合您的解决方案。基本上,您想要做的是为桌面会话设置以下环境变量。

 
 XMODIFIERS=@im=fcitx
 GTK_IM_MODULE=fcitx
 QT_IM_MODULE=fcitx
虽然它看起来像有效的 shell 脚本,但请 *注意* 上面的代码片段只是为了演示这些值是什么。请检查以下部分以了解不同方法的具体语法。

登录 shell 配置文件

如果您正在使用Bash作为您的登录shell,~/.bash_profile 是您可以信赖的最好的用户级东西。它受到不同 DM 的广泛支持,如果您从 TTY 启动图形,它也可以工作。

  • 支持主流显示管理器,包括GDM/SDDM/LightDM
  • TTY 登录

如果您不使用 bash,您可能需要仔细检查您的 shell 配置文件是否可以用作设置环境变量的位置,尤其是当您正在使用一些不常见的登录 shell时。

您需要添加到 ~/.bash_profile 的代码片段如下:

export XMODIFIERS=@im=fcitx
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx

有些人可能会认为 ~/.profile 是一个与 shell 无关的解决方案,这是错误的。虽然 GDM 始终获取此文件,但如果 ~/.bash_profile 存在,SDDM/Bash 将不会获取此文件。这使得 ~/.bash_profile 成为更好的解决方案,因为 bash 的使用相当广泛。但在继续之前请检查您的登录 shell,某些发行版可能不使用 bash 作为默认 shell。

视频演示了如何在 Archlinux 上手动设置环境变量

/etc/profile

如果您不关心使用 root 修改文件,这是最好的选择。所有发行版通常都支持此文件。您需要附加到 /etc/profile 末尾的代码片段与 登录shell配置文件 相同。

~/.xprofile

如果您使用 X11 和显示管理器,这是一个古老的完美选择。但 Wayland 没有对应的环境变量,因此如果要为 Wayland 设置环境变量并不理想。您要添加的代码与登录shell配置文件 相同。

environment.d

这是 system.d 引入的新配置,但并未得到桌面环境或显示管理器支持的广泛使用。它基本上是 systemd 用户单元的环境配置。目前,仅 GDM 或 Plasma 5.22+ 支持。作为 GDM,这意味着使用 GDM 登录的任何会话都可以工作。至于 Plasma,这意味着无论您使用什么 DM,它都适用于 Plasma。

此配置将在您首次用户会话登录时应用,并在之后持续存在,除非您手动停止 systemd 用户。因此,修改此配置后,使其生效的最简单方法是重新启动系统。

语法与 shell 类似,但不需要 export。例如,您可以创建一个包含以下内容的文件 ~/.config/environment.d/im.conf

XMODIFIERS=@im=fcitx
GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx

pam_env.so

This is an obsolete solution for following reasons:

  • pam deprecate user level configuration ~/.pam_environment since 1.5.0.
  • Some distribution does not enable pam_env in their pam configuration.

If you know it works for your system, you can put following snippet to your ~/.pam_environment.

XMODIFIERS DEFAULT=\@im=fcitx
GTK_IM_MODULE DEFAULT=fcitx
QT_IM_MODULE DEFAULT=fcitx.

Please NOTE that the syntax is different from shell script.

~/.config/plasma-workspace/env/*.sh

A env script location that only works for Plasma desktop, you need to create your own .sh file, e.g. ~/.config/plasma-workspace/env/im.sh and put the code snippet same as login shell.

Other less common setup

There are some other variable that might be useful certain applications.

SDL_IM_MODULE

Set the value to fcitx. Only SDL2 requires this. SDL1 uses XIM.

GLFW_IM_MODULE

This is a variable only used by kitty. You need to set it to `GLFW_IM_MODULE=ibus`.

Binary Qt application

Due to Qt 5 does not support XIM, and it only bundles ibus im module, you may want to set `QT_IM_MODULE=ibus` for Qt application that does not use your system Qt library. (It may still not work because certain Qt application does not even bundle any im module).

DBus

On most distribution that ships with systemd, this should no longer be an issue. But if you are using some so called "systemd" free distribution, you may need to start DBus yourself and set the relevant environment variables. Usually, this can be done by adding a line in like this in your start up script. E.g. ~/.xprofile if you are using X11. Also you need to make sure this syntax works for your login shell.

eval `dbus-launch --sh-syntax --exit-with-session`

Configure Fcitx 5

See Configtool (Fcitx 5).