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,27 +90,29 @@ ewmhDesktopsLogHookCustom f = withWindowSet $ \s -> do
|
|||||||
sort' <- getSortByIndex
|
sort' <- getSortByIndex
|
||||||
let ws = f $ sort' $ W.workspaces s
|
let ws = f $ sort' $ W.workspaces s
|
||||||
|
|
||||||
-- Number of Workspaces
|
cached <- readIORef cachedState
|
||||||
setNumberOfDesktops (length ws)
|
unless (cached == ws) $ do
|
||||||
|
writeIORef cachedState ws
|
||||||
|
|
||||||
-- Names thereof
|
-- Number of Workspaces
|
||||||
setDesktopNames (map W.tag ws)
|
setNumberOfDesktops (length ws)
|
||||||
|
|
||||||
-- all windows, with focused windows last
|
-- Names thereof
|
||||||
let wins = nub . concatMap (maybe [] (\(W.Stack x l r)-> reverse l ++ r ++ [x]) . W.stack) $ ws
|
setDesktopNames (map W.tag ws)
|
||||||
setClientList wins
|
|
||||||
|
|
||||||
-- Remap the current workspace to handle any renames that f might be doing.
|
-- all windows, with focused windows last
|
||||||
let maybeCurrent' = W.tag <$> listToMaybe (f [W.workspace $ W.current s])
|
let wins = nub . concatMap (maybe [] (\(W.Stack x l r)-> reverse l ++ r ++ [x]) . W.stack) $ ws
|
||||||
maybeCurrent = join (flip elemIndex (map W.tag ws) <$> maybeCurrent')
|
setClientList wins
|
||||||
|
|
||||||
fromMaybe (return ()) $ setCurrentDesktop <$> maybeCurrent
|
-- Remap the current workspace to handle any renames that f might be doing.
|
||||||
|
let maybeCurrent' = W.tag <$> listToMaybe (f [W.workspace $ W.current s])
|
||||||
|
maybeCurrent = join (flip elemIndex (map W.tag ws) <$> maybeCurrent')
|
||||||
|
|
||||||
sequence_ $ zipWith setWorkspaceWindowDesktops [0..] ws
|
fromMaybe (return ()) $ setCurrentDesktop <$> maybeCurrent
|
||||||
|
|
||||||
setActiveWindow
|
sequence_ $ zipWith setWorkspaceWindowDesktops [0..] ws
|
||||||
|
|
||||||
return ()
|
setActiveWindow
|
||||||
|
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user