admin管理员组

文章数量:1122832

I change my layouts with a very primitive xkb-switch utility. I need to imitate the 'Share the same input method among all applications - disabled' behaviour of IBus.

My idea is such:

  • When exiting a certain client I want to store the output of the xkb-switch shell command (it just lists my current layout: us(altgr-intl),am or ru).
  • After some time, when entering back into that client, I want to switch the keyboard layout back (to the stored one) with the shell command xkb-switch --switch <layout_here>

My attempt:

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)

Here is the behaviour: the notification popup is showing the intended language, but for some reason the switched language is wrong, is there some race hazard?

I change my layouts with a very primitive xkb-switch utility. I need to imitate the 'Share the same input method among all applications - disabled' behaviour of IBus.

My idea is such:

  • When exiting a certain client I want to store the output of the xkb-switch shell command (it just lists my current layout: us(altgr-intl),am or ru).
  • After some time, when entering back into that client, I want to switch the keyboard layout back (to the stored one) with the shell command xkb-switch --switch <layout_here>

My attempt:

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)

Here is the behaviour: the notification popup is showing the intended language, but for some reason the switched language is wrong, is there some race hazard? https://youtu.be/juarLneLBAo

Share Improve this question asked Nov 23, 2024 at 4:54 RobberFokZRobberFokZ 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

In the end I changed 2 lines of code and now this works:

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)

本文标签: luaUnique keyboard layout per clientStack Overflow