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]
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
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 forall a. Set a
Set.empty
extensionType :: SpawnOnce -> StateExtension
extensionType = 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 <- forall a (m :: * -> *) b.
(ExtensionClass a, XLike m) =>
(a -> b) -> m b
XS.gets (forall a. Ord a => a -> Set a -> Bool
Set.member String
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. SpawnOnce -> Set String
unspawnOnce)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
b forall a b. (a -> b) -> a -> b
$ do
String -> X ()
f String
s
forall a (m :: * -> *).
(ExtensionClass a, XLike m) =>
(a -> a) -> m ()
XS.modify (Set String -> SpawnOnce
SpawnOnce forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => a -> Set a -> Set a
Set.insert String
s 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 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 (forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_ Int
n 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)