├── README.md └── spusim.lua /README.md: -------------------------------------------------------------------------------- 1 | # fcitx5-lua-spusim 2 | 3 | ## 简介 4 | 此插件用于 fcitx5 对特定程序初始化特定输入法 5 | 6 | ## 要求 7 | fcitx5-lua >= 5.0.3 8 | 9 | ## 用法 10 | 1. 将 `spusim.lua` 置于`~/.local/share/fcitx5/lua/imeapi/extensions/`目录下,没有则新建 11 | 2. 通过设置环境变量 `FCITX_LUA_SPUSIM` 来指定特定程序初始化为特定输入法,格式为 `程序名:输入法名`,有多个用英文逗号隔开,例如: `firefox:shuangpin,fractal:rime` 12 | 13 | 14 | ### 备注 15 | 可使用以下命令获取当前输入法名称:
16 | `dbus-send --session --print-reply --dest=org.fcitx.Fcitx5 /controller org.fcitx.Fcitx.Controller1.CurrentInputMethod` 17 | -------------------------------------------------------------------------------- /spusim.lua: -------------------------------------------------------------------------------- 1 | local fcitx = require("fcitx") 2 | 3 | -- 获取环境变量 4 | local FCITX_LUA_SPUSIM = os.getenv("FCITX_LUA_SPUSIM") 5 | 6 | -- 将环境变量的值切割为 "程序名:输入法名" 格式 7 | local aaa = fcitx.splitString(FCITX_LUA_SPUSIM,",") 8 | 9 | function switchIM() 10 | for _,v in ipairs(aaa) do 11 | 12 | -- 将程序名称和输入法名称切割开 13 | local program_im = fcitx.splitString(v,":") 14 | 15 | -- 如果当前程序名称和环境变量指定的程序名称相同,则将输入法切换为指定的输入法 16 | if (program_im[1] == fcitx.currentProgram()) then 17 | fcitx.setCurrentInputMethod(program_im[2],true) 18 | end 19 | end 20 | end 21 | 22 | if (FCITX_LUA_SPUSIM ~= nil) then 23 | 24 | -- 监听输入法上下文创建事件 25 | fcitx.watchEvent(fcitx.EventType.ContextCreated, "switchIM") 26 | end 27 | --------------------------------------------------------------------------------