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
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
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
getStringListProp :: (MonadIO m) => Display -> StringProp -> m [String]
getStringListProp dpy prop = maybe [] words `liftM` getStringProp dpy prop
setStringListProp :: (MonadIO m) => Display -> StringProp -> [String] -> m ()
setStringListProp dpy prop str = setStringProp dpy prop (unwords str)