Remove trailing whitespace in A.KeyRemap

This commit is contained in:
Adam Vogt 2010-05-03 15:32:58 +00:00
parent 99e5a4393f
commit b21208dad7

View File

@ -20,7 +20,7 @@ module XMonad.Actions.KeyRemap (
setKeyRemap, setKeyRemap,
buildKeyRemapBindings, buildKeyRemapBindings,
setDefaultKeyRemap, setDefaultKeyRemap,
KeymapTable (KeymapTable), KeymapTable (KeymapTable),
emptyKeyRemap, emptyKeyRemap,
dvorakProgrammerKeyRemap dvorakProgrammerKeyRemap
@ -38,7 +38,7 @@ data KeymapTable = KeymapTable [((KeyMask, KeySym), (KeyMask, KeySym))] deriving
instance ExtensionClass KeymapTable where instance ExtensionClass KeymapTable where
initialValue = KeymapTable [] initialValue = KeymapTable []
-- $usage -- $usage
-- Provides the possibility to remap parts of the keymap to generate different keys -- Provides the possibility to remap parts of the keymap to generate different keys
-- --
@ -49,11 +49,11 @@ instance ExtensionClass KeymapTable where
-- --
-- > keys = myKeys ++ buildKeyRemapBindings [dvorakProgrammerKeyRemap,emptyKeyRemap] -- > keys = myKeys ++ buildKeyRemapBindings [dvorakProgrammerKeyRemap,emptyKeyRemap]
-- --
-- Then you must add setDefaultKeyRemap to your startup hook (e.g. you want to set the -- Then you must add setDefaultKeyRemap to your startup hook (e.g. you want to set the
-- empty keyremap (no remapping is done) as default after startup): -- empty keyremap (no remapping is done) as default after startup):
-- --
-- > myStartupHook :: X() -- > myStartupHook :: X()
-- > myStartupHook = do -- > myStartupHook = do
-- > setWMName "LG3D" -- > setWMName "LG3D"
-- > setDefaultKeyRemap emptyKeyRemap [dvorakProgrammerKeyRemap, emptyKeyRemap] -- > setDefaultKeyRemap emptyKeyRemap [dvorakProgrammerKeyRemap, emptyKeyRemap]
-- --
@ -69,7 +69,7 @@ instance ExtensionClass KeymapTable where
-- > KeymapTable [((0, xK_a), (shiftMask, xK_5))] -- would bind 'a' to '%' -- > KeymapTable [((0, xK_a), (shiftMask, xK_5))] -- would bind 'a' to '%'
-- > KeymapTable [((shiftMask, xK_a), (0, xK_5))] -- would bind 'A' to '5' -- > KeymapTable [((shiftMask, xK_a), (0, xK_5))] -- would bind 'A' to '5'
-- --
-- * the dvorakProgrammerKeyRemap uses the original us layout as lookuptable to generate -- * the dvorakProgrammerKeyRemap uses the original us layout as lookuptable to generate
-- the KeymapTable -- the KeymapTable
-- --
-- * KeySym and (ord Char) are incompatible, therefore the magic numbers in dvorakProgrammerKeyRemap -- * KeySym and (ord Char) are incompatible, therefore the magic numbers in dvorakProgrammerKeyRemap
@ -80,31 +80,31 @@ doKeyRemap mask sym = do
table <- XS.get table <- XS.get
let (insertMask, insertSym) = extractKeyMapping table mask sym let (insertMask, insertSym) = extractKeyMapping table mask sym
sendKey insertMask insertSym sendKey insertMask insertSym
-- | Using this in the keybindings to set the actual Key Translation table -- | Using this in the keybindings to set the actual Key Translation table
setKeyRemap :: KeymapTable -> X() setKeyRemap :: KeymapTable -> X()
setKeyRemap table = do setKeyRemap table = do
let KeymapTable newtable = table let KeymapTable newtable = table
KeymapTable oldtable <- XS.get KeymapTable oldtable <- XS.get
XConf { display = dpy, theRoot = rootw } <- ask XConf { display = dpy, theRoot = rootw } <- ask
let grab kc m = io $ grabKey dpy kc m rootw True grabModeAsync grabModeAsync let grab kc m = io $ grabKey dpy kc m rootw True grabModeAsync grabModeAsync
let ungrab kc m = io $ ungrabKey dpy kc m rootw let ungrab kc m = io $ ungrabKey dpy kc m rootw
forM_ oldtable $ \((mask, sym), _) -> do forM_ oldtable $ \((mask, sym), _) -> do
kc <- io $ keysymToKeycode dpy sym kc <- io $ keysymToKeycode dpy sym
-- "If the specified KeySym is not defined for any KeyCode, -- "If the specified KeySym is not defined for any KeyCode,
-- XKeysymToKeycode() returns zero." -- XKeysymToKeycode() returns zero."
when (kc /= 0) $ ungrab kc mask when (kc /= 0) $ ungrab kc mask
forM_ newtable $ \((mask, sym), _) -> do forM_ newtable $ \((mask, sym), _) -> do
kc <- io $ keysymToKeycode dpy sym kc <- io $ keysymToKeycode dpy sym
-- "If the specified KeySym is not defined for any KeyCode, -- "If the specified KeySym is not defined for any KeyCode,
-- XKeysymToKeycode() returns zero." -- XKeysymToKeycode() returns zero."
when (kc /= 0) $ grab kc mask when (kc /= 0) $ grab kc mask
XS.put table XS.put table
-- | Adding this to your startupHook, to select your default Key Translation table. -- | Adding this to your startupHook, to select your default Key Translation table.
-- You also must give it all the KeymapTables you are willing to use -- You also must give it all the KeymapTables you are willing to use
setDefaultKeyRemap :: KeymapTable -> [KeymapTable] -> X() setDefaultKeyRemap :: KeymapTable -> [KeymapTable] -> X()
@ -115,20 +115,20 @@ setDefaultKeyRemap dflt keyremaps = do
mappings = nub (keyremaps >>= \(KeymapTable table) -> table) mappings = nub (keyremaps >>= \(KeymapTable table) -> table)
extractKeyMapping :: KeymapTable -> KeyMask -> KeySym -> (KeyMask, KeySym) extractKeyMapping :: KeymapTable -> KeyMask -> KeySym -> (KeyMask, KeySym)
extractKeyMapping (KeymapTable table) mask sym = extractKeyMapping (KeymapTable table) mask sym =
insertKey filtered insertKey filtered
where filtered = filter (\((m, s),_) -> m == mask && s == sym) table where filtered = filter (\((m, s),_) -> m == mask && s == sym) table
insertKey [] = (mask, sym) insertKey [] = (mask, sym)
insertKey ((_, to):_) = to insertKey ((_, to):_) = to
-- | Append the output of this function to your keybindings with ++ -- | Append the output of this function to your keybindings with ++
buildKeyRemapBindings :: [KeymapTable] -> [((KeyMask, KeySym), X ())] buildKeyRemapBindings :: [KeymapTable] -> [((KeyMask, KeySym), X ())]
buildKeyRemapBindings keyremaps = buildKeyRemapBindings keyremaps =
[((mask, sym), doKeyRemap mask sym) | (mask, sym) <- bindings] [((mask, sym), doKeyRemap mask sym) | (mask, sym) <- bindings]
where mappings = concat (map (\(KeymapTable table) -> table) keyremaps) where mappings = concat (map (\(KeymapTable table) -> table) keyremaps)
bindings = nub (map (\binding -> fst binding) mappings) bindings = nub (map (\binding -> fst binding) mappings)
-- Here come the Keymappings -- Here come the Keymappings
-- | The empty KeymapTable, does no translation -- | The empty KeymapTable, does no translation
emptyKeyRemap :: KeymapTable emptyKeyRemap :: KeymapTable
@ -136,17 +136,17 @@ emptyKeyRemap = KeymapTable []
-- | The dvorak Programmers keymap, translates from us keybindings to dvorak programmers -- | The dvorak Programmers keymap, translates from us keybindings to dvorak programmers
dvorakProgrammerKeyRemap :: KeymapTable dvorakProgrammerKeyRemap :: KeymapTable
dvorakProgrammerKeyRemap = dvorakProgrammerKeyRemap =
KeymapTable [((charToMask maskFrom, from), (charToMask maskTo, to)) | KeymapTable [((charToMask maskFrom, from), (charToMask maskTo, to)) |
(maskFrom, from, maskTo, to) <- (zip4 layoutUsShift layoutUsKey layoutDvorakShift layoutDvorakKey)] (maskFrom, from, maskTo, to) <- (zip4 layoutUsShift layoutUsKey layoutDvorakShift layoutDvorakKey)]
where where
layoutUs = map (fromIntegral . fromEnum) "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?" :: [KeySym] layoutUs = map (fromIntegral . fromEnum) "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?" :: [KeySym]
layoutUsKey = map (fromIntegral . fromEnum) "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./" :: [KeySym] layoutUsKey = map (fromIntegral . fromEnum) "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./" :: [KeySym]
layoutUsShift = "0000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111" layoutUsShift = "0000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111"
layoutDvorak = map (fromIntegral . fromEnum) "$&[{}(=*)+]!#;,.pyfgcrl/@\\aoeuidhtns-'qjkxbmwvz~%7531902468`:<>PYFGCRL?^|AOEUIDHTNS_\"QJKXBMWVZ" :: [KeySym] layoutDvorak = map (fromIntegral . fromEnum) "$&[{}(=*)+]!#;,.pyfgcrl/@\\aoeuidhtns-'qjkxbmwvz~%7531902468`:<>PYFGCRL?^|AOEUIDHTNS_\"QJKXBMWVZ" :: [KeySym]
layoutDvorakShift = map getShift layoutDvorak layoutDvorakShift = map getShift layoutDvorak
layoutDvorakKey = map getKey layoutDvorak layoutDvorakKey = map getKey layoutDvorak
getKey char = let Just index = elemIndex char layoutUs getKey char = let Just index = elemIndex char layoutUs