EwmhDesktops: Cache property values to avoid needless property changes

This commit is contained in:
Ben Gamari 2018-06-19 01:47:08 -04:00
parent 9fcea6cb55
commit e814f748b5

View File

@ -26,6 +26,7 @@ module XMonad.Hooks.EwmhDesktops (
import Codec.Binary.UTF8.String (encode)
import Control.Applicative((<$>))
import Data.IORef
import Data.List
import Data.Maybe
import Data.Monoid
@ -70,6 +71,17 @@ ewmhDesktopsStartup = setSupported
-- of the current state of workspaces and windows.
ewmhDesktopsLogHook :: X ()
ewmhDesktopsLogHook = ewmhDesktopsLogHookCustom id
data CacheState = CacheState { cachedWs :: [WindowSpace] }
deriving (Eq)
-- |
-- Cache last property state to avoid needless property changes.
cachedState :: IORef CacheState
cachedState = newIORef []
{-# NOINLINE cachedState #-}
-- |
-- Generalized version of ewmhDesktopsLogHook that allows an arbitrary
-- user-specified function to transform the workspace list (post-sorting)
@ -78,6 +90,10 @@ ewmhDesktopsLogHookCustom f = withWindowSet $ \s -> do
sort' <- getSortByIndex
let ws = f $ sort' $ W.workspaces s
cached <- readIORef cachedState
unless (cached == ws) $ do
writeIORef cachedState ws
-- Number of Workspaces
setNumberOfDesktops (length ws)
@ -98,8 +114,6 @@ ewmhDesktopsLogHookCustom f = withWindowSet $ \s -> do
setActiveWindow
return ()
-- |
-- Intercepts messages from pagers and similar applications and reacts on them.