diff options
author | Adam Vogt <vogt.adam@gmail.com> | 2009-06-23 07:25:37 +0200 |
---|---|---|
committer | Adam Vogt <vogt.adam@gmail.com> | 2009-06-23 07:25:37 +0200 |
commit | 36fe458e23e119cd91c09f6ec66fe487eebec839 (patch) | |
tree | a0475f4439c79dcc4b20e33bad581b144b91626f /XMonad/Util/StringProp.hs | |
parent | d2d43db0c91a83f8279c1b5faaa15503360d6a25 (diff) | |
download | XMonadContrib-36fe458e23e119cd91c09f6ec66fe487eebec839.tar.gz XMonadContrib-36fe458e23e119cd91c09f6ec66fe487eebec839.tar.xz XMonadContrib-36fe458e23e119cd91c09f6ec66fe487eebec839.zip |
From A.Topicspace split functions for storing strings with root to U.StringProp
Ignore-this: 543b172fbefa9feded94d792d01921c4
These functions will be used to send strings for execution by command line, in
xmonad-eval
darcs-hash:20090623052537-1499c-d985ff1de9431dd80a88ae87015e5e4c1b27aa46.gz
Diffstat (limited to '')
-rw-r--r-- | XMonad/Util/StringProp.hs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/XMonad/Util/StringProp.hs b/XMonad/Util/StringProp.hs new file mode 100644 index 0000000..2cf26d7 --- /dev/null +++ b/XMonad/Util/StringProp.hs @@ -0,0 +1,56 @@ +----------------------------------------------------------------------------- +-- | +-- Module : XMonad.Util.StringProp +-- Copyright : (c) Nicolas Pouillard 2009 +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Nicolas Pouillard <nicolas.pouillard@gmail.com> +-- Stability : unstable +-- Portability : unportable +-- +-- Internal utility functions for storing Strings with the root window. +-- +-- Used for global state like IORefs with string keys, but more latency, +-- persistent between xmonad restarts. + +module XMonad.Util.StringProp ( + StringProp, + getStringProp, setStringProp, + getStringListProp, setStringListProp, + ) where + +import XMonad +import Control.Monad(liftM) +import Control.Applicative((<$>)) +import Foreign.C.String (castCCharToChar,castCharToCChar) + +type StringProp = String + +withStringProp :: (MonadIO m) => StringProp -> Display -> (Window -> Atom -> m b) -> m b +withStringProp prop dpy f = do + rootw <- io $ rootWindow dpy $ defaultScreen dpy + a <- io $ internAtom dpy prop False + f rootw a + +-- | Set the value of a string property. +setStringProp :: (MonadIO m) => Display -> StringProp -> [Char] -> m () +setStringProp dpy prop string = + withStringProp prop dpy $ \rootw a -> + io $ changeProperty8 dpy rootw a a propModeReplace $ map castCharToCChar string + +-- | Get the name of a string property and returns it as a 'Maybe'. +getStringProp :: (MonadIO m) => Display -> StringProp -> m (Maybe [Char]) +getStringProp dpy prop = + withStringProp prop dpy $ \rootw a -> do + p <- io $ getWindowProperty8 dpy a rootw + return $ map castCCharToChar <$> p + +-- | Given a property name, returns its contents as a list. It uses the empty +-- list as default value. +getStringListProp :: (MonadIO m) => Display -> StringProp -> m [String] +getStringListProp dpy prop = maybe [] words `liftM` getStringProp dpy prop + +-- | Given a property name and a list, sets the value of this property with +-- the list given as argument. +setStringListProp :: (MonadIO m) => Display -> StringProp -> [String] -> m () +setStringListProp dpy prop str = setStringProp dpy prop (unwords str) |