aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad
diff options
context:
space:
mode:
authorSpencer Janssen <spencerjanssen@gmail.com>2009-11-07 18:38:20 +0100
committerSpencer Janssen <spencerjanssen@gmail.com>2009-11-07 18:38:20 +0100
commit90045d7d04b0b0529f25929ff32136741244dd98 (patch)
tree0aaa6a9f9a2324ed2a5234b975b4857d5c5fee96 /XMonad
parent9dc3d316e89770ddb9cf620ba95b2db8a8997aba (diff)
downloadXMonadContrib-90045d7d04b0b0529f25929ff32136741244dd98.tar.gz
XMonadContrib-90045d7d04b0b0529f25929ff32136741244dd98.tar.xz
XMonadContrib-90045d7d04b0b0529f25929ff32136741244dd98.zip
Add XMonad.Util.SpawnOnce
Ignore-this: 8d4657bbaa8dbeb1d0f9d22293bfef19 darcs-hash:20091107173820-25a6b-8e4628c65594acd51f2fc6f601b0c3092d7316d0.gz
Diffstat (limited to 'XMonad')
-rw-r--r--XMonad/Util/SpawnOnce.hs39
1 files changed, 39 insertions, 0 deletions
diff --git a/XMonad/Util/SpawnOnce.hs b/XMonad/Util/SpawnOnce.hs
new file mode 100644
index 0000000..edb3b5f
--- /dev/null
+++ b/XMonad/Util/SpawnOnce.hs
@@ -0,0 +1,39 @@
+{-# LANGUAGE DeriveDataTypeable #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonad.Util.ExtensibleState
+-- Copyright : (c) Spencer Janssen 2009
+-- License : BSD3-style (see LICENSE)
+--
+-- Maintainer : spencerjanssen@gmail.com
+-- Stability : unstable
+-- Portability : not portable
+--
+-- A module for spawning a command once, and only once. Useful to start
+-- status bars and make session settings inside startupHook.
+--
+-----------------------------------------------------------------------------
+
+module XMonad.Util.SpawnOnce (spawnOnce) where
+
+import XMonad
+import Data.Set as Set
+import XMonad.Util.ExtensibleState
+import Control.Monad
+
+data SpawnOnce = SpawnOnce { unspawnOnce :: (Set String) }
+ deriving (Read, Show, Typeable)
+
+instance ExtensionClass SpawnOnce where
+ initialValue = SpawnOnce $ Set.empty
+ extensionType = PersistentExtension
+
+-- | The first time 'spawnOnce' is executed on a particular command, that
+-- command is executed. Subsequent invocations for a command do nothing.
+spawnOnce :: String -> X ()
+spawnOnce xs = do
+ b <- fmap (Set.member xs . unspawnOnce) $ getState
+ when (not b) $ do
+ spawn xs
+ modifyState (SpawnOnce . Set.insert xs . unspawnOnce)