module XMonad.Util.SpawnOnce (spawnOnce,
manageSpawn,
spawnOnOnce,
spawnNOnOnce,
spawnAndDoOnce) where
import XMonad
import XMonad.Actions.SpawnOn
import Data.Set as Set
import qualified XMonad.Util.ExtensibleState as XS
import XMonad.Prelude
newtype SpawnOnce = SpawnOnce { SpawnOnce -> Set String
unspawnOnce :: Set String }
deriving (ReadPrec [SpawnOnce]
ReadPrec SpawnOnce
Int -> ReadS SpawnOnce
ReadS [SpawnOnce]
(Int -> ReadS SpawnOnce)
-> ReadS [SpawnOnce]
-> ReadPrec SpawnOnce
-> ReadPrec [SpawnOnce]
-> Read SpawnOnce
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SpawnOnce]
$creadListPrec :: ReadPrec [SpawnOnce]
readPrec :: ReadPrec SpawnOnce
$creadPrec :: ReadPrec SpawnOnce
readList :: ReadS [SpawnOnce]
$creadList :: ReadS [SpawnOnce]
readsPrec :: Int -> ReadS SpawnOnce
$creadsPrec :: Int -> ReadS SpawnOnce
Read, Int -> SpawnOnce -> ShowS
[SpawnOnce] -> ShowS
SpawnOnce -> String
(Int -> SpawnOnce -> ShowS)
-> (SpawnOnce -> String)
-> ([SpawnOnce] -> ShowS)
-> Show SpawnOnce
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SpawnOnce] -> ShowS
$cshowList :: [SpawnOnce] -> ShowS
show :: SpawnOnce -> String
$cshow :: SpawnOnce -> String
showsPrec :: Int -> SpawnOnce -> ShowS
$cshowsPrec :: Int -> SpawnOnce -> ShowS
Show)
instance ExtensionClass SpawnOnce where
initialValue :: SpawnOnce
initialValue = Set String -> SpawnOnce
SpawnOnce Set String
forall a. Set a
Set.empty
extensionType :: SpawnOnce -> StateExtension
extensionType = SpawnOnce -> StateExtension
forall a. (Read a, Show a, ExtensionClass a) => a -> StateExtension
PersistentExtension
doOnce :: (String -> X ()) -> String -> X ()
doOnce :: (String -> X ()) -> String -> X ()
doOnce String -> X ()
f String
s = do
Bool
b <- (SpawnOnce -> Bool) -> X Bool
forall a (m :: * -> *) b.
(ExtensionClass a, XLike m) =>
(a -> b) -> m b
XS.gets (String -> Set String -> Bool
forall a. Ord a => a -> Set a -> Bool
Set.member String
s (Set String -> Bool)
-> (SpawnOnce -> Set String) -> SpawnOnce -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SpawnOnce -> Set String
unspawnOnce)
Bool -> X () -> X ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
b (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ do
String -> X ()
f String
s
(SpawnOnce -> SpawnOnce) -> X ()
forall a (m :: * -> *).
(ExtensionClass a, XLike m) =>
(a -> a) -> m ()
XS.modify (Set String -> SpawnOnce
SpawnOnce (Set String -> SpawnOnce)
-> (SpawnOnce -> Set String) -> SpawnOnce -> SpawnOnce
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Set String -> Set String
forall a. Ord a => a -> Set a -> Set a
Set.insert String
s (Set String -> Set String)
-> (SpawnOnce -> Set String) -> SpawnOnce -> Set String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SpawnOnce -> Set String
unspawnOnce)
spawnOnce :: String -> X ()
spawnOnce :: String -> X ()
spawnOnce = (String -> X ()) -> String -> X ()
doOnce String -> X ()
forall (m :: * -> *). MonadIO m => String -> m ()
spawn
spawnOnOnce :: WorkspaceId -> String -> X ()
spawnOnOnce :: String -> String -> X ()
spawnOnOnce String
ws = (String -> X ()) -> String -> X ()
doOnce (String -> String -> X ()
spawnOn String
ws)
spawnNOnOnce :: Int -> WorkspaceId -> String -> X ()
spawnNOnOnce :: Int -> String -> String -> X ()
spawnNOnOnce Int
n String
ws = (String -> X ()) -> String -> X ()
doOnce (Int -> X () -> X ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
n (X () -> X ()) -> (String -> X ()) -> String -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String -> X ()
spawnOn String
ws)
spawnAndDoOnce :: ManageHook -> String -> X ()
spawnAndDoOnce :: ManageHook -> String -> X ()
spawnAndDoOnce ManageHook
mh = (String -> X ()) -> String -> X ()
doOnce (ManageHook -> String -> X ()
spawnAndDo ManageHook
mh)