每个客户端都有独特的键盘布局

问题描述 投票:0回答:1

我用一个非常原始的

xkb-switch
实用程序更改布局。我需要模仿 IBus 的“在所有应用程序之间共享相同的输入法 - 禁用”行为。

我的想法是这样的:

  • 退出某个客户端时,我想存储
    xkb-switch
    shell 命令的输出(它只是列出我当前的布局:
    us(altgr-intl)
    am
    ru
  • 一段时间后,当重新进入该客户端时,我想使用 shell 命令将键盘布局切换回 (切换到存储的布局)
    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

lua awesome-wm
1个回答
0
投票

最后我更改了两行代码,现在可以了:

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)
© www.soinside.com 2019 - 2024. All rights reserved.