| |||||||||||||||
| |||||||||||||||
| |||||||||||||||
Description | |||||||||||||||
Useful helper functions for amending the defaultConfig, and for parsing keybindings specified in a special (emacs-like) format. (See also XMonad.Util.CustomKeys in xmonad-contrib.) | |||||||||||||||
Synopsis | |||||||||||||||
| |||||||||||||||
Usage | |||||||||||||||
To use this module, first import it into your ~/.xmonad/xmonad.hs: import XMonad.Util.EZConfig Then, use one of the provided functions to modify your configuration. You can use additionalKeys, removeKeys, additionalMouseBindings, and removeMouseBindings to easily add and remove keybindings or mouse bindings. You can use mkKeymap to create a keymap using emacs-style keybinding specifications like "M-x" instead of (modMask, xK_x), or additionalKeysP and removeKeysP to easily add or remove emacs-style keybindings. If you use emacs-style keybindings, the checkKeymap function is provided, suitable for adding to your startupHook, which can warn you of any parse errors or duplicate bindings in your keymap. For more information and usage eamples, see the documentation provided with each exported function, and check the xmonad config archive (http://haskell.org/haskellwiki/Xmonad/Config_archive) for some real examples of use. | |||||||||||||||
Adding or removing keybindings | |||||||||||||||
additionalKeys :: XConfig a -> [((ButtonMask, KeySym), X ())] -> XConfig a | |||||||||||||||
Add or override keybindings from the existing set. Example use: main = xmonad $ defaultConfig { terminal = "urxvt" } `additionalKeys` [ ((mod1Mask, xK_m ), spawn "echo 'Hi, mom!' | dzen2 -p 4") , ((mod1Mask, xK_BackSpace), withFocused hide) -- N.B. this is an absurd thing to do ] This overrides the previous definition of mod-m. Note that, unlike in xmonad 0.4 and previous, you can't use modMask to refer to the modMask you configured earlier. You must specify mod1Mask (or whichever), or add your own myModMask = mod1Mask line. | |||||||||||||||
additionalKeysP :: XConfig l -> [(String, X ())] -> XConfig l | |||||||||||||||
Like additionalKeys, except using short String key descriptors like "M-m" instead of (modMask, xK_m), as described in the documentation for mkKeymap. For example: main = xmonad $ defaultConfig { terminal = "urxvt" } `additionalKeysP` [ ("M-m", spawn "echo 'Hi, mom!' | dzen2 -p 4") , ("M-<Backspace>", withFocused hide) -- N.B. this is an absurd thing to do ] | |||||||||||||||
removeKeys :: XConfig a -> [(ButtonMask, KeySym)] -> XConfig a | |||||||||||||||
Remove standard keybindings you're not using. Example use: main = xmonad $ defaultConfig { terminal = "urxvt" } `removeKeys` [(mod1Mask .|. shiftMask, n) | n <- [xK_1 .. xK_9]] | |||||||||||||||
removeKeysP :: XConfig l -> [String] -> XConfig l | |||||||||||||||
Like removeKeys, except using short String key descriptors like "M-m" instead of (modMask, xK_m), as described in the documentation for mkKeymap. For example: main = xmonad $ defaultConfig { terminal = "urxvt" } `removeKeysP` ["M-S-" ++ [n] | n <- ['1'..'9']] | |||||||||||||||
additionalMouseBindings :: XConfig a -> [((ButtonMask, Button), Window -> X ())] -> XConfig a | |||||||||||||||
Like additionalKeys, but for mouse bindings. | |||||||||||||||
removeMouseBindings :: XConfig a -> [(ButtonMask, Button)] -> XConfig a | |||||||||||||||
Like removeKeys, but for mouse bindings. | |||||||||||||||
Emacs-style keybinding specifications | |||||||||||||||
mkKeymap :: XConfig l -> [(String, X ())] -> Map (KeyMask, KeySym) (X ()) | |||||||||||||||
Given a config (used to determine the proper modifier key to use) and a list of (String, X ()) pairs, create a key map by parsing the key sequence descriptions contained in the Strings. The key sequence descriptions are "emacs-style": M-, C-, S-, and M#- denote mod, control, shift, and mod1-mod5 (where # is replaced by the appropriate number) respectively; some special keys can be specified by enclosing their name in angle brackets. For example, "M-C-x" denotes mod+ctrl+x; "S-<Escape>" denotes shift-escape. Sequences of keys can also be specified by separating the key descriptions with spaces. For example, "M-x y <Down>" denotes the sequence of keys mod+x, y, down. Submaps (see XMonad.Actions.Submap) will be automatically generated to correctly handle these cases. So, for example, a complete key map might be specified as keys = \c -> mkKeymap c $ [ ("M-S-<Return>", spawn $ terminal c) , ("M-x w", spawn "xmessage 'woohoo!'") -- type mod+x then w to pop up 'woohoo!' , ("M-x y", spawn "xmessage 'yay!'") -- type mod+x then y to pop up 'yay!' , ("M-S-c", kill) ] Alternatively, you can use additionalKeysP to automatically create a keymap and add it to your config. Here is a complete list of supported special keys. Note that a few keys, such as the arrow keys, have synonyms: <Backspace> <Tab> <Return> <Pause> <Scroll_lock> <Sys_Req> <Escape>, <Esc> <Delete> <Home> <Left>, <L> <Up>, <U> <Right>, <R> <Down>, <D> <Page_Up> <Page_Down> <End> <Insert> <Break> <Space> <F1>-<F12> | |||||||||||||||
checkKeymap :: XConfig l -> [(String, a)] -> X () | |||||||||||||||
Given a configuration record and a list of (key sequence description, action) pairs, check the key sequence descriptions for validity, and warn the user (via a popup xmessage window) of any unparseable or duplicate key sequences. This function is appropriate for adding to your startupHook, and you are highly encouraged to do so; otherwise, duplicate or unparseable keybindings will be silently ignored. For example, you might do something like this: main = xmonad $ myConfig myKeymap = [("S-M-c", kill), ...] myConfig = defaultConfig { ... keys = \c -> mkKeymap c myKeymap startupHook = return () >> checkKeymap myConfig myKeymap ... } NOTE: the return () in the example above is very important! Otherwise, you might run into problems with infinite mutual recursion: the definition of myConfig depends on the definition of startupHook, which depends on the definition of myConfig, ... and so on. Actually, it's likely that the above example in particular would be OK without the return (), but making myKeymap take myConfig as a parameter would definitely lead to problems. Believe me. It, uh, happened to my friend. In... a dream. Yeah. In any event, the return () >> introduces enough laziness to break the deadlock. | |||||||||||||||
Produced by Haddock version 0.8 |