Xmonad multiple submap key combos

767 views Asked by At

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?

2

There are 2 answers

1
Chris Stryczynski On BEST ANSWER

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" )
         ]
      )
    ]
 )
0
Blake Miller On

You might also like to try EZConfig, which makes submaps for you given binding strings inspired by those in Emacs. For example:

import XMonad.Util.EZConfig

myKeymap :: [(String, X ())]
myKeymap =
  [ ("M-; s m",    namedScratchpadAction myScratchpads "mongod" )
  , ("M-; s a m",  namedScratchpadAction myScratchpads "mongod2" )
  , ("M-; s z",    namedScratchpadAction myScratchpads "zk" )
  , ("M-; s k",    namedScratchpadAction myScratchpads "kafka" )

  -- ... and so on ...

use that with additionalKeys, see https://hackage.haskell.org/package/xmonad-contrib-0.13/docs/XMonad-Util-EZConfig.html