Xmonad multiple submap key combos

假如想象 提交于 2020-01-04 05:40:12

问题


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?


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/46224259/xmonad-multiple-submap-key-combos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!