mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
XMonad.Hooks.ManageHelpers: reformatting
This commit is contained in:
parent
6761a61cad
commit
6ada04c415
@ -44,9 +44,9 @@ import Data.Monoid
|
|||||||
|
|
||||||
-- | A ManageHook that may or may not have been executed; the outcome is embedded in the Maybe
|
-- | A ManageHook that may or may not have been executed; the outcome is embedded in the Maybe
|
||||||
type MaybeManageHook = Query (Maybe (Endo WindowSet))
|
type MaybeManageHook = Query (Maybe (Endo WindowSet))
|
||||||
-- | A grouping type, which can hold the outcome of a predicate Query
|
-- | A grouping type, which can hold the outcome of a predicate Query.
|
||||||
-- This is analogous to group types in regular expressions
|
-- This is analogous to group types in regular expressions.
|
||||||
-- TODO create a better API for aggregating multiple Matches logically
|
-- TODO: create a better API for aggregating multiple Matches logically
|
||||||
data Match a = Match Bool a
|
data Match a = Match Bool a
|
||||||
|
|
||||||
-- | An alternative 'ManageHook' composer. Unlike 'composeAll' it stops as soon as
|
-- | An alternative 'ManageHook' composer. Unlike 'composeAll' it stops as soon as
|
||||||
@ -70,12 +70,14 @@ q /=? x = fmap (/= x) q
|
|||||||
-- | q <==? x. if the result of q equals x, return True grouped with 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 => Query a -> a -> Query (Match a)
|
||||||
q <==? x = fmap (`eq` x) q
|
q <==? x = fmap (`eq` x) q
|
||||||
where eq q' x' = Match (q' == x') q'
|
where
|
||||||
|
eq q' x' = Match (q' == x') q'
|
||||||
|
|
||||||
-- | q <\/=? x. if the result of q notequals x, return True grouped with q
|
-- | q <\/=? x. if the result of q notequals x, return True grouped with q
|
||||||
(</=?) :: Eq a => Query a -> a -> Query (Match a)
|
(</=?) :: Eq a => Query a -> a -> Query (Match a)
|
||||||
q </=? x = fmap (`neq` x) q
|
q </=? x = fmap (`neq` x) q
|
||||||
where neq q' x' = Match (q' /= x') q'
|
where
|
||||||
|
neq q' x' = Match (q' /= x') q'
|
||||||
|
|
||||||
-- | A helper operator for use in 'composeOne'. It takes a condition and an action;
|
-- | A helper operator for use in 'composeOne'. It takes a condition and an action;
|
||||||
-- if the condition fails, it returns 'Nothing' from the 'Query' so 'composeOne' will
|
-- if the condition fails, it returns 'Nothing' from the 'Query' so 'composeOne' will
|
||||||
@ -87,13 +89,15 @@ p -?> f = do
|
|||||||
|
|
||||||
-- | 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.
|
-- | 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
|
(-->>) :: Query (Match a) -> (a -> ManageHook) -> ManageHook
|
||||||
p -->> f = do Match b m <- p
|
p -->> f = do
|
||||||
if b then (f m) else mempty
|
Match b m <- p
|
||||||
|
if b then (f m) else 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.
|
-- | 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
|
(-?>>) :: Query (Match a) -> (a -> ManageHook) -> MaybeManageHook
|
||||||
p -?>> f = do Match b m <- p
|
p -?>> f = do
|
||||||
if b then fmap Just (f m) else return Nothing
|
Match b m <- p
|
||||||
|
if b then fmap Just (f m) else return Nothing
|
||||||
|
|
||||||
-- | A predicate to check whether a window is a KDE system tray icon.
|
-- | A predicate to check whether a window is a KDE system tray icon.
|
||||||
isKDETrayWindow :: Query Bool
|
isKDETrayWindow :: Query Bool
|
||||||
@ -109,19 +113,18 @@ isKDETrayWindow = ask >>= \w -> liftX $ do
|
|||||||
-- It holds the result which might be the window it is transient to
|
-- It holds the result which might be the window it is transient to
|
||||||
-- or it might be 'Nothing'.
|
-- or it might be 'Nothing'.
|
||||||
transientTo :: Query (Maybe Window)
|
transientTo :: Query (Maybe Window)
|
||||||
transientTo = do w <- ask
|
transientTo = do
|
||||||
d <- (liftX . asks) display
|
w <- ask
|
||||||
liftIO $ getTransientForHint d w
|
d <- (liftX . asks) display
|
||||||
|
liftIO $ getTransientForHint d w
|
||||||
|
|
||||||
-- | A convenience 'MaybeManageHook' that will check to see if a window
|
-- | A convenience 'MaybeManageHook' that will check to see if a window
|
||||||
-- is transient, and then move it to its parent.
|
-- is transient, and then move it to its parent.
|
||||||
transience :: MaybeManageHook
|
transience :: MaybeManageHook
|
||||||
transience = transientTo </=? Nothing
|
transience = transientTo </=? Nothing -?>> move
|
||||||
-?>> move
|
where
|
||||||
where move :: Maybe Window -> ManageHook
|
move mw = maybe idHook (doF . move') mw
|
||||||
move mw = maybe idHook (doF . move') mw
|
move' w s = maybe s (`W.shift` s) (W.findTag w s)
|
||||||
where move' :: Window -> (WindowSet -> WindowSet)
|
|
||||||
move' w = \s -> maybe s (`W.shift` s) (W.findTag w s)
|
|
||||||
|
|
||||||
-- | 'transience' set to a 'ManageHook'
|
-- | 'transience' set to a 'ManageHook'
|
||||||
transience' :: ManageHook
|
transience' :: ManageHook
|
||||||
@ -141,6 +144,5 @@ doRectFloat r = ask >>= \w -> doF (W.float w r)
|
|||||||
-- | Floats a new window with its original size, but centered.
|
-- | Floats a new window with its original size, but centered.
|
||||||
doCenterFloat :: ManageHook
|
doCenterFloat :: ManageHook
|
||||||
doCenterFloat = ask >>= \w -> doF . W.float w . center . snd =<< liftX (floatLocation w)
|
doCenterFloat = ask >>= \w -> doF . W.float w . center . snd =<< liftX (floatLocation w)
|
||||||
where center (W.RationalRect _ _ w h)
|
where
|
||||||
= W.RationalRect ((1-w)/2) ((1-h)/2) w h
|
center (W.RationalRect _ _ w h) = W.RationalRect ((1-w)/2) ((1-h)/2) w h
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user