Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xmonad multiple submap key combos

Tags:

xmonad

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?

like image 794
user905686 Avatar asked Jul 06 '26 05:07

user905686


2 Answers

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" )
         ]
      )
    ]
 )
like image 157
Chris Stryczynski Avatar answered Jul 08 '26 18:07

Chris Stryczynski


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

like image 34
Blake Miller Avatar answered Jul 08 '26 19:07

Blake Miller