diff --git a/CHANGES.md b/CHANGES.md index 5c071a1c..56213950 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -92,6 +92,10 @@ Do not overwrite wm name in `handleFocusQuery`, if user has already set it. + * `XMonad.Hooks.ManageHelpers` + + Make type of ManageHook combinators more general. + ## 0.12 (December 14, 2015) ### Breaking Changes diff --git a/XMonad/Hooks/Focus.hs b/XMonad/Hooks/Focus.hs index 7559f9f1..f20edc36 100644 --- a/XMonad/Hooks/Focus.hs +++ b/XMonad/Hooks/Focus.hs @@ -149,7 +149,7 @@ import XMonad.Util.EZConfig -- -- > import XMonad -- > --- > import XMonad.Hooks.ManageHelpers hiding ((-?>), composeOne) +-- > import XMonad.Hooks.ManageHelpers -- > import XMonad.Hooks.Focus -- > -- > main :: IO () @@ -160,32 +160,12 @@ import XMonad.Util.EZConfig -- > ]) -- > $ def -- > xmonad xcf --- > --- > composeOne :: (Monoid a, Monad m) => [m (Maybe a)] -> m a --- > composeOne [] = return mempty --- > composeOne (mx : xs) = do --- > x <- mx --- > case x of --- > Just y -> return y --- > Nothing -> composeOne xs --- > --- > infixr 0 -?> --- > (-?>) :: Monad m => m Bool -> m a -> m (Maybe a) --- > (-?>) mb mx = do --- > b <- mb --- > if b --- > then Just <$> mx --- > else return Nothing --- -- -- Note: -- -- - /mod4Mask+v/ key toggles focus lock (when enabled, focus will not be -- switched to new window). -- - 'handleFocusQuery' will enable window activation. --- - I need more generic 'XMonad.Hooks.ManageHelpers.-?>' and --- 'XMonad.Hooks.ManageHelpers.composeOne', than in the --- 'XMonad.Hooks.ManageHelpers'. -- - The order, when constructing final 'FocusHook' in 'handleFocusQuery' -- call: 'FocusHook' without 'activated' predicate will match to activated -- windows too, thus i should place it after one with 'activated' (so the @@ -231,7 +211,7 @@ import XMonad.Util.EZConfig -- > import XMonad -- > import qualified XMonad.StackSet as W -- > --- > import XMonad.Hooks.ManageHelpers hiding ((-?>), composeOne) +-- > import XMonad.Hooks.ManageHelpers -- > import XMonad.Hooks.Focus -- > -- > main :: IO () @@ -269,22 +249,6 @@ import XMonad.Util.EZConfig -- > -- Default behavior for new windows: switch focus. -- > , return True -?> switchFocus -- > ] --- > --- > composeOne :: (Monoid a, Monad m) => [m (Maybe a)] -> m a --- > composeOne [] = return mempty --- > composeOne (mx : xs) = do --- > x <- mx --- > case x of --- > Just y -> return y --- > Nothing -> composeOne xs --- > --- > infixr 0 -?> --- > (-?>) :: Monad m => m Bool -> m a -> m (Maybe a) --- > (-?>) mb mx = do --- > b <- mb --- > if b --- > then Just <$> mx --- > else return Nothing -- -- Note here: -- diff --git a/XMonad/Hooks/ManageHelpers.hs b/XMonad/Hooks/ManageHelpers.hs index de03b553..bdb2f432 100644 --- a/XMonad/Hooks/ManageHelpers.hs +++ b/XMonad/Hooks/ManageHelpers.hs @@ -73,8 +73,8 @@ data Match a = Match Bool a -- | An alternative 'ManageHook' composer. Unlike 'composeAll' it stops as soon as -- a candidate returns a 'Just' value, effectively running only the first match -- (whereas 'composeAll' continues and executes all matching rules). -composeOne :: [MaybeManageHook] -> ManageHook -composeOne = foldr try idHook +composeOne :: (Monoid a, Monad m) => [m (Maybe a)] -> m a +composeOne = foldr try (return mempty) where try q z = do x <- q @@ -85,17 +85,17 @@ composeOne = foldr try idHook infixr 0 -?>, -->>, -?>> -- | q \/=? x. if the result of q equals x, return False -(/=?) :: Eq a => Query a -> a -> Query Bool +(/=?) :: (Eq a, Functor m) => m a -> a -> m Bool q /=? x = fmap (/= x) q -- | q <==? x. if the result of q equals x, return True grouped with q -(<==?) :: Eq a => Query a -> a -> Query (Match a) +(<==?) :: (Eq a, Functor m) => m a -> a -> m (Match a) q <==? x = fmap (`eq` x) q where eq q' x' = Match (q' == x') q' -- | q <\/=? x. if the result of q notequals x, return True grouped with q -( Query a -> a -> Query (Match a) +( m a -> a -> m (Match a) q ) :: Query Bool -> ManageHook -> MaybeManageHook +(-?>) :: (Functor m, Monad m) => m Bool -> m a -> m (Maybe a) p -?> f = do x <- p if x then fmap Just f else return Nothing -- | A helper operator for use in 'composeAll'. It takes a condition and a function taking a grouped datum to action. If 'p' is true, it executes the resulting action. -(-->>) :: Query (Match a) -> (a -> ManageHook) -> ManageHook +(-->>) :: (Monoid b, Monad m) => m (Match a) -> (a -> m b) -> m b p -->> f = do Match b m <- p - if b then (f m) else mempty + if b then (f m) else return mempty -- | A helper operator for use in 'composeOne'. It takes a condition and a function taking a groupdatum to action. If 'p' is true, it executes the resulting action. If it fails, it returns 'Nothing' from the 'Query' so 'composeOne' will go on and try the next rule. -(-?>>) :: Query (Match a) -> (a -> ManageHook) -> MaybeManageHook +(-?>>) :: (Functor m, Monad m) => m (Match a) -> (a -> m b) -> m (Maybe b) p -?>> f = do Match b m <- p if b then fmap Just (f m) else return Nothing @@ -179,7 +179,7 @@ transience' :: ManageHook transience' = maybeToDefinite transience -- | converts 'MaybeManageHook's to 'ManageHook's -maybeToDefinite :: MaybeManageHook -> ManageHook +maybeToDefinite :: (Monoid a, Functor m) => m (Maybe a) -> m a maybeToDefinite = fmap (fromMaybe mempty)