From fcb57bd657ec596dc3225be1d8551db2079eae40 Mon Sep 17 00:00:00 2001 From: Bogdan Sinitsyn Date: Tue, 25 Oct 2016 08:22:02 +0300 Subject: [PATCH] Move `modifyXS` to X.U.ExtensibleState --- XMonad/Hooks/ManageDocks.hs | 11 ++--------- XMonad/Util/ExtensibleState.hs | 8 ++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/XMonad/Hooks/ManageDocks.hs b/XMonad/Hooks/ManageDocks.hs index 6e721598..d11d8110 100644 --- a/XMonad/Hooks/ManageDocks.hs +++ b/XMonad/Hooks/ManageDocks.hs @@ -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. diff --git a/XMonad/Util/ExtensibleState.hs b/XMonad/Util/ExtensibleState.hs index 7fe3b0a7..7e12a12c 100644 --- a/XMonad/Util/ExtensibleState.hs +++ b/XMonad/Util/ExtensibleState.hs @@ -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