module XMonad.Util.WindowPropertiesRE
(PropertyRE (..),
(~?),
propertyToQueryRE, hasPropertyRE
) where
import Text.Regex.Posix ((=~))
import XMonad
import XMonad.Util.WindowProperties
import XMonad.Layout.LayoutBuilderP
data PropertyRE = RE Property
deriving (Show,Read,Typeable)
(~?) :: (Functor f) => f String -> String -> f Bool
q ~? x = fmap (=~ x) q
propertyToQueryRE :: Property -> Query Bool
propertyToQueryRE (Title s) = title ~? s
propertyToQueryRE (Resource s) = resource ~? s
propertyToQueryRE (ClassName s) = className ~? s
propertyToQueryRE (Role s) = stringProperty "WM_WINDOW_ROLE" ~? s
propertyToQueryRE (Machine s) = stringProperty "WM_CLIENT_MACHINE" ~? s
propertyToQueryRE (And p1 p2) = propertyToQueryRE p1 <&&> propertyToQueryRE p2
propertyToQueryRE (Or p1 p2) = propertyToQueryRE p1 <||> propertyToQueryRE p2
propertyToQueryRE (Not p) = not `fmap` propertyToQueryRE p
propertyToQueryRE (Const b) = return b
hasPropertyRE :: PropertyRE -> Window -> X Bool
hasPropertyRE (RE p) w = runQuery (propertyToQueryRE p) w
instance Predicate PropertyRE Window where
alwaysTrue _ = RE (Const True)
checkPredicate = hasPropertyRE