aboutsummaryrefslogtreecommitdiffstats
path: root/WorkspacePrompt.hs
blob: 005d96a7025a1d841b3df28548b226a386a9e20f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-----------------------------------------------------------------------------
-- |
-- Module      :  XMonadContrib.WorkspacePrompt
-- Copyright   :  (C) 2007 Andrea Rossato, David Roundy
-- License     :  BSD3
-- 
-- Maintainer  :  droundy@darcs.net
-- Stability   :  unstable
-- Portability :  unportable
--
-- A directory prompt for XMonad
--
-----------------------------------------------------------------------------

module XMonadContrib.WorkspacePrompt (
                             -- * Usage
                             -- $usage
                             workspacePrompt
                              ) where

import Control.Monad.State ( gets )
import Data.List ( sort )
import XMonad
import XMonadContrib.XPrompt
import StackSet ( workspaces, tag )

-- $usage
-- You can use this module with the following in your Config.hs file:
-- 
-- > import XMonadContrib.WorkspacePrompt
--
-- >   , ((modMask .|. shiftMask, xK_m     ), workspacePrompt myXPConfig (windows . W.shift))

data Wor = Wor String

instance XPrompt Wor where
    showXPrompt (Wor x) = x

workspacePrompt :: XPConfig -> (String -> X ()) -> X ()
workspacePrompt c job = do ws <- gets (workspaces . windowset)
                           let ts = sort $ map tag ws
                           mkXPrompt (Wor "") c (mkCompl ts) job

mkCompl :: [String] -> String -> IO [String]
mkCompl l s = return $ filter (\x -> take (length s) x == s) l