mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
EwmhDesktops: Cache property values to avoid needless property changes
This commit is contained in:
parent
9fcea6cb55
commit
e814f748b5
@ -26,6 +26,7 @@ module XMonad.Hooks.EwmhDesktops (
|
|||||||
|
|
||||||
import Codec.Binary.UTF8.String (encode)
|
import Codec.Binary.UTF8.String (encode)
|
||||||
import Control.Applicative((<$>))
|
import Control.Applicative((<$>))
|
||||||
|
import Data.IORef
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
@ -70,6 +71,17 @@ ewmhDesktopsStartup = setSupported
|
|||||||
-- of the current state of workspaces and windows.
|
-- of the current state of workspaces and windows.
|
||||||
ewmhDesktopsLogHook :: X ()
|
ewmhDesktopsLogHook :: X ()
|
||||||
ewmhDesktopsLogHook = ewmhDesktopsLogHookCustom id
|
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
|
-- Generalized version of ewmhDesktopsLogHook that allows an arbitrary
|
||||||
-- user-specified function to transform the workspace list (post-sorting)
|
-- user-specified function to transform the workspace list (post-sorting)
|
||||||
@ -78,6 +90,10 @@ ewmhDesktopsLogHookCustom f = withWindowSet $ \s -> do
|
|||||||
sort' <- getSortByIndex
|
sort' <- getSortByIndex
|
||||||
let ws = f $ sort' $ W.workspaces s
|
let ws = f $ sort' $ W.workspaces s
|
||||||
|
|
||||||
|
cached <- readIORef cachedState
|
||||||
|
unless (cached == ws) $ do
|
||||||
|
writeIORef cachedState ws
|
||||||
|
|
||||||
-- Number of Workspaces
|
-- Number of Workspaces
|
||||||
setNumberOfDesktops (length ws)
|
setNumberOfDesktops (length ws)
|
||||||
|
|
||||||
@ -98,8 +114,6 @@ ewmhDesktopsLogHookCustom f = withWindowSet $ \s -> do
|
|||||||
|
|
||||||
setActiveWindow
|
setActiveWindow
|
||||||
|
|
||||||
return ()
|
|
||||||
|
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
-- Intercepts messages from pagers and similar applications and reacts on them.
|
-- Intercepts messages from pagers and similar applications and reacts on them.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user