X.U.NamedScratchpad: Factor out isNSP

This function can be pretty useful in a general context, so let's factor
it out.
This commit is contained in:
Tony Zorman 2022-10-31 20:05:24 +01:00
parent 48a6d34f55
commit 49e9570f12

View File

@ -154,6 +154,11 @@ defaultFloating = doFloat
customFloating :: W.RationalRect -> ManageHook customFloating :: W.RationalRect -> ManageHook
customFloating = doRectFloat customFloating = doRectFloat
-- | @isNSP win nsps@ checks whether the window @win@ is any scratchpad
-- in @nsps@.
isNSP :: Window -> NamedScratchpads -> X Bool
isNSP w = fmap or . traverse ((`runQuery` w) . query)
-- | Named scratchpads configuration -- | Named scratchpads configuration
type NamedScratchpads = [NamedScratchpad] type NamedScratchpads = [NamedScratchpad]
@ -225,11 +230,8 @@ nsHideOnFocusLoss scratches = withWindowSet $ \winSet -> do
let cur = W.currentTag winSet let cur = W.currentTag winSet
withRecentsIn cur () $ \lastFocus _ -> withRecentsIn cur () $ \lastFocus _ ->
when (lastFocus `elem` W.index winSet && cur /= scratchpadWorkspaceTag) $ when (lastFocus `elem` W.index winSet && cur /= scratchpadWorkspaceTag) $
whenX (isNS lastFocus) $ whenX (isNSP lastFocus scratches) $
shiftToNSP (W.workspaces winSet) ($ lastFocus) shiftToNSP (W.workspaces winSet) ($ lastFocus)
where
isNS :: Window -> X Bool
isNS w = or <$> traverse ((`runQuery` w) . query) scratches
-- | Execute some action on a named scratchpad. -- | Execute some action on a named scratchpad.
-- --