REF simplify keymap creation

This commit is contained in:
Nathan Dwarshuis 2020-03-26 09:48:02 -04:00
parent 738205cba2
commit ccc3aca822
1 changed files with 65 additions and 64 deletions

View File

@ -76,7 +76,7 @@ main = do
_ <- forkIO runWorkspaceMon' _ <- forkIO runWorkspaceMon'
launch launch
$ ewmh $ ewmh
$ addDescrKeys' ((myModMask, xK_F1), showKeybindings) (myKeys [barPID] dbClient) $ addDescrKeys' ((myModMask, xK_F1), showKeybindings) (mkKeys [barPID] dbClient)
$ def { terminal = myTerm $ def { terminal = myTerm
, modMask = myModMask , modMask = myModMask
, layoutHook = myLayouts , layoutHook = myLayouts
@ -537,99 +537,100 @@ myModMask = mod4Mask
mkNamedSubmap mkNamedSubmap
:: XConfig l :: XConfig l
-> String -> String
-> [(String, NamedAction)] -> [(String, String, X ())]
-> [((KeyMask, KeySym), NamedAction)] -> [((KeyMask, KeySym), NamedAction)]
mkNamedSubmap c sectionName bindings = mkNamedSubmap c sectionName bindings =
(subtitle sectionName:) $ mkNamedKeymap c bindings (subtitle sectionName:) $ mkNamedKeymap c
$ map (\(key, name, cmd) -> (key, addName name cmd)) bindings
-- NOTE: the following bindings are used by dunst: -- NOTE: the following bindings are used by dunst:
-- "M-~", "M-<esc>", "M-S-<esc>", "M-S-." -- "M-~", "M-<esc>", "M-S-<esc>", "M-S-."
myKeys :: [ProcessID] -> Client -> XConfig Layout -> [((KeyMask, KeySym), NamedAction)] mkKeys :: [ProcessID] -> Client -> XConfig Layout -> [((KeyMask, KeySym), NamedAction)]
myKeys hs client c = mkKeys hs client c =
mkNamedSubmap c "Window Layouts" mkNamedSubmap c "Window Layouts"
[ ("M-j", addName "focus down" $ windows W.focusDown) [ ("M-j", "focus down", windows W.focusDown)
, ("M-k", addName "focus up" $ windows W.focusUp) , ("M-k", "focus up", windows W.focusUp)
, ("M-m", addName "focus master" $ windows W.focusMaster) , ("M-m", "focus master", windows W.focusMaster)
, ("M-S-j", addName "swap down" $ windows W.swapDown) , ("M-S-j", "swap down", windows W.swapDown)
, ("M-S-k", addName "swap up" $ windows W.swapUp) , ("M-S-k", "swap up", windows W.swapUp)
, ("M-S-m", addName "swap master" $ windows W.swapMaster) , ("M-S-m", "swap master", windows W.swapMaster)
-- TODO this will decrement past 0? -- TODO this will decrement past 0?
, ("M-C-j", addName "remove master window" $ sendMessage (IncMasterN (-1))) , ("M-C-j", "remove master window", sendMessage (IncMasterN (-1)))
, ("M-C-k", addName "add master window" $ sendMessage (IncMasterN 1)) , ("M-C-k", "add master window", sendMessage (IncMasterN 1))
, ("M-<Return>", addName "next layout" $ sendMessage NextLayout) , ("M-<Return>", "next layout", sendMessage NextLayout)
, ("M-S-<Return>", addName "reset layout" $ setLayout $ XMonad.layoutHook c) , ("M-S-<Return>", "reset layout", setLayout $ XMonad.layoutHook c)
, ("M-t", addName "sink tiling" $ withFocused $ windows . W.sink) , ("M-t", "sink tiling", withFocused $ windows . W.sink)
, ("M--", addName "shrink" $ sendMessage Shrink) , ("M--", "shrink", sendMessage Shrink)
, ("M-=", addName "expand" $ sendMessage Expand) , ("M-=", "expand", sendMessage Expand)
] ++ ] ++
mkNamedSubmap c "Workspaces" mkNamedSubmap c "Workspaces"
-- NOTE this assumes that there are workspaces bound to numbers -- NOTE this assumes that there are workspaces bound to numbers
([ (mods ++ show i, addName (msg ++ " " ++ show i) $ windows $ f w) ([ (mods ++ show i, msg ++ " " ++ show i, windows $ f w)
| (w, i) <- zip (XMonad.workspaces c) [1..] :: [(String, Int)] | (w, i) <- zip (XMonad.workspaces c) [1..] :: [(String, Int)]
, (mods, msg, f) <- , (mods, msg, f) <-
[ ("M-", "switch to workspace", W.view) [ ("M-", "switch to workspace", W.view)
, ("M-S-", "move client to workspace", W.shift)] , ("M-S-", "move client to workspace", W.shift)]
] ++ ] ++
[ ("M-v", addName "switch to VM workspace" $ showWorkspace myVMWorkspace) [ ("M-v", "switch to VM workspace", showWorkspace myVMWorkspace)
, ("M-M1-g", addName "switch to Gimp workspace" $ showWorkspace myGimpWorkspace) , ("M-M1-g", "switch to Gimp workspace", showWorkspace myGimpWorkspace)
]) ++ ]) ++
mkNamedSubmap c "Screens" mkNamedSubmap c "Screens"
[ ("M-l", addName "move up screen" nextScreen) [ ("M-l", "move up screen", nextScreen)
, ("M-h", addName "move down screen" prevScreen) , ("M-h", "move down screen", prevScreen)
, ("M-C-l", addName "move client up screen" $ shiftNextScreen >> nextScreen) , ("M-C-l", "move client up screen", shiftNextScreen >> nextScreen)
, ("M-C-h", addName "move client down screen" $ shiftPrevScreen >> prevScreen) , ("M-C-h", "move client down screen", shiftPrevScreen >> prevScreen)
, ("M-S-l", addName "shift up screen" $ swapNextScreen >> nextScreen) , ("M-S-l", "shift up screen", swapNextScreen >> nextScreen)
, ("M-S-h", addName "shift down screen" $ swapPrevScreen >> prevScreen) , ("M-S-h", "shift down screen", swapPrevScreen >> prevScreen)
] ++ ] ++
mkNamedSubmap c "Actions" mkNamedSubmap c "Actions"
[ ("M-q", addName "close window" kill1) [ ("M-q", "close window", kill1)
, ("M-r", addName "run program" runCmdMenu) , ("M-r", "run program", runCmdMenu)
, ("M-C-s", addName "capture area" runAreaCapture) , ("M-C-s", "capture area", runAreaCapture)
, ("M-C-S-s", addName "capture screen" runScreenCapture) , ("M-C-S-s", "capture screen", runScreenCapture)
, ("M-C-d", addName "capture desktop" runDesktopCapture) , ("M-C-d", "capture desktop", runDesktopCapture)
-- , ("M-C-S-s", addName "capture focused window" $ spawn myWindowCap) -- , ("M-C-S-s", "capture focused window", spawn myWindowCap)
, ("M-<Delete>", addName "lock screen" runScreenLock) , ("M-<Delete>", "lock screen", runScreenLock)
] ++ ] ++
mkNamedSubmap c "Launchers" mkNamedSubmap c "Launchers"
[ ("<XF86Search>", addName "select/launch app" runAppMenu) [ ("<XF86Search>", "select/launch app", runAppMenu)
, ("M-g", addName "launch clipboard manager" runClipMenu) , ("M-g", "launch clipboard manager", runClipMenu)
, ("M-a", addName "launch network selector" runNetMenu) , ("M-a", "launch network selector", runNetMenu)
, ("M-w", addName "launch window selector" runWinMenu) , ("M-w", "launch window selector", runWinMenu)
, ("M-u", addName "launch device selector" runDevMenu) , ("M-u", "launch device selector", runDevMenu)
, ("M-C-e", addName "launch editor" runEditor) , ("M-C-e", "launch editor", runEditor)
, ("M-C-w", addName "launch browser" runBrowser) , ("M-C-w", "launch browser", runBrowser)
, ("M-C-t", addName "launch terminal" runTerm) , ("M-C-t", "launch terminal", runTerm)
, ("M-C-q", addName "launch calc" runCalc) , ("M-C-q", "launch calc", runCalc)
, ("M-C-f", addName "launch file manager" runFileManager) , ("M-C-f", "launch file manager", runFileManager)
-- TODO shoudn't these be flipped? -- TODO shoudn't these be flipped?
, ("M-C-v", addName "launch windows VM" $ runVBox >> appendWorkspace myVMWorkspace) , ("M-C-v", "launch windows VM", runVBox >> appendWorkspace myVMWorkspace)
, ("M-C-g", addName "launch GIMP" $ runGimp >> appendWorkspace myGimpWorkspace) , ("M-C-g", "launch GIMP", runGimp >> appendWorkspace myGimpWorkspace)
] ++ ] ++
mkNamedSubmap c "Multimedia" mkNamedSubmap c "Multimedia"
[ ("<XF86AudioPlay>", addName "toggle play/pause" runTogglePlay) [ ("<XF86AudioPlay>", "toggle play/pause", runTogglePlay)
, ("<XF86AudioPrev>", addName "previous track" runPrevTrack) , ("<XF86AudioPrev>", "previous track", runPrevTrack)
, ("<XF86AudioNext>", addName "next track" runNextTrack) , ("<XF86AudioNext>", "next track", runNextTrack)
, ("<XF86AudioStop>", addName "stop" runStopPlay) , ("<XF86AudioStop>", "stop", runStopPlay)
, ("<XF86AudioLowerVolume>", addName "volume down" runVolumeDown) , ("<XF86AudioLowerVolume>", "volume down", runVolumeDown)
, ("<XF86AudioRaiseVolume>", addName "volume up" runVolumeUp) , ("<XF86AudioRaiseVolume>", "volume up", runVolumeUp)
, ("<XF86AudioMute>", addName "volume mute" runVolumeMute) , ("<XF86AudioMute>", "volume mute", runVolumeMute)
, ("M-C-b", addName "toggle bluetooth" runToggleBluetooth) , ("M-C-b", "toggle bluetooth", runToggleBluetooth)
] ++ ] ++
mkNamedSubmap c "System" mkNamedSubmap c "System"
[ ("M-.", addName "backlight up" runIncBacklight) [ ("M-.", "backlight up", runIncBacklight)
, ("M-,", addName "backlight down" runDecBacklight) , ("M-,", "backlight down", runDecBacklight)
, ("M-M1-,", addName "backlight min" runMinBacklight) , ("M-M1-,", "backlight min", runMinBacklight)
, ("M-M1-.", addName "backlight max" runMaxBacklight) , ("M-M1-.", "backlight max", runMaxBacklight)
, ("M-M1-=", addName "toggle screensaver" toggleDPMS) , ("M-M1-=", "toggle screensaver", toggleDPMS)
, ("M-<F2>", addName "restart xmonad" $ runCleanup hs client >> runRestart) , ("M-<F2>", "restart xmonad", runCleanup hs client >> runRestart)
, ("M-S-<F2>", addName "recompile xmonad" runRecompile) , ("M-S-<F2>", "recompile xmonad", runRecompile)
, ("M-<End>", addName "power menu" runPowerPrompt) , ("M-<End>", "power menu", runPowerPrompt)
, ("M-<Home>", addName "quit xmonad" runQuitPrompt) , ("M-<Home>", "quit xmonad", runQuitPrompt)
, ("M-<Esc>", addName "switch gpu" runOptimusPrompt) , ("M-<Esc>", "switch gpu", runOptimusPrompt)
] ]