aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad
diff options
context:
space:
mode:
authorAdam Vogt <vogt.adam@gmail.com>2009-06-23 07:25:37 +0200
committerAdam Vogt <vogt.adam@gmail.com>2009-06-23 07:25:37 +0200
commit36fe458e23e119cd91c09f6ec66fe487eebec839 (patch)
treea0475f4439c79dcc4b20e33bad581b144b91626f /XMonad
parentd2d43db0c91a83f8279c1b5faaa15503360d6a25 (diff)
downloadXMonadContrib-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 'XMonad')
-rw-r--r--XMonad/Actions/TopicSpace.hs47
-rw-r--r--XMonad/Util/StringProp.hs56
2 files changed, 62 insertions, 41 deletions
diff --git a/XMonad/Actions/TopicSpace.hs b/XMonad/Actions/TopicSpace.hs
index 62cf675..7e4bf05 100644
--- a/XMonad/Actions/TopicSpace.hs
+++ b/XMonad/Actions/TopicSpace.hs
@@ -172,13 +172,10 @@ import Data.List
import Data.Maybe (fromMaybe, isNothing, listToMaybe)
import Data.Ord
import qualified Data.Map as M
-import Graphics.X11.Xlib
import Control.Monad ((=<<),liftM2,when,unless,replicateM_)
import System.IO
-import Foreign.C.String (castCCharToChar,castCharToCChar)
import XMonad.Operations
-import Control.Applicative ((<$>))
import qualified XMonad.StackSet as W
import XMonad.Prompt
@@ -189,6 +186,7 @@ import XMonad.Hooks.DynamicLog (PP(..))
import qualified XMonad.Hooks.DynamicLog as DL
import XMonad.Util.Run (spawnPipe)
+import XMonad.Util.StringProp(getStringListProp,setStringListProp)
-- | An alias for @flip replicateM_@
(>*>) :: Monad m => m a -> Int -> m ()
@@ -220,16 +218,16 @@ data TopicConfig = TopicConfig { topicDirs :: M.Map Topic Dir
-- | Returns the list of last focused workspaces the empty list otherwise.
-- This function rely on a reserved property namely _XMONAD_LAST_FOCUSED_WORKSPACES.
getLastFocusedTopics :: X [String]
-getLastFocusedTopics = getStringListProp "_XMONAD_LAST_FOCUSED_WORKSPACES"
+getLastFocusedTopics = asks display >>= flip getStringListProp "_XMONAD_LAST_FOCUSED_WORKSPACES"
-- | Given a 'TopicConfig', the last focused topic, and a predicate that will
-- select topics that one want to keep, this function will set the property
-- of last focused topics.
setLastFocusedTopic :: TopicConfig -> Topic -> (Topic -> Bool) -> X ()
-setLastFocusedTopic tg w predicate =
- getLastFocusedTopics >>=
- setStringListProp "_XMONAD_LAST_FOCUSED_WORKSPACES"
- . take (maxTopicHistory tg) . nub . (w:) . filter predicate
+setLastFocusedTopic tg w predicate = do
+ disp <- asks display
+ setStringListProp disp "_XMONAD_LAST_FOCUSED_WORKSPACES"
+ . take (maxTopicHistory tg) . nub . (w:) . filter predicate =<< getLastFocusedTopics
-- | This function is a variant of 'DL.pprWindowSet' which takes a topic configuration
-- and a pretty-printing record 'PP'. It will show the list of topics sorted historically
@@ -301,42 +299,9 @@ checkTopicConfig tags tg = do
check diffTopic "Seen but missing topics/workspaces"
check dups "Duplicate topics/workspaces"
-type StringProp = String
-
-withStringProp :: StringProp -> (Display -> Window -> Atom -> X a) -> X a
-withStringProp prop f =
- withDisplay $ \dpy -> do
- rootw <- asks theRoot
- a <- io $ internAtom dpy prop False
- f dpy rootw a
-
--- | Get the name of a string property and returns it as a 'Maybe'.
-getStringProp :: StringProp -> X (Maybe String)
-getStringProp prop =
- withStringProp prop $ \dpy rootw a -> do
- p <- io $ getWindowProperty8 dpy a rootw
- return $ map castCCharToChar <$> p
-
--- | Set the value of a string property.
-setStringProp :: StringProp -> String -> X ()
-setStringProp prop string =
- withStringProp prop $ \dpy rootw a ->
- io $ changeProperty8 dpy rootw a a propModeReplace $ map castCharToCChar string
-
--- | Given a property name, returns its contents as a list. It uses the empty
--- list as default value.
-getStringListProp :: StringProp -> X [String]
-getStringListProp prop = return . maybe [] words =<< getStringProp prop
-
--- | Given a property name and a list, sets the value of this property with
--- the list given as argument.
-setStringListProp :: StringProp -> [String] -> X ()
-setStringListProp prop = setStringProp prop . unwords
-
-- | Display the given message using the @xmessage@ program.
xmessage :: String -> IO ()
xmessage s = do
h <- spawnPipe "xmessage -file -"
hPutStr h s
hClose h
-
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)