我用一个非常原始的
xkb-switch
实用程序更改布局。我需要模仿 IBus 的“在所有应用程序之间共享相同的输入法 - 禁用”行为。
xkb-switch
shell 命令的输出(它只是列出我当前的布局:us(altgr-intl)
、am
或 ru
)。xkb-switch --switch <layout_here>
client.connect_signal("unfocus", function(c)
awful.spawn.easy_async_with_shell("xkb-switch", function(stdout)
if c.valid then
c.keyboard_layout = stdout
end
end)
end)
client.connect_signal("focus", function(c)
c = awful.screen.focused({client = true})
if c.keyboard_layout == nil then
c.keyboard_layout = "us(altgr-intl)"
end
awful.spawn.with_shell("xkb-switch -s "..c.keyboard_layout)
end)
行为如下:通知弹出窗口显示了预期的语言,但由于某种原因切换的语言是错误的,是否存在种族危险? https://youtu.be/juarLneLBAo
最后我更改了两行代码,现在可以了:
client.connect_signal("unfocus", function(c)
awful.spawn.easy_async_with_shell("xkb-switch", function(stdout)
if c.valid then -- To avoid 'Invalid Object' error
c.keyboard_layout = stdout
end
end)
end)
client.connect_signal("focus", function(c)
if c.keyboard_layout == nil then
c.keyboard_layout = "us(altgr-intl)"
end
awful.spawn("xkb-switch -s "..c.keyboard_layout, false) -- `false` to prevent cursor being stuck in 'loading' state
end)