Gentoo Linux Sway fcitx中文输入

警告

由于我在 Gentoo + Sway + fcitx 上折腾了一周多时间,所以本文记录比较混乱,包含我的多次探索记录。我准备在后续重新完成一次部署,预计在重新 在MacBook Pro上安装Gentoo Linux 之后再次部署,撰写修订笔记。待完成…

备注

sway基于 wayland显示服务器协议 native程序,中文输入法选择 小企鹅输入法fcitx ,实践中有很多坑和挫折,远比

困难很多

Gentoo Linux在主流软件上非常稳健,但是实验性软件(非主流)则不如 Arch LinuxUbuntu Linux 发行版。可能主要原因是使用者、维护者相对少一些,也缺乏商业支持。

不过,通过折腾Gentoo Linux,所有的报错和底层排障都会加深你对系统的认知,也提高你的解决能力。得失之间,需要你自己把控。

版本选择

默认的仓库提供的fcitx版本比较古早,是fcitx4系列稳定版本,而fcitx5.x则需要指定版本:

安装fcitx(归档)

我选择 小企鹅输入法fcitx 以及比较轻巧的中州输入法:

安装fcitx输入法以及中州输入
emerge --ask app-i18n/fcitx app-i18n/fcitx-rime

备注

默认稳定版本还是 fcitx4 ,要激活使用最新的 fcitx5 需要允许

备注

默认 fcitx 的 USE flags 包含了 cairo (2D图形库,支持多种输出如X Window,Quartz,PostScript,PDF,SVG等) 和 pango (gnome的文本布局和渲染库) ,我暂时取消掉

安装fcitx5

备注

参考 gentoo linux wiki: Fcitx 建议应用程序编译 Gentoo Linux USE Flags 启用 gtk2 或者 gtk3

通过指定 :5 SLOT来安装 fcitx5
emerge --ask app-i18n/fcitx:5

备注

对于非稳定版本, 需要在 /etc/portage/make.conf 中添加 ACCEPT_KEYWORDS=”~amd64” (不建议全局添加 ACCEPT_KEYWORDS="~amd64" )采用在 /etc/portage/packages.use 针对特定软件包添加USE关键字 ~amd64

安装输入引擎

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

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

备注

已改变策略 实际我现在选择 fcitx-rime

由于安装第三方输入法涉及到大量的依赖库,并且第三方输入法开发不活跃,所以目前我考虑先使用 fcitx5 内置拼音输入法。如有必要再尝试 fcitx-libpinyinfcitx-rime

配置fcitx

  • 配置 /etc/environment :

启用fcitx5环境变量配置 /etc/environment
GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
INPUT_METHOD=fcitx
SDL_IM_MODULE=fcitx
GLFW_IM_MODULE=ibus

备注

根据fcitx官方文档,当没有激活gtk/gtk3以及qt USE flag时,需要将对应配置行修订成 xim

export GTK_IM_MODULE=xim
export QT_IM_MODULE=xim
  • 在个人配置定制文件 ~/.config/sway/config 中添加一行:

在 ~/.config/sway/config 中添加运行 fcitx5 的配置
#以下两种方法可能都行
#exec_always fcitx5 -d --replace
exec_always --no-startup-id  fcitx5 -d

异常排查

fcitx5的 Gentoo D-Bus 相关报错

再次进入 sway 之后,通过 ps 命令检查可以看到 fcitx5 进程已经启动,不过没有看到有托盘图标(应该是我还没有安装托盘组件),但是遇到一个问题,按下 ctrl+space 没有看到浮现中文输入框

我改为终端运行 fcitx5 (杀掉后台进程,直接在终端执行 fcitx5 ) ,看到 fcitx5 运行的终端显示报错信息似乎与 Gentoo D-Bus 有关:

控制台fcitx5启动时 Gentoo D-Bus 相关错误
I2024-01-07 08:41:07.756092 instance.cpp:1323] Override Enabled Addons: {}
I2024-01-07 08:41:07.756168 instance.cpp:1324] Override Disabled Addons: {}
I2024-01-07 08:41:07.758339 addonmanager.cpp:193] Loaded addon imselector
I2024-01-07 08:41:07.760053 addonmanager.cpp:193] Loaded addon quickphrase
I2024-01-07 08:41:07.766443 addonmanager.cpp:193] Loaded addon keyboard
E2024-01-07 08:41:07.766856 addonloader.cpp:61] Failed to create addon: dbus Failed to connect to session dbus
I2024-01-07 08:41:07.766908 addonmanager.cpp:189] Could not load addon dbus
I2024-01-07 08:41:07.805878 inputmethodmanager.cpp:198] Found 737 input method(s) in addon keyboard
I2024-01-07 08:41:07.807832 addonmanager.cpp:193] Loaded addon wayland
I2024-01-07 08:41:07.808087 addonmanager.cpp:193] Loaded addon clipboard
I2024-01-07 08:41:07.808354 addonmanager.cpp:193] Loaded addon waylandim
I2024-01-07 08:41:07.808533 addonmanager.cpp:193] Loaded addon unicode
I2024-01-07 08:41:07.831016 classicui.cpp:96] Created classicui for wayland display:
I2024-01-07 08:41:07.831092 addonmanager.cpp:193] Loaded addon classicui

我调整 Gentoo D-Bus/etc/portage/make.conf 添加:

全局激活 dbus
USE="dbus"

使用 --changed-use 选项确保更新整个系统

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

完成后检查,发现 fcitx5 运行报错依旧,这是窗口管理器 D-Bus session bus 没有创建,仔细看了 Gentoo Sway 文档,原来 sway 需要通过shell脚本包装 XDG_RUNTIME_DIR 变量,并且使用 dbus-run-session 命令来启动(方法一) 或者 采用 elogind 加入到启动服务中(来完成环境变量设置),然后使用 dbus-run-session (方法二),这样才能实现 D-Bus session bus (详见 在Gentoo环境安装和使用Sway ):

我采用方法一 :

安装 sys-auth/seatd 并且配置用户 huatai 到对应组,以及启动服务:

安装和配置 seatdseat USE flag必须添加 serverbuiltin
emerge --ask sys-auth/seatd

# 针对OpenRC配置
gpasswd -a huatai video
gpasswd -a huatai seat
rc-update add seatd default
rc-service seatd start

为用户 huatai 配置 ~/.bashrc 添加如下内容设置用户环境变量:

配置用户环境变量 ~/.bashrc
export XDG_RUNTIME_DIR="/tmp/user/"`id -u`
if [ ! -d $XDG_RUNTIME_DIR ]; then
    mkdir -p $XDG_RUNTIME_DIR
    chmod 0700 $XDG_RUNTIME_DIR
fi

最后使用 dbus-run-session 来启动 sway :

使用 dbus-run-session 启动 sway 这样能够正确获得 D-Bus session bus
dbus-run-session sway

再次前台运行 fcitx5 可以看到连接成功,但是出现了新的关于DBus调用错误:

控制台fcitx5启动时 DBus调用错误
I2024-01-07 19:30:51.112663 instance.cpp:1323] Override Enabled Addons: {}
I2024-01-07 19:30:51.112783 instance.cpp:1324] Override Disabled Addons: {}
I2024-01-07 19:30:51.115008 addonmanager.cpp:193] Loaded addon imselector
I2024-01-07 19:30:51.117186 addonmanager.cpp:193] Loaded addon quickphrase
I2024-01-07 19:30:51.124208 addonmanager.cpp:193] Loaded addon keyboard
I2024-01-07 19:30:51.126275 addonmanager.cpp:193] Loaded addon dbus
I2024-01-07 19:30:51.127291 addonmanager.cpp:193] Loaded addon dbusfrontend
I2024-01-07 19:30:51.130361 addonmanager.cpp:193] Loaded addon fcitx4frontend
I2024-01-07 19:30:51.132095 addonmanager.cpp:193] Loaded addon ibusfrontend
I2024-01-07 19:30:51.134235 addonmanager.cpp:193] Loaded addon wayland
I2024-01-07 19:30:51.134630 addonmanager.cpp:193] Loaded addon clipboard
I2024-01-07 19:30:51.134987 addonmanager.cpp:193] Loaded addon waylandim
I2024-01-07 19:30:51.135241 addonmanager.cpp:193] Loaded addon unicode
I2024-01-07 19:30:51.177208 inputmethodmanager.cpp:198] Found 737 input method(s) in addon keyboard
I2024-01-07 19:30:51.178170 addonmanager.cpp:193] Loaded addon kimpanel
I2024-01-07 19:30:51.178647 addonmanager.cpp:193] Loaded addon virtualkeyboard
I2024-01-07 19:30:51.199065 classicui.cpp:96] Created classicui for wayland display:
I2024-01-07 19:30:51.199120 addonmanager.cpp:193] Loaded addon classicui
I2024-01-07 19:30:51.199714 addonmanager.cpp:193] Loaded addon notificationitem
I2024-01-07 19:30:51.200465 addonmanager.cpp:193] Loaded addon notifications
I2024-01-07 19:30:51.200674 kimpanel.cpp:116] Kimpanel new owner:
I2024-01-07 19:30:51.200722 virtualkeyboard.cpp:223] VirtualKeyboard new owner:
E2024-01-07 19:30:51.200770 portalsettingmonitor.cpp:115] DBus call error: org.freedesktop.DBus.Error.ServiceUnknown The name org.freedesktop.portal.Desktop was not provided by any .service files

参考 [Bug]: The name org.freedesktop.portal.Desktop was not provided by any .service files #5201 : 需要安装 xdg-desktop-portal 已经和特定桌面环境相关的后端软件,例如GNOME Shell 需要安装 xdg-desktop-portal-gnome , KDE Plasma需要安装 xdg-desktop-portal-kde ,对于gtk环境则安装 xdg-desktop-portal-gtk 等。这个软件包是 Flatpak 开发的,已经用于很多应用软件,如gimp, firefox, slack 等。:

  • 安装 xdg-desktop-portal :

安装 xdg-desktop-portal
emerge --ask sys-apps/xdg-desktop-portal
安装面向 wayland显示服务器协议xdg-desktop-portal-wlr
emerge --ask gui-libs/xdg-desktop-portal-wlr

还是没有解决 控制台fcitx5启动时 DBus调用错误 仔细看了报错信息:

portalsettingmonitor.cpp:115] DBus call error: org.freedesktop.DBus.Error.ServiceUnknown The name org.freedesktop.portal.Desktop was not provided by any .service files

看来这个配置确实缺乏,暂无头绪

这个报错信息看起来是获取 Desktop 名字的,但是 xdg-desktop-portal-wlr 似乎没有提供? 但是我突然注意到 Gentoo xdg-desktop-portal 安装了 xdg-desktop-portal-wlr 默认配置 /usr/share/xdg-desktop-portal/sway-portals.conf

/usr/share/xdg-desktop-portal/sway-portals.conf
[preferred]
# Use xdg-desktop-portal-gtk for every portal interface...
default=gtk
# ... except for the ScreenCast and Screenshot
org.freedesktop.impl.portal.ScreenCast=wlr
org.freedesktop.impl.portal.Screenshot=wlr
# 下面这行是我参考 https://wiki.gentoo.org/wiki/Xdg-desktop-portal#Configuration
# 因为fcitx5启动时检查 org.freedesktop.portal.Settings ,不过加了也没用,貌似检查的是其他节点
org.freedesktop.impl.portal.Settings=darkman

原来 xdg-desktop-portal-wlr 默认依赖 xdg-desktop-portal-gtk 来提供 interface ,所以必须得安装

xdg-desktop-portal-wlr 默认使用 xdg-desktop-portal-gtk 提供portal接口,所以同时安装 sys-apps/xdg-desktop-portal-gtk
emerge --ask sys-apps/xdg-desktop-portal-gtk

警告

还是没有解决 fcitx5 调用 DBus 的报错,😷

警告

文档中每一句话都可能隐藏深意 每一句话可能都是关键

官方文档中提到 Important :

Starting Sway with dbus requires that XDG_RUNTIME_DIR is set. elogind or systemd will set this if used.

Omitting the dbus-run-session may cause runtime errors.

备注

其他启用 D-Bus session bus 方法可以使用 dbus-launch (这个命令可以在shell环境中以session bus方式运行程序)

例如 Sway 下到底怎么用输入法?

dbus-launch --exit-with-session sway

“条条大路通罗马” 这也是确保 DBUS_SESSION_BUS_ADDRESS 方法,在 Gentoo D-Bus 官网文档 gentoo wiki: D-Bus : 为确保 X 或 Wayland 会话中具备了 D-Bus session,则可以通过 dbus-launch 来启动窗口管理器(例如 i3窗口管理器 , bspwm 等)

使用 dbus-launch 来加载窗口管理器,确保窗口管理器会话支持 session bus
exec dbus-launch --exit-with-session i3

另外 医学生折腾Gentoo Linux记 (有不少注意点)提到使用以下方法(这个方法是 archlinux wiki: Fcitx5 文档中记录的)

exec --no-startup-id fcitx5 -d

一点疑惑

Gentoo D-Bus 是重要的功能,在 fcitx 的官方文档中说明fcitx和im模块之间是通过 dbus 通讯。所以我推测 fcitx-rime 输入法和 fcitx 之间还是需要 dbus 来通讯的,并且我看到默认启动的 fcitx 进程显示:

/usr/bin/fcitx-dbus-watcher unix:path=/tmp/dbus-TPoXVu8TM0,guid=140f65b1a3552b97ddd7e9cd6505a51b 617

Gentoo Chromium 一样,默认启动了一个 dbus socket文件,这个应该有功能影响

警告

我在2024年1月的实践中,采用了上述指定 SLOT 5 方式安装了 fcitx5 ,但是发现一个问题,没有配套的软件包可以安装,例如,没有 fcitx5-data ,也没有 xcb-imkit ,我对比了以下 Fedora操作系统镜像 中 Fedora Sway (以LiveCD方式运行),安装 fcitx5 时候会配套安装相应组件:

Fedora Sway安装fctix5
===============================================================================================================================
 Package                                      Architecture          Version                       Repository              Size
===============================================================================================================================
Installing:
 fcitx5                                       x86_64                5.1.5-1.fc39                  updates                1.3 M
Installing dependencies:
 fcitx5-data                                  noarch                5.1.5-1.fc39                  updates                6.7 M
 fcitx5-gtk3                                  x86_64                5.1.0-1.fc39                  fedora                  53 k
 fcitx5-gtk4                                  x86_64                5.1.0-1.fc39                  fedora                  52 k
 fcitx5-libs                                  x86_64                5.1.5-1.fc39                  updates                604 k
 fcitx5-qt-libfcitx5qt5widgets                x86_64                5.1.3-1.fc39                  updates                 55 k
 fcitx5-qt-libfcitx5qtdbus                    x86_64                5.1.3-1.fc39                  updates                 98 k
 fcitx5-qt-module                             x86_64                5.1.3-1.fc39                  updates                105 k
 kf5-kitemviews                               x86_64                5.110.0-1.fc39                fedora                 150 k
 kf5-kwidgetsaddons                           x86_64                5.110.0-1.fc39                fedora                 1.6 M
 xcb-imdkit                                   x86_64                1.0.5-2.fc39                  fedora                 330 k
Installing weak dependencies:
 fcitx5-configtool                            x86_64                5.1.2-1.fc39                  updates                254 k
 fcitx5-gtk                                   x86_64                5.1.0-1.fc39                  fedora                  35 k
 fcitx5-qt                                    x86_64                5.1.3-1.fc39                  updates                 92 k

Transaction Summary
===============================================================================================================================
Install  14 Packages

Total download size: 11 M
Installed size: 27 M

参考 SWAY配置中文输入法 提到的使用 gentoo-zh 社区overlay仓库,其中也依赖安装 x11-libs/xcb-imdkitapp-i18n/libime 等包

使用 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
  • 执行安装:

安装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

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

安装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"

Error with fcitx5-config-qt

could’nt found fcitx5-config-qt
You're currently running Fcitx with GUI, but fcitx5-config-qt couldn't be found. Now it will open config directory.
Cannot find a command to run.

refer 安装fcitx5-chinese-addons遇到的问题 #512 :

  • fcitx5 need KDE to run fcitx5-config-qt , else must use kcm-fcitx to config; I have try install kcm-fcitx but it not include in gentoo-zh overlay, so failed

  • kcmshell5 fcitx5 maybe from kcm-fcitx5 package?

解决线索

使用 gentoo-zh Gentoo Overlays 确实可以安装更多相关软件包, 但是目前我还没有解决输入法唤起,所以还没有解决输入问题。 ,我最终通过了一些曲线方法来完成配置,见下文 最终解决

仔细看了一下 目前大家是怎样在 wayland 中使用中文输入法的? (原帖是针对 Arch Linux ),发现还有一些底层原理需要学习(可能解决的线索):

原帖问题有关 can not show up input interface on arch linux sway wm #39

q234rty 提到: sway 下对于 wayland native 的程序来说,有两种可能

  • 通过 GTK_IM_MODULE/QT_IM_MODULE,目前来说不需要特殊配置,只需要设置环境变量就能工作。注意 chromium 对此的支持有一定问题(electron 则暂时不支持),见 Chrome/Chromium 今日 Wayland 输入法支持现状

  • 通过 wayland 的 text_input/input_method 系列协议,需要 Implement input_method_v2 popups #5890 ,目前 archlinuxcn 有 sway-im 这个包提供打上此补丁的 sway,另 aur 也有 sway-im-git 。目前来说 sway 下只有支持 text-input-v3 的程序(包括绝大部分 gtk 3/4 程序(这里同样不包括 chromium/electron)和一部分终端模拟器,如 kitty/foot)能通过这个方法进行输入。 <= 这里是重点

参考 can not show up input interface on arch linux sway wm #39 :

  • maybe use Xwayland application can use input method

  • compositor <-> application is using text_input (v1 v2 v3…)

  • compositor <-> input method is using input method (v1 v2): v1 is included in wayland-protocols, and there is also input method v2 which contributed by prism inc, but fcitx don’t support that yet

  • sway is using the v2 so fcitx can’t yet work with it, also since v2 remove the input panel positioning part, fcitx developer don’t yet know where to move the input method window with the protocol.

and say:

environment for sway (but my try is failed)
export MOZ_ENABLE_WAYLAND=1
export XDG_SESSION_TYPE=wayland
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"

then exec --no-startup-id fcitx5 -d in sway config, and enable wayland in fcitx5-configtool

Now fcitx is support sway : gentoo+sway无法在WPS、foot、dingtalk应用中显示输入法候选窗口 #455 :

最终解决方法

最终我采用了一个取巧的方法:

  • 完成 Gentoo Linux KDE fcitx中文输入 ,将能够正确用于KDE环境的fcitx配置文件同样用于sway环境

  • 经过验证,确认基本无需调整就能正常工作,唯一的缺点是 foot 等终端无法显示输入候选词窗口。这个问题的解决看来需要使用 Arch Linux 的一个 sway-im 补丁来解决,我尚未实践

KDE

Gentoo KDE 提供了交互配置工具运行的环境,所以我尝试先安装KDE基本运行环境:

kde-plasma/plasma-desktop
emerge --ask kde-plasma/plasma-desktop

当运行 fcitx5-configtool 提示以下错误 :

run fcitx5-configtool in kde, error
You're currently running KDE, but KCModule for fcitx couldn't be found, the package name of this KCModule is usually kcm-fcitx or kde-config-fcitx. Now it will open config directory.
kf.service.services: KApplicationTrader: mimeType "x-scheme-handler/file" not found

kcm-fcitx 是一个和KDE高度集成的配置工具, kcm 意思是 KDE configuration module , 在安装了 kcm-fcitx 之后, 可以在KDE谁知中看到 Input Method 配置:

但是 kcm-fcitx CMake ( either in relase 0.5.6 , or in git version ) 报错:

kcm-fcitx CMake errors
CMake Error at CMakeLists.txt:24 (find_package):
  By not providing "FindFcitxQt5DBusAddons.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "FcitxQt5DBusAddons", but CMake did not find one.

  Could not find a package configuration file provided by
  "FcitxQt5DBusAddons" (requested version 1.1.0) with any of the following
  names:

    FcitxQt5DBusAddonsConfig.cmake
    fcitxqt5dbusaddons-config.cmake

  Add the installation prefix of "FcitxQt5DBusAddons" to CMAKE_PREFIX_PATH or
  set "FcitxQt5DBusAddons_DIR" to a directory containing one of the above
  files.  If "FcitxQt5DBusAddons" provides a separate development package or
  SDK, be sure it has been installed.

fcitx5-qt 源代码中, qt5/dbusaddons/Fcitx5Qt5DBusAddonsConfig.cmake.in 提供了这个cmake配置。

警告

我最终没有解决这个编译问题,似乎是 kcm-fcitx 长时间不活跃开发,已经无法在最新的KDE环境编译。所以我采用了上文所述的取巧方法,在一个运行KDE的虚拟机中生成配置文件复制到 sway 环境使用。验证是可行的。

编译 librime-octagram 依赖报错处理

2024年1月 升级Gentoo 遇到 librime-octagram 依赖编译报错:

编译 app-i18n/librime-octagram 报错
...
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Unwind: Found unsuitable version "1.7.2", but required is at
  least "1.8.0" (found /usr/include)
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:598 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/glog/cmake/FindUnwind.cmake:42 (find_package_handle_standard_args)
  /usr/share/cmake/Modules/CMakeFindDependencyMacro.cmake:76 (find_package)
  /usr/lib64/cmake/glog/glog-config.cmake:35 (find_dependency)
  tools/CMakeLists.txt:15 (find_package)


-- Configuring incomplete, errors occurred!
 * ERROR: app-i18n/librime-octagram-20230125-r2::gentoo-zh failed (configure phase):
 *   cmake failed
 * 
 * Call stack:
 *     ebuild.sh, line  136:  Called src_configure
 *   environment, line 2095:  Called cmake_src_configure
 *   environment, line 1003:  Called die
 * The specific snippet of code:
 *       "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed";
 * 
...

搜索关键字 1.7.2 以排查 Gentoo Linux Sway fcitx中文输入 报错的软件包版本:

检查系统已经安装的软件包版本包含 1.7.2 版本信息
equery list "*" | grep 1.7.2

输出显示:

检查系统已经安装的软件包版本包含 1.7.2 版本信息输出内容
app-text/hunspell-1.7.2
gui-apps/swaylock-1.7.2
sys-libs/libunwind-1.7.2
  • 配置 /etc/portage/package.accept_keywords/fcitx5 添加对应 ~amd64 :

配置 /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

chromium

对于chromium/Electron,如果使用原生wayland,在需要向 chromium 传递参数 --enable-wayland-ime :

在原生Wayland环境,chromium支持fcitx中文输入需要传递 --enable-wayland-ime 参数
chromium --enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime

奇怪,究竟 unwind 版本 1.7.2 不符合 1.8.0 要求是哪个软件包?

通过 Gentoo emerge 方法 equery 查询:

检查系统已经安装的软件包版本包含 1.7.2 版本信息输出内容
app-text/hunspell-1.7.2
gui-apps/swaylock-1.7.2
sys-libs/libunwind-1.7.2

通过 | grep 1.7.2 可以找到 sys-libs/libunwind-1.7.2 ,也就是需要添加 sys-libs/libunwind~amd64 unstable标记来安装必要的对应 1.8.0 版本

参考