forked from colonelpanic/dotfiles
[XMonad] Add utility function section, write >>=/
This commit is contained in:
parent
cabbd09aa1
commit
670a0719dd
@ -62,6 +62,24 @@ main = xmonad $ def
|
|||||||
, keys = customKeys (const []) addKeys
|
, keys = customKeys (const []) addKeys
|
||||||
} where
|
} where
|
||||||
x +++ y = mappend y x
|
x +++ y = mappend y x
|
||||||
|
|
||||||
|
|
||||||
|
-- Utility functions
|
||||||
|
|
||||||
|
fork :: Monad m => (i -> m a) -> (i -> m b) -> i -> m (a, b)
|
||||||
|
fork a b input = do
|
||||||
|
resA <- a input
|
||||||
|
resB <- b input
|
||||||
|
return (resA, resB)
|
||||||
|
|
||||||
|
tee :: Monad m => (i -> m a) -> (i -> m b) -> i -> m a
|
||||||
|
tee = (fmap . fmap . fmap) (fmap fst) fork
|
||||||
|
|
||||||
|
(>>=/) :: Monad m => m a -> (a -> m b) -> m a
|
||||||
|
(>>=/) a = (a >>=) . tee return
|
||||||
|
|
||||||
|
findM :: (Monad m) => (a -> m (Maybe b)) -> [a] -> m (Maybe b)
|
||||||
|
findM f = runMaybeT . msum . map (MaybeT . f)
|
||||||
|
|
||||||
-- Selectors
|
-- Selectors
|
||||||
|
|
||||||
@ -145,13 +163,9 @@ selectToggle = togglesMap >>= DM.menuMapArgs "rofi" ["-dmenu", "-i"] >>=
|
|||||||
toggleInState :: (Transformer t Window) => t -> Maybe Bool -> X Bool
|
toggleInState :: (Transformer t Window) => t -> Maybe Bool -> X Bool
|
||||||
toggleInState t s = fmap (/= s) (isToggleActive t)
|
toggleInState t s = fmap (/= s) (isToggleActive t)
|
||||||
|
|
||||||
whenB b a = do
|
|
||||||
when b a
|
|
||||||
return b
|
|
||||||
|
|
||||||
setToggleActive' toggle active =
|
setToggleActive' toggle active =
|
||||||
toggleInState toggle (Just active) >>=
|
toggleInState toggle (Just active) >>=/
|
||||||
flip whenB (sendMessage $ Toggle toggle)
|
flip when (sendMessage $ Toggle toggle)
|
||||||
|
|
||||||
-- Ambiguous type reference without signature
|
-- Ambiguous type reference without signature
|
||||||
setToggleActive :: (Transformer t Window) => t -> Bool -> X ()
|
setToggleActive :: (Transformer t Window) => t -> Bool -> X ()
|
||||||
@ -196,9 +210,6 @@ myLayoutHook = avoidStruts . minimize . boringAuto . mkToggle1 MIRROR .
|
|||||||
|
|
||||||
-- WindowBringer
|
-- WindowBringer
|
||||||
|
|
||||||
findM :: (Monad m) => (a -> m (Maybe b)) -> [a] -> m (Maybe b)
|
|
||||||
findM f = runMaybeT . msum . map (MaybeT . f)
|
|
||||||
|
|
||||||
myWindowBringerConfig =
|
myWindowBringerConfig =
|
||||||
WindowBringerConfig { menuCommand = "rofi"
|
WindowBringerConfig { menuCommand = "rofi"
|
||||||
, menuArgs = ["-dmenu", "-i"]
|
, menuArgs = ["-dmenu", "-i"]
|
||||||
|
Loading…
Reference in New Issue
Block a user