Re-ask: Why Fcitx?

I wrote some post about “Why Fcitx” before, while I was little bit worried about fcitx’s future. But for now, I already have some idea for this question.

There is already several input method framework on Linux world, why Fcitx is needed? First let’s review the history of Fcitx. Fcitx was born in 2002, which by that time was named “gWubi”. It got renamed “fcitx” some year later. It’s never an input method framework, but an input method collection.

In 2007, there is some incident for Fcitx, you can find the detailed link on wikipedia. At that time I didn’t even use Linux yet. The story for me on Fcitx began with that I became a KDE user. At that time, IBus nor Scim is not a good choice for Qt based program, so I moved to Fcitx, and found there is a little plasmoid, called kimpanel. Fcitx’s kimpanel support is only a branch inside fcitx, and didn’t sync with trunk for a long time. So I decided to port it to the trunk. That‘s the chance that I become a Fcitx developer, till now. I want to make Fcitx a unique framework, which cannot be replaced. I carefully learn the all existing function of Fcitx, and I thought I finally found an awesome road for Fcitx.

Fcitx is famous of its lightweight, and quick speed, this idea didn’t chance even after I change Fcitx a lot. And it’s become even more light for the core, actually. Now I want to add some new properties to Fcitx, including native feeling, flexibility, and consistency.

Thanks to dbus, and kimpanel, I could make fcitx to use the most native UI on all the desktop, including GNOME, and KDE. And if you just want a xlib based UI? Ok, fcitx-ui-light is for you. And I even provides two configuration tool, for gtk users and KDE users, which could brings them the most native feeling on theirs system.

The second property is flexibility . Fcitx don’t choose the interprocess model, because that will breaks some flexibility of Fcitx. Input method is basically interprocess key stroke and mouse event passing between program. But I want input method can access some global property easily, and interact with each other, that’s why I stop my step for the interprocess input method support. Fcitx could be extended very easy, with nearly no limitation.

Consistency is the last property, which brings together with the first two properties. First, code is largely reused between input method, which brings consistency among different input method. The question about why this input method can customize punctuation, why that cannot, could hardly happen on Fcitx. Fcitx input method can share the built punctuation module, which also reduce the effort for developing an CJK input method. Other great features, like cloud-pinyin, auto switch, and quick phrase, are also shared among different input methods. This idea cannot be achieved by all existing input method framework.

What can be done with fcitx? Everything you can think of, for example, tweet sending could be extended to fcitx easily; bind a hotkey with specific input method could also be possible. You want a ncurses based configuration tool? Ok, just use fcitx-config to do the thing you want. Need some more dbus interface, fcitx-dbus is there and you can implement your own dbus module. I can hardly say there is some limitation to make your own input method module.

Feel free to join the development with Fcitx, to bring some more cool stuff to the input method world.

Posted in fcitx development | Tagged | 11 Comments

Make Fcitx like a system component.

Some days ago, I added a little option to Fcitx, which is called: “Use first input method as inactive state”. What does that mean? Actually that’s how I make Fcitx more like a system input method framework.

Fcitx have three state in the past, called: “Close”, “Inactive”, and “Active”. “Close” is the default state of Fcitx, which means Fcitx will not RECEIVE any key from program, in spite of the trigger key (Which by default is CTRL + SPACE). When trigger key is used, then Fcitx will goes to Active state, so it will receive key from program, and you can compose with your favorite input method. You can switch betwen inactive and active with switch key, which by default is “Left Ctrl”.

When “Use first input method as inactive state” is enabled, close state will be never used (in spite of some special case, like fcitx-fbterm, since fbterm must totally control the state change.), and you can assign your first input method to inactive state, and trigger key and switch key will have the same behavior.

This option will become useful with fcitx-keyboard. Since fcitx-keyboard’s function can replace the “Close” State. For example, if you are simply a Chinese Pinyin User, you can add “English (US)” and Pinyin to your input method list. Then you can just use it as before, but you can also use the extra feature provides by fcitx-keyboard easily. You don’t need to bother extra keyboard configuration, just gives everything to fcitx.

Another benefit is you can use some special switch key as your trigger key. Due to some implement limitation, you cannot configure a hotkey contains only combination keys (ctrl, alt shift).

I just cannot make this option by default right now, since Fcitx is not default component on most system, enable it by default but without proper configuration, it might take more effort to make things work. But I recommend you to give it a try. Or if any distribution interested in using fcitx as a default system component, you can do some specific patch to “config.desc” to reset the default value.

Posted in fcitx development | 6 Comments

折腾Linux桌面中让人迷惑的形容词

用桌面的很多人都对自己的桌面有评价,但很多用词对我来说总是难以把握具体含义。

所以对使用以下描述的词评论都无视。描述个人感受不做到精确(concrete),那和对牛弹琴没什么两样。

1、字体清晰/锐利

这也就是我不和别人讨论字体设置的原因。因为清晰/锐利是个模糊的概念。

想要做到精确,上来第一句话应该先回答,是使用位图字体,还是矢量字体?对有些人来说,清晰/锐利等于位图,对有些人来说,清晰/锐利是使用在矢量字体的前提下的,所以经常会看到一群人互相对牛弹琴。

2、降低效率/专注

这是个主观概念,而且几乎总是预设别人了解你到底平时在干什么。

如果一个人没事就是只对着一个浏览器上网的话,这个概念也许对他完全就没意义。

我直到现在都没明白有些人执着的高效是什么意思。

3、花俏

这又是个模糊的概念,问题在于形容的对象是什么?有些人似乎形容的是动画效果,有些人形容的是样式。那么对应的反义词前者应该是不平滑、或者静态,后者应该是朴素。

4、轻快/轻量

首先很多人把“功能多”和“重量”联系在一起,这显然不是一个正确的联系。功能多寡取决于你的需要。

其次就是不了解内部实现就评价轻量或者重量。

当然由于主观因素过多,最没有价值的评论还是人云亦云,而且还无法区分;以及因果倒错,很多人应该打回去学逻辑。

欢迎补充。

Posted in Linux | 15 Comments

Fcitx Keyboard

Video demonstration:

Fcitx will support spell checker based word hint, and automatically keyboard layout switch.

1. You can use keyboard layout as a single input method, and use corresponding language spell checker.

2. Input method can gives a hint about what keyboard layout it requires, for instance, pinyin will request us layout and fcitx-keyboard can then switch to us layout once pinyin is used.

You can take a look at the code at: https://github.com/fcitx/fcitx-keyboard

Posted in fcitx development | Tagged | 2 Comments

Memory pool

自从fcitx的内核从古老的gbk转向了utf8之后,自带拼音和码表的字符串就带来了一些问题。

首先情况是这样的在我的系统上,fcitx的自带拼音加载后将占用28MB的内存,考虑下的话,其中有个 (2int+2pointer)*词数的数据结构,其次是词本身,有约4MB,词总数约20万。那么估计一下的话拼音应该占用约8.5M。考虑刚刚启动不加载的时候,占用约6M,总计应该在14M左右。那多出来的14M都干啥去了呢?(并无内存泄露)

之前也一直没有关注这件事情,不过在前几天在 @henryhu 的建议下增加了一个Memory pool的实现。这个实现非常naive,乃至于不能单独释放申请的内存(只能整体释放)。不过对于fcitx自身拼音和码表的实现这个情况来说,是一个非常合适的选择。

首先有兴趣的人可以来做一个实验,写一个for循环,每次使用malloc申请1字节,循环申请1M次。然后看看操作系统的内存使用量。然后修改下,每次申请16字节,循环申请64k次,总量也是1MB,然后再看看操作系统内存使用量。

具体实现如下,内存不足时默认每次申请8k字节的内存块,如果一次申请超过8k就申请8k的2的n次方那么大的内存。每个块使用一个offset标记里面当前free的位置,当offset和容量的差距小于某个threshold的时候,就将其从可申请的list中移除,保证在遍历候选内存块的列表时的效率,那些不使用的部分成为可以忽略的内存碎片。(实际设定threshold = 16,16相比 8k 可忽略不计)

对于码表和拼音来说,其中的数据是几乎不用单独释放的,这正好可以采用这种naive的实现(而不是使用比较复杂的full functional的memory pool)。

那么最终的效果就是在我的系统上fcitx自带拼音加载后使用内存达到14MB,符合最开始的预期使用。

Ref:

http://code.google.com/p/fcitx/issues/detail?id=133

http://en.wikipedia.org/wiki/Memory_pool

Posted in fcitx development | 8 Comments