Search code examples
xmonad

Xmonad multiple submap key combos


This answer describes how to create combo key bindings in Xmonad.

With additionalKeys I add my key bindings as a list to my XConfig configuration:

...
-- Does NOT work
, ((myModMask, xK_a), submap . M.fromList $
    [ ((0, xK_l),    submap . M.fromList $
        [ ((0, xK_1),  spawn "xbacklight -set 10" ) ])
    ])
-- Does work
, ((myModMask, xK_d), submap . M.fromList $
    [ ((0, xK_l),    submap . M.fromList $
        [ ((0, xK_2),  spawn "xbacklight -set 20" ) ])
    ])
-- Does work
, ((myModMask, xK_a), submap . M.fromList $
    [ ((0, xK_l),    submap . M.fromList $
        [ ((0, xK_5),  spawn "xbacklight -set 50" ) ])
    ])
...

But it seems like only the last defined combination of those starting with the same key works (here the first one starting with an "a" seems to be overridden by the last one).

What is different from the example in the linked answer is only that the combinations start with a modkey+key binding instead of just a key.

What could be the problem here?


Solution

  • I'm fairly certain that you can't have keymap list entries with the same keybinding - (myModMask, xK_a). In which case the last entry overrides the previous entry.

    You can combine the two entries however:

     ((myModMask, xK_a), submap . M.fromList $
        [ ((0, xK_l),    submap . M.fromList $
             [
                 ((0, xK_1),  spawn "xbacklight -set 10" )
               , ((0, xK_5),  spawn "xbacklight -set 50" )
             ]
          )
        ]
     )