From fe55d0845c351e8ca15dcb4aade79fbda671f221 Mon Sep 17 00:00:00 2001 From: "Valery V. Vorotyntsev" Date: Wed, 14 Nov 2007 16:34:18 +0100 Subject: CustomKeys.hs: moved into `Util' directory I still wonder why do we need all those configuration examples. :) darcs-hash:20071114153418-ae588-f5280e0c2f0de7aebec97b81f934b2529aba4f0f.gz --- XMonad/Config/CustomKeys.hs | 76 --------------------------------------------- XMonad/Util/CustomKeys.hs | 76 +++++++++++++++++++++++++++++++++++++++++++++ XMonad/Util/EZConfig.hs | 2 +- 3 files changed, 77 insertions(+), 77 deletions(-) delete mode 100644 XMonad/Config/CustomKeys.hs create mode 100644 XMonad/Util/CustomKeys.hs (limited to 'XMonad') diff --git a/XMonad/Config/CustomKeys.hs b/XMonad/Config/CustomKeys.hs deleted file mode 100644 index a35ec97..0000000 --- a/XMonad/Config/CustomKeys.hs +++ /dev/null @@ -1,76 +0,0 @@ --------------------------------------------------------------------- --- | --- Module : XMonad.Config.CustomKeys --- Copyright : (c) 2007 Valery V. Vorotyntsev --- License : BSD3-style (see LICENSE) --- --- Maintainer : Valery V. Vorotynsev --- --- Customized key bindings. --- --- (See also "XMonad.Util.EZConfig" in xmonad-contrib.) --------------------------------------------------------------------- - -module XMonad.Config.CustomKeys ( - -- * Usage - -- $usage - customKeys - , customKeysFrom - ) where - -import XMonad -import Graphics.X11.Xlib - -import Control.Monad.Reader -import qualified Data.Map as M - --- $usage --- --- 1. In @~\/.xmonad\/xmonad.hs@ add: --- --- > import XMonad.Config.CustomKeys --- --- 2. Set key bindings with 'customKeys': --- --- > main = xmonad defaultConfig { keys = customKeys delkeys inskeys } --- > where --- > delkeys :: XConfig l -> [(KeyMask, KeySym)] --- > delkeys XConfig {modMask = modm} = --- > -- we're preferring Futurama to Xinerama here --- > [ (modm .|. m, k) | (m, k) <- zip [0, shiftMas] [xK_w, xK_e, xK_r] ] --- > --- > inskeys :: XConfig l -> [((KeyMask, KeySym), X ())] --- > inskeys conf@(XConfig {modMask = modm}) = --- > [ ((mod1Mask, xK_F2 ), spawn $ terminal conf) --- > , ((modm .|. controlMask, xK_F11 ), spawn "xscreensaver-command -lock") --- > , ((mod1Mask, xK_Down), spawn "amixer set Master 1-") --- > , ((mod1Mask, xK_Up ), spawn "amixer set Master 1+") --- > ] - --- | Customize 'XMonad.Config.defaultConfig' -- delete needless --- shortcuts and insert the ones you use. -customKeys :: (XConfig Layout -> [(KeyMask, KeySym)]) -- ^ shortcuts to delete - -> (XConfig Layout -> [((KeyMask, KeySym), X ())]) -- ^ key bindings to insert - -> XConfig Layout -> M.Map (KeyMask, KeySym) (X ()) -customKeys = customKeysFrom defaultConfig - --- | General variant of 'customKeys': customize key bindings of --- third-party configuration. -customKeysFrom :: XConfig l -- ^ original configuration - -> (XConfig Layout -> [(KeyMask, KeySym)]) -- ^ shortcuts to delete - -> (XConfig Layout -> [((KeyMask, KeySym), X ())]) -- ^ key bindings to insert - -> XConfig Layout -> M.Map (KeyMask, KeySym) (X ()) -customKeysFrom conf = (runReader .) . customize conf - -customize :: XConfig l - -> (XConfig Layout -> [(KeyMask, KeySym)]) - -> (XConfig Layout -> [((KeyMask, KeySym), X ())]) - -> Reader (XConfig Layout) (M.Map (KeyMask, KeySym) (X ())) -customize conf ds is = Reader (keys conf) >>= delete ds >>= insert is - -delete :: (MonadReader r m, Ord a) => (r -> [a]) -> M.Map a b -> m (M.Map a b) -delete dels kmap = asks dels >>= return . foldr M.delete kmap - -insert :: (MonadReader r m, Ord a) => - (r -> [(a, b)]) -> M.Map a b -> m (M.Map a b) -insert ins kmap = asks ins >>= return . foldr (uncurry M.insert) kmap diff --git a/XMonad/Util/CustomKeys.hs b/XMonad/Util/CustomKeys.hs new file mode 100644 index 0000000..7c7a239 --- /dev/null +++ b/XMonad/Util/CustomKeys.hs @@ -0,0 +1,76 @@ +-------------------------------------------------------------------- +-- | +-- Module : XMonad.Util.CustomKeys +-- Copyright : (c) 2007 Valery V. Vorotyntsev +-- License : BSD3-style (see LICENSE) +-- +-- Maintainer : Valery V. Vorotynsev +-- +-- Customized key bindings. +-- +-- (See also "XMonad.Util.EZConfig" in xmonad-contrib.) +-------------------------------------------------------------------- + +module XMonad.Util.CustomKeys ( + -- * Usage + -- $usage + customKeys + , customKeysFrom + ) where + +import XMonad +import Graphics.X11.Xlib + +import Control.Monad.Reader +import qualified Data.Map as M + +-- $usage +-- +-- 1. In @~\/.xmonad\/xmonad.hs@ add: +-- +-- > import XMonad.Util.CustomKeys +-- +-- 2. Set key bindings with 'customKeys': +-- +-- > main = xmonad defaultConfig { keys = customKeys delkeys inskeys } +-- > where +-- > delkeys :: XConfig l -> [(KeyMask, KeySym)] +-- > delkeys XConfig {modMask = modm} = +-- > -- we're preferring Futurama to Xinerama here +-- > [ (modm .|. m, k) | (m, k) <- zip [0, shiftMas] [xK_w, xK_e, xK_r] ] +-- > +-- > inskeys :: XConfig l -> [((KeyMask, KeySym), X ())] +-- > inskeys conf@(XConfig {modMask = modm}) = +-- > [ ((mod1Mask, xK_F2 ), spawn $ terminal conf) +-- > , ((modm .|. controlMask, xK_F11 ), spawn "xscreensaver-command -lock") +-- > , ((mod1Mask, xK_Down), spawn "amixer set Master 1-") +-- > , ((mod1Mask, xK_Up ), spawn "amixer set Master 1+") +-- > ] + +-- | Customize 'XMonad.Config.defaultConfig' -- delete needless +-- shortcuts and insert those you will use. +customKeys :: (XConfig Layout -> [(KeyMask, KeySym)]) -- ^ shortcuts to delete + -> (XConfig Layout -> [((KeyMask, KeySym), X ())]) -- ^ key bindings to insert + -> XConfig Layout -> M.Map (KeyMask, KeySym) (X ()) +customKeys = customKeysFrom defaultConfig + +-- | General variant of 'customKeys': customize key bindings of +-- third-party configuration. +customKeysFrom :: XConfig l -- ^ original configuration + -> (XConfig Layout -> [(KeyMask, KeySym)]) -- ^ shortcuts to delete + -> (XConfig Layout -> [((KeyMask, KeySym), X ())]) -- ^ key bindings to insert + -> XConfig Layout -> M.Map (KeyMask, KeySym) (X ()) +customKeysFrom conf = (runReader .) . customize conf + +customize :: XConfig l + -> (XConfig Layout -> [(KeyMask, KeySym)]) + -> (XConfig Layout -> [((KeyMask, KeySym), X ())]) + -> Reader (XConfig Layout) (M.Map (KeyMask, KeySym) (X ())) +customize conf ds is = Reader (keys conf) >>= delete ds >>= insert is + +delete :: (MonadReader r m, Ord a) => (r -> [a]) -> M.Map a b -> m (M.Map a b) +delete dels kmap = asks dels >>= return . foldr M.delete kmap + +insert :: (MonadReader r m, Ord a) => + (r -> [(a, b)]) -> M.Map a b -> m (M.Map a b) +insert ins kmap = asks ins >>= return . foldr (uncurry M.insert) kmap diff --git a/XMonad/Util/EZConfig.hs b/XMonad/Util/EZConfig.hs index 3690f98..903a39e 100644 --- a/XMonad/Util/EZConfig.hs +++ b/XMonad/Util/EZConfig.hs @@ -8,7 +8,7 @@ -- -- Useful helper functions for amending the defaultConfig. -- --- (See also "XMonad.Config.CustomKeys" in xmonad-contrib.) +-- (See also "XMonad.Util.CustomKeys" in xmonad-contrib.) -- -------------------------------------------------------------------- -- cgit v1.2.3