如何在 awesome WM 中将数字键盘绑定到标签切换器?

如何在 awesome WM 中将数字键盘绑定到标签切换器?

在 awesome WM 下,我发现即使开启了Mod4 + numpad <1-9>,效果也不一样。我觉得用它来切换标签很方便。如何绑定这个?Mod4 + 1-9NumLockMod4 + numpad <1-9>

答案1

我使用 获取了数字键盘按键映射xev。因此,将数字键盘映射到标签切换器可能很容易,如下所示:

-- Numpad: [0-9] = [#90, #87-#89, #83-#85, #79-#81]
local np_map = { 87, 88, 89, 83, 84, 85, 79, 80, 81 }
for i = 1, keynumber do
   globalkeys = awful.util.table.join(
      globalkeys,
      awful.key({ modkey }, "#" .. np_map[i],
        function ()
           local screen = mouse.screen
           if tags[screen][i] then
              awful.tag.viewonly(tags[screen][i])
           end
        end),
      awful.key({ modkey, "Control" }, "#" .. np_map[i],
        function ()
           local screen = mouse.screen
           if tags[screen][i] then
              awful.tag.viewtoggle(tags[screen][i])
           end
        end),
      awful.key({ modkey, "Shift" }, "#" .. np_map[i],
        function ()
           if client.focus and tags[client.focus.screen][i] then
              awful.client.movetotag(tags[client.focus.screen][i])
           end
        end),
      awful.key({ modkey, "Control", "Shift" }, "#" .. np_map[i],
        function ()
           if client.focus and tags[client.focus.screen][i] then
              awful.client.toggletag(tags[client.focus.screen][i])
           end
        end))
end

答案2

您可以使用以下keygroup论点awful.key

    awful.key {
        modifiers   = { modkey },
        keygroup    = "numpad",
        description = "only view tag",
        group       = "tag",
        on_press    = function (index)
            local screen = awful.screen.focused()
            local tag = screen.tags[index]
            if tag then
                tag:view_only()
            end
        end,
    },

https://awesomewm.org/apidoc/input_handling/awful.key.html#keygroups

我用它来进行没有 modkey 的标签切换,因为否则我就用不到数字键盘。

相关内容