XMonad.Util.EZConfig: minor cleanups

This commit is contained in:
Lukas Mai
2008-05-28 16:54:50 +00:00
parent 389e23b979
commit 4dc9baca48

View File

@@ -35,7 +35,7 @@ import XMonad.Actions.Submap
import qualified Data.Map as M import qualified Data.Map as M
import Data.List (foldl', intersperse, sortBy, groupBy, nub) import Data.List (foldl', intersperse, sortBy, groupBy, nub)
import Data.Ord (comparing) import Data.Ord (comparing)
import Data.Maybe (catMaybes, isNothing, isJust, fromJust) import Data.Maybe
import Control.Arrow (first, (&&&)) import Control.Arrow (first, (&&&))
import Text.ParserCombinators.ReadP import Text.ParserCombinators.ReadP
@@ -205,16 +205,14 @@ op `on` f = \x y -> f x `op` f y
-- @(KeyMask,KeySym)@ pairs. Key sequences which fail to parse will -- @(KeyMask,KeySym)@ pairs. Key sequences which fail to parse will
-- be ignored. -- be ignored.
readKeymap :: XConfig l -> [(String, X())] -> [([(KeyMask,KeySym)], X())] readKeymap :: XConfig l -> [(String, X())] -> [([(KeyMask,KeySym)], X())]
readKeymap c = catMaybes . map (maybeKeys . first (readKeySequence c)) readKeymap c = mapMaybe (maybeKeys . first (readKeySequence c))
where maybeKeys (Nothing,_) = Nothing where maybeKeys (Nothing,_) = Nothing
maybeKeys (Just k, act) = Just (k, act) maybeKeys (Just k, act) = Just (k, act)
-- | Parse a sequence of keys, returning Nothing if there is -- | Parse a sequence of keys, returning Nothing if there is
-- a parse failure (no parse, or ambiguous parse). -- a parse failure (no parse, or ambiguous parse).
readKeySequence :: XConfig l -> String -> Maybe [(KeyMask, KeySym)] readKeySequence :: XConfig l -> String -> Maybe [(KeyMask, KeySym)]
readKeySequence c s = case parses s of readKeySequence c = listToMaybe . parses
[k] -> Just k
_ -> Nothing
where parses = map fst . filter (null.snd) . readP_to_S (parseKeySequence c) where parses = map fst . filter (null.snd) . readP_to_S (parseKeySequence c)
-- | Parse a sequence of key combinations separated by spaces, e.g. -- | Parse a sequence of key combinations separated by spaces, e.g.
@@ -271,8 +269,8 @@ functionKeys = [ ("F" ++ show n, k)
-- | A list of special key names and their corresponding KeySyms. -- | A list of special key names and their corresponding KeySyms.
specialKeys :: [(String, KeySym)] specialKeys :: [(String, KeySym)]
specialKeys = [ ("Backspace", xK_BackSpace) specialKeys = [ ("Backspace" , xK_BackSpace)
, ("Tab" , xK_Tab ) , ("Tab" , xK_Tab)
, ("Return" , xK_Return) , ("Return" , xK_Return)
, ("Pause" , xK_Pause) , ("Pause" , xK_Pause)
, ("Scroll_lock", xK_Scroll_Lock) , ("Scroll_lock", xK_Scroll_Lock)
@@ -290,7 +288,7 @@ specialKeys = [ ("Backspace", xK_BackSpace)
, ("R" , xK_Right) , ("R" , xK_Right)
, ("D" , xK_Down) , ("D" , xK_Down)
, ("Page_Up" , xK_Page_Up) , ("Page_Up" , xK_Page_Up)
, ("Page_Down", xK_Page_Down) , ("Page_Down" , xK_Page_Down)
, ("End" , xK_End) , ("End" , xK_End)
, ("Insert" , xK_Insert) , ("Insert" , xK_Insert)
, ("Break" , xK_Break) , ("Break" , xK_Break)