diff options
author | Spencer Janssen <sjanssen@cse.unl.edu> | 2007-12-22 11:41:14 +0100 |
---|---|---|
committer | Spencer Janssen <sjanssen@cse.unl.edu> | 2007-12-22 11:41:14 +0100 |
commit | 656c004bd143fd354667f8f1d2e8786d5cbb4b96 (patch) | |
tree | e18ba450437036df66ccd9a2e8b37986be73aa00 /XMonad/Util | |
parent | 0a99440e52d872287b1add151c2608f089c45c5c (diff) | |
download | XMonadContrib-656c004bd143fd354667f8f1d2e8786d5cbb4b96.tar.gz XMonadContrib-656c004bd143fd354667f8f1d2e8786d5cbb4b96.tar.xz XMonadContrib-656c004bd143fd354667f8f1d2e8786d5cbb4b96.zip |
Factor workspace sorting into a separate module
darcs-hash:20071222104114-a5988-bfd9059d0556a526c275b6d0e4a930103bd7d990.gz
Diffstat (limited to 'XMonad/Util')
-rw-r--r-- | XMonad/Util/WorkspaceCompare.hs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/XMonad/Util/WorkspaceCompare.hs b/XMonad/Util/WorkspaceCompare.hs new file mode 100644 index 0000000..93bd597 --- /dev/null +++ b/XMonad/Util/WorkspaceCompare.hs @@ -0,0 +1,37 @@ +----------------------------------------------------------------------------- +-- | +-- Module : XMonad.Util.WorkspaceCompare +-- Copyright : (c) Spencer Janssen <sjanssen@cse.unl.edu> +-- License : BSD3-style (see LICENSE) +-- +-- Maintainer : Spencer Janssen <sjanssen@cse.unl.edu> +-- Stability : unstable +-- Portability : unportable +-- + +module XMonad.Util.WorkspaceCompare ( getWsIndex, getWsCompare, getSortByTag ) where + +import XMonad +import qualified XMonad.StackSet as S +import Data.List +import Data.Monoid + +getWsIndex :: X (WorkspaceId -> Maybe Int) +getWsIndex = do + spaces <- asks (workspaces . config) + return $ flip elemIndex spaces + +getWsCompare :: X (WorkspaceId -> WorkspaceId -> Ordering) +getWsCompare = do + wsIndex <- getWsIndex + return $ \a b -> f (wsIndex a) (wsIndex b) `mappend` compare a b + where + f Nothing Nothing = EQ + f (Just _) Nothing = LT + f Nothing (Just _) = GT + f (Just x) (Just y) = compare x y + +getSortByTag :: X ([WindowSpace] -> [WindowSpace]) +getSortByTag = do + cmp <- getWsCompare + return $ sortBy (\a b -> cmp (S.tag a) (S.tag b)) |