Move modifyXS to X.U.ExtensibleState

This commit is contained in:
Bogdan Sinitsyn
2016-10-25 08:22:02 +03:00
parent e38fb3bdb8
commit fcb57bd657
2 changed files with 10 additions and 9 deletions

View File

@@ -103,20 +103,13 @@ refreshDocks = sendMessage UpdateDocks
instance ExtensionClass StrutCache where
initialValue = StrutCache M.empty
modifyXS :: (ExtensionClass a, Eq a) => (a -> a) -> X Bool
modifyXS f = do
v <- XS.get
case f v of
v' | v' == v -> return False
| otherwise -> XS.put v' >> return True
updateStrutCache :: Window -> [Strut] -> X Bool
updateStrutCache w strut = do
modifyXS $ StrutCache . M.insert w strut . fromStrutCache
XS.modified $ StrutCache . M.insert w strut . fromStrutCache
deleteFromStructCache :: Window -> X Bool
deleteFromStructCache w = do
modifyXS $ StrutCache . M.delete w . fromStrutCache
XS.modified $ StrutCache . M.delete w . fromStrutCache
-- | Detects if the given window is of type DOCK and if so, reveals
-- it, but does not manage it.

View File

@@ -21,6 +21,7 @@ module XMonad.Util.ExtensibleState (
, remove
, get
, gets
, modified
) where
import Data.Typeable (typeOf,cast)
@@ -115,3 +116,10 @@ gets = flip fmap get
-- | Remove the value from the extensible state field that has the same type as the supplied argument
remove :: ExtensionClass a => a -> X ()
remove wit = modifyStateExts $ M.delete (show . typeOf $ wit)
modified :: (ExtensionClass a, Eq a) => (a -> a) -> X Bool
modified f = do
v <- get
case f v of
v' | v' == v -> return False
| otherwise -> put v' >> return True