SlideShare a Scribd company logo
fcitx-chewing 逐行審查
先讀碼,再 compile
Huei-Horng Yo (hiroshiyui) 游輝宏 <hiroshi@ghostsinthelab.org>
前情提要
● libchewing 推出 0.4.0 新版
● fcitx-chewing 如預期的需要配合新版 libchewing 修
改,否則動不了
● 究竟,在這段冒險的路上,有什麼險阻正在等待
著 Hiroshi ? Hiroshi 又將如何化解這些難關呢?
敬請期待下一回
(聽眾的鞋子丟過來了)
修復過程
1. 跟 chewing_Init(), chewing_Terminate() 說再見
2. 將 chewing_zuin_String() 改用
chewing_bopomofo_String_static()
3. 處理 libchewing 新引入 SQLite 作為使用者詞庫的
異常問題
4. 打完收工
心理建設
● 程式爛了,沒有人去改,不會自己變好
● 自己的輸入法自己修!
● 我一個非本科的文組外行人、不慣 C 的小弱弱都
能把問題修好了,真的沒有那麼難
● 修理的過程中幾乎把整個 fcitx-chewing 程式碼看
過了,因此瞭解如何實作一個輸入法→ Level Up!
輸入法
● 很多人分不清楚:
– 輸入法(法→法則)
● 倉頡、注音、行列、大易…
– 輸入法框架、平台、引擎(提供輸入法一套有系統的
實作方式)
●
iBus,Fcitx,Gcin,SCIM,OpenVanilla...
● 看過這張投影片後,從現在開始請別再混淆了
輸入法
● 基本概念
– 定義輸入法規則
– 實作
– 處理使用者輸入字根、聲韻符號鍵位(先不論手寫、
語音)
– 查詢符合字根、聲韻符號組合的字或詞,提供使用者
候選
– 將選擇字詞放在預備區或輸出(上字)到應用程式
fcitx-chewing 逐行審查
●
config.h
– 顯而易見的一行,由 FindChewing.cmake 找出
libchewing 所在
fcitx-chewing 逐行審查
●
chewing.conf.in & fcitx-chewing.conf.in
– 兩者實際安裝到系統時會是 chewing.conf & fcitx-
chewing.conf ,也很好懂,是這個輸入法的基本描
述
– fcitx-chewing 之於 fcitx 既是一個 input method
同時也是一個 add-on
– 截自目前 fcitx 對輸入法模組的僅接受 shared
library 型式,故 Type 欄位值恆為 SharedLibrary
fcitx-chewing 逐行審查
●
fcitx-chewing.desc
– 定義一些新酷音輸入法的設定選項,如選字鍵、前後
方加詞、注音鍵盤種類
●
config.c
– 與 fcitx-chewing.desc 相配合,登錄設定鍵、值
● 在 eim.h 當中實際定義了 FcitxChewingConfig 的結構
● 這裡可以看出 fcitx 處理輸入法設定的方式很有條
理,選項交由檔案定義,而不在 code 裡寫死
fcitx-chewing 逐行審查
●
eim.h
– 整個檔案裡我覺得最該注意的是那幾行
__EXPORT_API ,是這個輸入法實作 fcitx 輸入法
模組的幾個介面,可以對照 eim.c 的 FcitxIMIFace
這段
– FcitxChewing 這個結構分別將 fcitx 的設定、生成
實例,以及 libchewing 的 context 包在一起
fcitx-chewing 逐行審查
●
eim.c
– 最主要的程式所在
– FCITX_DEFINE_PLUGIN 這行指定使用
FcitxIMClass2 來定義這個模組的生成、結束所用的
函式
– 重點還是在 FcitxIMIFace 這裡
fcitx-chewing 逐行審查
●
eim.c
– 重點還是在 FcitxIMIFace 這裡
– 對照一下前面提過的輸入法基本概念
fcitx-chewing 逐行審查
● 重點還是在 FcitxIMIFace 這裡
– Init 一開始啟動時做些什麼
– ResetIM 重置整個輸入法的狀態
– DoInput 輸入中應該如何處理各種狀況
– GetCandWords 取得候選字詞
– ReloadConfig 重新讀入設定
– OnClose 處理輸入法開啟、關閉的狀態切換
– KeyBlocker 處理特殊鍵
結語
● fcitx-chewing 就是負責讓 fcitx 與 libchewing 好好合作
的中間人
– 可以把 fcitx-chewing 代換成其他輸入法框架的新酷音
實作
● 瞭解一個字詞如何「由人腦的聲韻符號→對應按鍵
→ libchewing 查詢對應字詞→輸入法框架處理輸出」
的基本觀念,觀念有了就不覺得程式碼像火星文
● 自己的輸入法自己修、自己改良!
閉場黑
謝謝!

More Related Content

More from Hui-Hong You

Explore DVB-T SI
Explore DVB-T SIExplore DVB-T SI
Explore DVB-T SI
Hui-Hong You
 
Arch Linux Taiwan Community Introduction - COSCUP 2017
Arch Linux Taiwan Community Introduction - COSCUP 2017Arch Linux Taiwan Community Introduction - COSCUP 2017
Arch Linux Taiwan Community Introduction - COSCUP 2017
Hui-Hong You
 
Besides programming
Besides programmingBesides programming
Besides programming
Hui-Hong You
 
用 Ruby 操作 OSM 資料批次匯入:以 YouBike 微笑單車租借站資料為例
用 Ruby 操作 OSM 資料批次匯入:以 YouBike 微笑單車租借站資料為例用 Ruby 操作 OSM 資料批次匯入:以 YouBike 微笑單車租借站資料為例
用 Ruby 操作 OSM 資料批次匯入:以 YouBike 微笑單車租借站資料為例Hui-Hong You
 
Coscup 2013 Lightning Talk (was not really presented)
Coscup 2013 Lightning Talk (was not really presented)Coscup 2013 Lightning Talk (was not really presented)
Coscup 2013 Lightning Talk (was not really presented)Hui-Hong You
 
Drupal 皮、Web 骨:我如何為鉅額效能耗損止血並重新愛上 Drupal?
Drupal 皮、Web 骨:我如何為鉅額效能耗損止血並重新愛上 Drupal?Drupal 皮、Web 骨:我如何為鉅額效能耗損止血並重新愛上 Drupal?
Drupal 皮、Web 骨:我如何為鉅額效能耗損止血並重新愛上 Drupal?Hui-Hong You
 

More from Hui-Hong You (6)

Explore DVB-T SI
Explore DVB-T SIExplore DVB-T SI
Explore DVB-T SI
 
Arch Linux Taiwan Community Introduction - COSCUP 2017
Arch Linux Taiwan Community Introduction - COSCUP 2017Arch Linux Taiwan Community Introduction - COSCUP 2017
Arch Linux Taiwan Community Introduction - COSCUP 2017
 
Besides programming
Besides programmingBesides programming
Besides programming
 
用 Ruby 操作 OSM 資料批次匯入:以 YouBike 微笑單車租借站資料為例
用 Ruby 操作 OSM 資料批次匯入:以 YouBike 微笑單車租借站資料為例用 Ruby 操作 OSM 資料批次匯入:以 YouBike 微笑單車租借站資料為例
用 Ruby 操作 OSM 資料批次匯入:以 YouBike 微笑單車租借站資料為例
 
Coscup 2013 Lightning Talk (was not really presented)
Coscup 2013 Lightning Talk (was not really presented)Coscup 2013 Lightning Talk (was not really presented)
Coscup 2013 Lightning Talk (was not really presented)
 
Drupal 皮、Web 骨:我如何為鉅額效能耗損止血並重新愛上 Drupal?
Drupal 皮、Web 骨:我如何為鉅額效能耗損止血並重新愛上 Drupal?Drupal 皮、Web 骨:我如何為鉅額效能耗損止血並重新愛上 Drupal?
Drupal 皮、Web 骨:我如何為鉅額效能耗損止血並重新愛上 Drupal?
 

fcitx-chewing 逐行審查