fcitx / fcitx5-lua

25 stars 7 forks source link

Bug: watchEvent(InputMethodActivated) doesn't work #10

Closed chuangzhu closed 3 years ago

chuangzhu commented 3 years ago

The script below causes fcitx5 failing to start:

local fcitx = require("fcitx")

fcitx.watchEvent(fcitx.EventType.InputMethodActivated, "handler")

function handler()
    print("deactivated")
    return false
end
$ fcitx5
I2021-01-28 08:32:46.000851 instance.cpp:1307] Override Enabled Addons: {}
I2021-01-28 08:32:46.000957 instance.cpp:1308] Override Disabled Addons: {}
I2021-01-28 08:32:46.003857 addonmanager.cpp:177] Loaded addon imselector
I2021-01-28 08:32:46.006249 addonmanager.cpp:177] Loaded addon quickphrase
I2021-01-28 08:32:46.046296 addonmanager.cpp:177] Loaded addon xcb
I2021-01-28 08:32:46.046876 addonmanager.cpp:177] Loaded addon wayland
I2021-01-28 08:32:46.047226 addonmanager.cpp:177] Loaded addon waylandim
I2021-01-28 08:32:46.085466 addonmanager.cpp:177] Loaded addon keyboard
I2021-01-28 08:32:46.086328 addonmanager.cpp:177] Loaded addon clipboard
I2021-01-28 08:32:46.339282 addonmanager.cpp:177] Loaded addon pinyinhelper
I2021-01-28 08:32:46.340049 addonmanager.cpp:177] Loaded addon luaaddonloader
I2021-01-28 08:32:46.342045 addonmanager.cpp:177] Loaded addon dbus
I2021-01-28 08:32:46.355301 addonmanager.cpp:177] Loaded addon xim
I2021-01-28 08:32:46.367945 addonmanager.cpp:177] Loaded addon ibusfrontend
=========================
Fcitx 5.0.4 -- Get Signal No.: 11
Date: try "date -d @1611793966" if you are using GNU date ***
ProcessID: 112617
fcitx5(+0xbd9e)[0x55e35d7e1d9e]
/usr/lib/libc.so.6(+0x3d6a0)[0x7f6dd660c6a0]

Changing the event type to fcitx.EventType.InputMethodDeactivated, the handler is called on both activated and deactivated. Argument the handler receives seems to be the name of current input method:

local fcitx = require("fcitx")

fcitx.watchEvent(fcitx.EventType.InputMethodDeactivated, "handler")

function handler(arg)
    print(arg)
    return false
end
I2021-01-28 09:02:09.049486 kimpanel.cpp:121] Kimpanel new owner
keyboard-us
xmodmap:  please release the following keys within 2 seconds:
I2021-01-28 09:02:10.064545 addonmanager.cpp:177] Loaded addon fullwidth
I2021-01-28 09:02:10.065257 addonmanager.cpp:177] Loaded addon chttrans
pinyin
keyboard-us
pinyin

I investigated a little bit into the code, and I think it is caused by a mismatch in the definition of EventType between fcitx5 and base.lua.

chuangzhu commented 3 years ago

Still not solved, the code below crashes fcitx5 when switching input method.

local fcitx = require("fcitx")

-- fcitx.watchEvent(fcitx.EventType.InputMethodActivated, "switch_input_method")
fcitx.watchEvent(fcitx.EventType.SwitchInputMethod, "switch_input_method")

function switch_input_method()
    -- print(im)
    return false
end
=========================
Fcitx 5.0.7 -- Get Signal No.: 11
Date: try "date -d @1619326822" if you are using GNU date ***
ProcessID: 181087
fcitx5(+0xbdae)[0x5648d01b3dae]
/usr/lib/libc.so.6(+0x3cf80)[0x7fa6df3f3f80]
/usr/lib/libc.so.6(+0x15c9fe)[0x7fa6dd8269fe]

[1]  + 181087 exit 1     fcitx5
chuangzhu commented 3 years ago

@wengxt Please reopen this issue.

wengxt commented 3 years ago

@chuangzhu fixed by https://github.com/fcitx/fcitx5-lua/commit/6e513a859d07065e80213a3cb85c083416aa0d04