关于之前发在 Archlinux CN 群里 Fcitx 5 问卷里面问题的几个回答

1、sni图标似乎不响应系统(kde)配色了?

图标上来说用的是 input-keyboard-symbolic ,不幸他们没这个图标的 plasma 版本。其他图标都挺正常的啊?可以给 breeze 提交一个希望增加 input-keyboard 这个图标的请求。

2、非kde下面托盤和托盤右鍵菜單太醜了,還沒之前的4好看。

右键菜单和输入框一个主题吧。自带主题来说应该还行,没有修改的打算。如果你用的别的主题那就和 Fcitx 无关了。

3、更好康的皮肤,更佳的英文混输体验

皮肤本身就不说了,我自己应该不会再做什么别的皮肤。不过目前给皮肤增加了好几个新的功能,应该能帮助大家做出更好的皮肤。一个是 Overlay 图片,一个不会受到缩放的图片,可以固定显示在背景上。另一个是增加了 KWin 的模糊背景的支持,目前暂时可以设定一个矩形区域并模糊。

混合输入这个应该继续学习一下有什么办法……短期内肯定是没有大的改进。

4、Doesn’t work well on Sway, but that’s mainly a Wayland input protocol issue, no rush.

这个确实是比较难的事情…不过我对 wlroots 那个协议很不满意,下一步反正是打算自己实现一个新的协议。

5、fcitx5 拼音的繁体翻译建议改一下 OpenCC 的配置档或者提供选项供偏好设定,个人不是很喜欢直接用 s2t 的翻译

安排上了,已经修改了。

6、Kimpanel的菜单要是能模糊就好了

……右键菜单是就是普通的菜单,输入框本身也可以模糊,如果你的系统输入窗口没有模糊建议检查窗口配置。

7、完善对 steam 的支持

steam 完善对输入法的支持才对

8、希望能增强对wsl/wsl2环境的兼容性

用 opensuse leap 测试了一下,没有问题。建议网上搜索一下别人的设置步骤。

9、词库太少 云输入太慢

open-gram 确实数据版本是有年头了…不知道能不能联系他们有机会在训练一次。其他有可以直接下载 sogou 词库的功能,另外也可以试试 zhwiki 这个词库。

10、支持用户自己加入个别未收录的字

现在就可以的。拼音词库的话可以随便添加字(只要拼音本身合法),如果有特殊读音的需求请提交 issue 给 libime。

11、可以配置指定程序初始化指定的输入法(比如可以手动设置tg默认使用中文,终端默认英文)

如果急切需要的话,其实写个插件就可以实现。

12、对wm有更好的支持

这个……不够具体。不太懂说的意思。

Posted in fcitx development | Tagged , | Leave a comment

Fcitx 5 的拼音有哪些新功能

拼音方面做了特别多的改进,但是目前还没有比较集中的地方说明到底有哪些新功能,所以这里特别列举一下。

1、算法的改进
数据采用了和 sunpinyin 相同的 open-gram(也是为什么没有 fcitx5-sunpinyin的原因),算法来说是类似的基于统计语言模型计算概率,在用户的历史处理上和 sunpinyin 有所不同,但是整体来说是类似的。和原本的 Fcitx 4 自带拼音相比的话改进则是巨大的。

2、笔画过滤
按 ` (反引号)键触发,可以输入 hpszn(横撇竖折捺)进行搜索。

3、输入颜文字
对于有对应颜文字的词组可以直接输入,具体列表可以参考 https://github.com/fcitx/fcitx5-chinese-addons/blob/master/im/pinyin/emoji.txt

4、查询读音
选中一段文字之后,可以用快速输入输入 duyin 来列出文字的读音。

5、自定义双拼方案音节
例如可以直接指定某个音节对应的双拼,而不是根据单独声母/韵母来指定。此外之前似乎一直和标准不符的自然码方案也得到了修复。

6、多词库管理
可以直接导入搜狗的细胞词库,单独启用或者禁用某个词库等。

7、Lua 扩展
目前加入了针对候选词匹配的功能,而且预置了一些 lua 功能,例如输入时间:

8、拆字输入
通过输入汉字部件来找到对应汉字。例如:

9、一些之前就有的功能
笔画输入(直接hpszn输入笔画查找汉字),以词定字,联想,简繁转换,输入单词,云拼音,还有 Fcitx 一直以来就有的高度可扩展的快速输入功能。

Posted in fcitx development | Tagged , , | 1 Comment

世纪未解之谜之 Emacs 为什么要设置 LC_CTYPE 才能用输入法终于

在 Linux 上用 Emacs 和输入法的人可能都曾经有这样的疑惑,为什么只有 emacs 非常奇怪经常要额外设置一个 LC_CTYPE 才能正常使用输入法。很多年以前,我也一直不明白,直到最近 LibX11 的一个 bug 让我们有机会找到了…Emacs 不能用输入法的真正原因。

首先声明,并不是 Emacs 对这个环境变量有任何的判断。设置它,只是触发了一个副作用让 Emacs 能够正常工作。而这个真实原因的线索其实在几年前就已经被发现了并且写到了 Fcitx Wiki 的 FAQ 上,但是一直没有被联系起来。

首先要说 XIM。XIM 这个协议里面其实有很多过时的部分,过时的意思主要是指,实际上在今天完全没有人使用了的部分,但是因为 LibX11 的实现和 XIM 高度绑定,所以不得不依然使用的部分。其中一个就是需要设置一个字体。这个字体的本意,大概只是为了让输入法知道程序在用什么字体,可能让输入法可以选择配合窗口的字体来绘制输入框。XIM 的协议,主要是通过 X11 的 ClientMessage 来实现的,发送字体的部分,是传递一大堆字体的名字列表过去。但是好巧不巧,Emacs 判断这部分关于字体的代码可能会出现很多不同的问题。

可能的问题包括:

1、找不到字体
2、找到太多字体

几年前一个 Emacs 用户研究许久之后,最终发现了因为找不到字体,才没办法使用的情况。

可能有人奇怪,为什么找到太多字体也会出问题?因为对于 X11 的协议来说,每条事件可以发送的字节是有限制的,而 Emacs 上恰恰因为找到了太多字体而且把这些一股脑全部都发送了,才导致输入法在创建连接阶段就已经失败无法继续进行。而这个字体的匹配过程,是会受到 LC_CTYPE 的影响的,当你设置成别的语言例如中文的时候,可能因为字体覆盖编码的原因,反而会让匹配的字体数量大大减少,而恰好满足了要求。

也正是这个副作用导致了为什么在有些人的系统上就一定要设置这个环境变量,而其他人的就不用,实质上是和你系统安装了某些字体有关而已……

本文主要感谢 Yichao Yu 的调试。顺便感谢他还写了个 Patch 给 emacs:https://debbugs.gnu.org/cgi/bugreport.cgi?bug=10867

Posted in fcitx development | Tagged , | Leave a comment

The Road to Fcitx 5: 7 Get event order right

I didn’t expect this to be a thing that is only fixed recently. And the fix itself goes through a little bit back and forth. So I’d just like to share it since it is an interesting experience.

Between the communication of application and input method server. A common thing is application send a key event to input method and wait for the handling result of this event. Fcitx allows multiple different mode for it, including sync and async mode. By default it is async mode to avoid any block on the application side. But since we also support sync mode, we should keep two implementation have the same effect.

But in reality, we do behave the same under most circumstance, except when you bypass the key event and do some other thing at the same time. The reason behind this is actually easy to understand. Check the pseudo code below.

DBusCall call = inputContext->processKeyEvent();
call.waitForFinished();
DBusCall call = inputContext->processKeyEvent();
call.onFinished(processKeyEventCallback);

Imagine the input method issues commitString request at the same time. In the first sync case, the key event will be handled before the commitString, while the latter one will handle commitString before the key event.

If the key event is filtered, then there is no difference, but if the key is not filtered, then we will get two different result. For example, keyboard engine will show spell check within the preedit, but when you press space, the preedit will be commit to client and also the space key. You may say you can solve it by just combining the space key within the commit string request. Then what about a “left” key that doesn’t produce text? One way to solve it is to piggyback a rich result value instead of just a boolean value, but that would require more code change to existing interface. So in order to resolve this, we will force the input method to use the forward key interface to send the key back. Luckily, all event can be handled by the same way. The trick can be done within the last reserved event handler for key event.

Here’s the things changed with in the fcitx framework.

  1. Engine can safely assume any commitString is handled before the key event. If engine want it the other way, it can use forward key request itself. This keeps the default behavior for all input context.
  2. DBus based input context will block all the request sending the client until the request is returned. This ensures processKeyEvent is returned before the following request.
  3. If there is any pending request, mark processKeyEvent request as true, and use forwardKey to re-send the key event to the client.
  4. Within the input context code, tries to use the same data to forward key event if possible to avoid any conversion error.

Posted in fcitx development | Tagged , | 2 Comments

如何现在就在 Arch Linux 用上 Fcitx 5

一开始想了想要不要在标题写 Arch Linux,觉得还是必要的,因为目前只有 Arch Linux (和 Debian)出于套近乎的关系有了 Fcitx 5 全家桶。

1、需要安装的包

IM Module:fcitx5-gtk / fcitx5-qt

拼音和码表:fcitx5-chinese-addons

其他输入法可以参照 fcitx 4 的对应包名安装(例如 fcitx5-chewing 等)

配置工具:kcm-fcitx5(内含 fcitx5-config-qt 对于依赖纠结的人请去拍打 @felixonmars 拆包)

和 Fcitx 4 有一些文件冲突,不能同时安装。

2、环境变量和启动

和 Fcitx 4 一致即可,如果要多说几句的话那就是:

~/.xprofile (X11) 或者 ~/.bash_profile 或者 ~/.profile (SDDM 在 bash_profile 存在时只会读取 bash_profile)

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

目前暂时没有自带 XDG 的自动启动文件,需要自动启动的话暂时可以选择 cp /usr/share/applications/fcitx5.desktop ~/.config/autostart/

3、配置

目前没有对拼音和码表的数据的迁移工具,需要重新训练,但应该用起来已经不错了。拼音的 bug(如果有)应该会比码表少一些。

当然如果你使用了别的并没有改变库的其他输入法数据基本可以直接拿过来用。路径会有所不同,在 fcitx 5 中路径将变为更加标准的 ~/.local/share/fcitx5 ,配置文件还是主要存放在 ~/.config/fcitx5。

默认启动后并不会添加其他输入法,可以通过配置工具进行添加。

4、功能

关于键盘布局方面有较大区别,系统键盘布局现在和一个新的「分组」的概念绑定,同一个分组里的键盘布局是直接通过 xkbcommon 进行模拟,而不是采用修改系统键盘布局的方式。因此也不再有针对 ~/.Xmodmap 的支持,如果需要修改常见的设置(例如交换 Ctrl Esc)建议使用 xkb option 进行修改。

拼音相比原来的「自带拼音」有不少新增的功能,例如多词库,Emoji等,可以通过配置工具那边自行浏览。

Posted in fcitx development | Tagged , | 2 Comments