user905686
user905686

Reputation: 4634

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?

Upvotes: 3

Views: 823

Answers (2)

Blake Miller
Blake Miller

Reputation: 805

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

Upvotes: 1

Chris Stryczynski
Chris Stryczynski

Reputation: 33881

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" )
         ]
      )
    ]
 )

Upvotes: 2

Related Questions