[software development] 为大部分无法使用输入法的Qt based应用添加Fcitx插件支持
Tofloor
poster avatar
Ziggy
deepin
2023-12-19 22:25
Author

背景

近期受到不少关于应用中无法调用输入法/输入中文的反馈,在论坛逛了一圈,发现似乎大家都一致确定了是某些应用维护者在封装的时候并没有把Qt的fcitx plugins随其他libs封装到容器内,导致应用在加载容器内的Qt之后无法索引到正确的plugin导致基于fcitx输入法无法被启动.

定位

既然有了大概的可能原因,那就先一步步验证猜测吧hhh.

确认影响库

这里感谢@北冥夜未央 的文章,初步确认了是libfcitxplatforminputcontextplugin.so这个库缺失导致的问题.然后根据"apt-file search"功能找到了"fcitx-frontend-qt5"这个包

ziggy@ziggy-PC:/$ apt-file search libfcitxplatforminputcontextplugin.so
fcitx-frontend-qt5: /usr/lib/x86_64-linux-gnu/qt5/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so

从"/usr/lib/x86_64-linux-gnu/qt5/plugins"这个路径可以看出,这个库属于Qt的plugins之一

逐级排查

查看appimage等预封装的Qt based应用中包含的Qt plugins

既然确定了是Qt plugin,常理来说fcitx这种输入法框架的插件应该算是比较基础化的组成部分了,
拆开一个Qt based应用-Keepassxc的appimage包,可以看到里面有Qt的plugins目录,也有platforminputcontexts关于输入法框架插件的目录,但是里面居然只有ibus的库,缺失了fcitx的库。

 zijie@XPS  /media/zijie/Data/deb_package/uploaded/src/sz_libs/others/keepassxc/2.6.6+szbt1/amd64/org.keepassxc.keepassxc/opt/apps/org.keepassxc.keepassxc/files  tree -L 3                                                                                       
    ├── plugins
    │   ├── bearer
    │   │   ├── libqconnmanbearer.so
    │   │   ├── libqgenericbearer.so
    │   │   └── libqnmbearer.so
    │   ├── iconengines
    │   │   └── libqsvgicon.so
    │   ├── imageformats
    │   │   ├── libqgif.so
    │   │   ├── libqicns.so
    │   │   ├── libqico.so
    │   │   ├── libqjpeg.so
    │   │   ├── libqmng.so
    │   │   ├── libqsvg.so
    │   │   ├── libqtga.so
    │   │   ├── libqtiff.so
    │   │   ├── libqwbmp.so
    │   │   └── libqwebp.so
    │   ├── platforminputcontexts
    │   │   ├── libcomposeplatforminputcontextplugin.so
    │   │   └── libibusplatforminputcontextplugin.so
    │   ├── platforms
    │   │   └── libqxcb.so
    │   ├── platformthemes
    │   │   ├── libqgtk3.so
    │   │   └── libqxdgdesktopportal.so
    │   └── xcbglintegrations
    │       ├── libqxcb-egl-integration.so
    │       └── libqxcb-glx-integration.so

Qt编译选项

虽然说法是维护者在封装应用的时候没有把fcitx的Qt plugin一同封装进去。但是,SZBT编译出来用了一段时间的QT5.15也存在这个情况,但是这可是原生编译的。翻看了一下Qt5.15的编译选项手册和最终编译使用的参数,发现并没有关于fcitx的启用/禁用内容。难道说,输入法插件不归Qt管吗?

图片.png

图片.png

查看正确的项目归属

想起来前面查到包含fcitx Qt plugin的一个包"fcitx-frontend-qt5",用apt查了一下homepage信息。

ziggy@ziggy-PC:/$ apt show fcitx-frontend-qt5
Package: fcitx-frontend-qt5
Version: 1.2.7-2
Priority: optional
Section: libs
Source: fcitx-qt5
Maintainer: Debian Input Method Team 
Installed-Size: 191 kB
Depends: fcitx-module-dbus, libc6 (>= 2.14), libgcc-s1 (>= 3.0), libqt5core5a (>= 5.15.1), libqt5dbus5 (>= 5.0.2), libqt5gui5 (>= 5.6.0~beta) | libqt5gui5-gles (>= 5.6.0~beta), libstdc++6 (>= 11), libxkbcommon0 (>= 0.5.0), qtbase-abi-5-15-7
Homepage: https://www.fcitx-im.org

发现官网地址是fcitx而不是Qt的网站,说明了这个插件相对Qt是一个独立的体系,并不算在Qt强相关插件内,更多的接近一个应用的Qt plugin.
在找到fcitx-qt5项目地址并编译源码后,通过设置"QT_PLUGIN_PATH"和"LD_LIBRARY_PATH"变量来设置fcitx-qt插件的运行库、插件路径后,Qt based应用可以正常调用fcitx插件了.

潜在风险(建议方案)

如果应用/预封装的包自带了Qt库和Qt插件,只是缺了fcitx插件,那直接把fcitx的libs和插件加进去就好,如果直接换掉/覆盖所有plugin,就会导致插件冲突,应用加载失败
如果是自己要从源码开始编译,可以直接使用SZBT集成fcitx插件的Qt5.15.10来进行编译&使用。
目前"deepin-shared-libs"的仓库中已经上传了SZBT的Qt5.15.10完整包和fcitx-qt的独立plugin package,感兴趣的可以根据需求来下载使用

Reply Favorite View the author
All Replies
jjcui8595
Moderator
2023-12-19 22:30
#1

感谢分享like

Reply View the author
阿尼樱奈奈
Moderator
2023-12-19 22:43
#2

like

Reply View the author
Shiroko
deepin
2023-12-19 23:55
#3

V23用的Fcitx5是fcitx5-frontend-qt5包里面的那个so。一个套路~

Reply View the author
Ziggy
deepin
2023-12-20 00:43
#4
Shiroko

V23用的Fcitx5是fcitx5-frontend-qt5包里面的那个so。一个套路~

fcitx5用fcitx4的好像也没问题applaud

Reply View the author
nexfia
deepin
2023-12-21 02:24
#5

like

Reply View the author
berners
deepin
2024-01-23 00:40
#6

目前"deepin-shared-libs"的仓库中已经上传了SZBT的Qt5.15.10完整包和fcitx-qt的独立plugin package,感兴趣的可以根据需求来下载使用

page not exist

Reply View the author
Ziggy
deepin
2024-01-23 14:50
#7
berners

目前"deepin-shared-libs"的仓库中已经上传了SZBT的Qt5.15.10完整包和fcitx-qt的独立plugin package,感兴趣的可以根据需求来下载使用

page not exist

Fixed,thanks.似乎是直接从纯markdown文本迁移过来出现了点问题

Reply View the author