Gentoo Linux KDE fcitx中文输入

我在 Gentoo Linux Sway fcitx中文输入 环境中折腾了很久中文输入,最终解决了 80% 的问题,勉强可用:

  • 仓库中没有提供 kcm-fcitx ,这个组件之前是作为集成到KDE环境的Setting中来生成fcitx配置文件的工具,但是现在看来已经废弃了(KDE5中不再需要)

  • 我推测 gentoo-zh Gentoo Overlays 核心组件是能够工作的,但是没有提供很好的配置集成工具(我不确定完整安装 Gentoo KDEkde-plasma/plasma-meta 软件包是否提供设置方法。我为了能够尽快修复掉Gentoo Linux中文输入(已经停滞在这个中文输入问题上一周时间),所以采用了 Gentoo 虚拟化 来运行 Fedora 虚拟机KDE环境,快速完成 小企鹅输入法fcitx 配置之后,再将配置文件复制到Gentoo环境中使用

  • 通过 Fedora 提供的fcitx配置文件,就能够完成(本文) Gentoo KDE 中文输入

  • 也验证了 Gentoo Linux KDE fcitx中文输入 的fcitx配置可以用于 Gentoo Linux Sway fcitx中文输入 环境(无修改),差异是在 sway - i3兼容Wayland compositor 中终端程序 foot/alacritty 无法显示中文候选词窗口(KDE环境无此问题)。

备注

这次折腾我 基本 找到了Gentoo环境的 小企鹅输入法fcitx 中文输入配置方法,虽然还有一些不足,但是基本可用。我准备在下次(大约一个月后)重新 在MacBook Pro上安装Gentoo Linux 时再次验证和修订手册:

  • 备份和恢复本次实践通过 Fedora KDE环境生成的 小企鹅输入法fcitx 配置文件,以绕开Gentoo环境没有合适的配置工具问题

    • 无需安装KDE环境来运行配置工具,可以大幅减少安装编译的投入

  • 仅安装核心 fcitx / fcitx-qt / fcitx-gtk / fcitx-rime 应该就能够满足中文输入需求

备注

fcitx开发wengxt的博客 Use Plasma 5.24 to type in Alacritty (Or any other text-input-v3 client) with Fcitx 5 on Wayland 解释了 wayland显示服务器协议 引擎Plasma(KDE)环境经下支持 text-input-v3 的客户端,如 GPU加速终端模拟器alacritty 使用fcitx的原理:

Fcitx5的Wayland IM Frontend通过KWin Wayland发送输入给使用 text-input-v3 可以实现非常完美的输入候选词窗口显示

输入引擎

fcitx内置了非常简单的拼音输入法,所以通常会安装第三方输入法引擎:

总之,第三方输入法的开发不是很活跃, 可能 需要先自己构建 Gentoo ebuild repository (自己定制ebuild) 以便通过 Gentoo版本指定器 指定 SLOT 5 进行安装。我在 Gentoo ebuild repository 完整记录了如何针对 fcitx5 安装 fcitx-rime

经过简单对比,我最终采用Gentoo wiki中中文输入文档推荐的 fcitx-rime 输入法

备注

rime 输入法默认是繁体中文输入,调整方法是按下 F4 或者组合键 Ctrl+` ,就能看到输入选项,选择简体中文即可。 ( GitHub: rime/wiki UserGuide )

USE flags

经过反复折腾,参考 gentoo+sway无法在WPS、foot、dingtalk应用中显示输入法候选窗口 #455

  • 尽可能不启用X支持,但是gtk,qt,sway似乎都需要X的支持才能使用fcitx输入中文,所以配置了如下组件X支持 /etc/portage/package.use/X :

/etc/portage/package.use/X
x11-libs/cairo X aqua
x11-libs/pango X
x11-libs/gtk+ X
dev-cpp/gtkmm X
dev-cpp/cairomm X
media-libs/libepoxy X
x11-libs/libxkbcommon X
media-libs/mesa X
dev-qt/qtgui egl
  • 安装KDE,配置 /etc/portage/package.use/kde :

/etc/portage/package.use/kde
kde-frameworks/kwindowsystem X
app-text/xmlto text
kde-frameworks/sonnet qml
app-crypt/qca qt5
media-video/vlc ogg
dev-qt/qtgui jpeg X accessibility
kde-frameworks/prison qml
kde-frameworks/kconfig qml
kde-frameworks/kitemmodels qml
dev-qt/qtcore icu

#启用webengine会安装大量依赖,目前采用firefox作为浏览器,且kde支持集成firefox和chrome
#kde-plasma/kdeplasma-addons share webengine
kde-plasma/kdeplasma-addons share
  • 配置 fcitx 启用X支持:

/etc/portage/package.use/fcitx
app-i18n/fcitx X
app-i18n/fcitx-gtk gtk4
app-i18n/fcitx-chinese-addons cloudpinyin qt5
app-i18n/fcitx-qt qt5 X
app-i18n/fcitx-configtool config-qt

使用 gentoo-zh Gentoo Overlays 仓库

实在难以解决,不想再折腾中文输入,改为参考 SWAY配置中文输入法 使用 gentoo-zh Gentoo Overlays 仓库

备注

详细折腾请参考 Bug 760501 - app-i18n/fcitx-5 version bump 在一些非常用软件维护上,Gentoo使用不如 Arch Linux

卸载之前已经安装的 SLOT 5fcitx
emerge -acv app-i18n/fcitx:5
emerge -avuDN @world
emerge --depclean
  • 激活 gentoo-zh 仓库:

激活 gentoo-zh 仓库
eselect repository enable gentoo-zh

安装步骤参考了 Gentoo 教程:系统完善

  • 使用 emaint 对新添加Portage进行软件库同步:

使用 emaint 同步新添加的软件库
emaint sync -r gentoo-zh
  • 配置 /etc/portage/package.accept_keywords/fcitx5 :

配置 /etc/portage/package.accept_keywords/fcitx5
#直接使用 /etc/portage/package.accept_keywords
#echo "net-wireless/broadcom-sta" >> /etc/portage/package.accept_keywords

#或者 /etc/portage/package.accept_keywords 目录下分别配置针对不同应用的配置
#这里举例为fcitx5配置 /etc/portage/package.accept_keywords/fcitx5
#注意 zh-gentoo 提供的fcitx5软件包命名是 fcitx
app-i18n/fcitx ~amd64
x11-libs/xcb-imdkit ~amd64
# 去除安装fcitx-chinese-addons,仅安装fcitx-rime来支持拼音输入引擎`
#app-i18n/fcitx-chinese-addons ~amd64
app-i18n/fcitx-rime ~amd64
app-i18n/rime-data ~amd64
app-i18n/rime-octagram-data ~amd64

# librime-octagram-20230125-r2 需要 sys-libs/libunwind 1.8.0
sys-libs/libunwind ~amd64
app-i18n/librime-octagram ~amd64
app-i18n/libime ~amd64

#在 sway 环境不再安装qt支持,采用纯gtk环境(如果要支持KDE,则启用qt支持)
#app-i18n/fcitx-qt ~amd64
#app-i18n/fcitx-configtool ~amd64
#dev-qt/qtcore ~amd64
app-i18n/fcitx-gtk ~amd64

# dev-libs/boost-1.84.0 required by fcitx-chinese-addons (~amd64)
# 不过可以不安装fcitx-chinese-addons就需要配置下面这行
#dev-libs/boost ~amd64
  • 执行安装: 采用 gentoo-zh Gentoo Overlays 安装源安装以下组件(下次再尝试精简,是否只需要安装 fcitxfcitx-rime ?):

安装overlay的fcitx5(实际调正安装了更多软件包)
emerge boost

# 注意,安装包名就是 fcitx fcitx-qt fcitx-gtk ,可以看到软件包版本能够限制最新版本 5.x ,不需要指定SLOT , gentoo-zh 的overlay版本比官方高,默认安装就可以
# 通过 emerge -s fcitx5-gtk 这样的命令查找出包名,然后就能一一安装
# xcb-imdkit fcitx5 kcm-fcitx5 fcitx5-qt fcitx5-chinese-addons libime fcitx5-gtk

#emerge --ask x11-libs/xcb-imdkit \
#             app-i18n/fcitx \
#             app-i18n/kcm-fcitx \
#             app-i18n/fcitx-qt \
#             app-i18n/fcitx-chinese-addons \
#             app-i18n/libime \
#             app-i18n/fcitx-gtk

# 说明:
# kcm-fcitx 是用于KDE的配置模块
# xcb-imdkit 是支持xcb的输入模式
# fcitx-chinese-addons 需要 qt5支持(我暂时去掉)

emerge --ask app-i18n/fcitx \
             app-i18n/fcitx-gtk
安装 fcitx 组件(针对KDE安装)
emerge --ask app-i18n/fcitx app-i18n/fcitx-chinese-addons \
    app-i18n/fcitx-gtk app-i18n/fcitx-qt app-i18n/fcitx-rime

安装输出信息(依赖安装包)

安装overlay的fcitx5输出信息
[ebuild  N     ] kde-frameworks/extra-cmake-modules-5.113.0  USE="-doc -test"
[ebuild  N     ] app-text/iso-codes-4.15.0
[ebuild  N     ] app-i18n/fcitx-5.1.5  USE="autostart emoji enchant keyboard server wayland -X -doc -presage -systemd -test"
[ebuild  N     ] media-libs/graphene-1.10.8  USE="introspection -doc -test" CPU_FLAGS_X86="sse2"
[ebuild  N     ] gui-libs/gtk-4.12.4  USE="introspection wayland -X (-aqua) -broadway -cloudproviders -colord -cups -examples (-ffmpeg) -gstreamer -sysprof -test (-vulkan)" CPU_FLAGS_X86="f16c"
[ebuild  N     ] app-i18n/fcitx-gtk-5.1.0  USE="gtk3 gtk4 introspection snooper wayland -X -gtk2 -onlyplugin"

由于多次调整USE flag,所以可能需要执行:

在修改了 USE flag 之后对整个系统进行更新
emerge --ask --changed-use --deep @world

配置fcitx

Fedora

在Gentoo Linux环境下我解决不了配置工具安装,所以采用 Gentoo 虚拟化 运行 Fedora 虚拟机来配置 小企鹅输入法fcitx ,大致步骤按照官方文档:

  • Fedora 中安装 fcitx5-autostart 软件包配合 fcitx 就能自动启动和设置好 fcitx5 运行环境

  • 安装核心组件 fcitx5 fcitx5-gtk fcitx5-qt fcitx5-rime :

在Fedora中安装fcitx
dnf install fcitx5 fcitx5-gtk fcitx5-qt \
    fcitx5-configtool fcitx5-rime
  • 在Fedora中配置fcitx不需要使用 im-chooser ,只需要安装好 fcitx5-autostart 就能够在登录KDE时候自动启动 fcitx

  • 在Fedora中,启动 System Settings 点击 Input Devices 然后点击 Virtual Keyboard ,选择 Fcitx5 然后点击 Apply 。这样就将Fcitx5设置为虚拟键盘

  • Regional 设置中,选择 Input Method ,然后点击 Add Input Method ,选择 rime 作为输入法,并保存。这样重新登录以后,就会看到RIME输入法是可选的,通过 ctrl+space 可以切换

以上就是Fedora中配置,完成后将 ~/.config/fcitx5 目录复制到 Gentoo Linux Sway fcitx中文输入 的工作环境中就可以绕开Gentoo平台没有合适的配置工具的问题

Gentoo

  • 配置 ~/.bashrc :

~/.bashrc 配置环境变量
export MOZ_DBUS_REMOTE=1
export GTK_USE_PORTAL=0
export XMODIFIERS=@im=fcitx

# Enable Wayland support for Mozilla Firefox
export MOZ_ENABLE_WAYLAND=1

备注

在KDE环境中使用 fcitx 不需要配置 QT_IM_MODULEGTK_IM_MODULESDL_IM_MODULE 环境变量,虽然我配置了以后没有看出使用有什么不同。不过登录KDE环境时会提示不要设置这两个参数,所以我还是取消了。请参考 Using Fcitx 5 on Wayland >> KDE Plasma

参考