aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Prompt/Layout.hs
blob: 3f55d066d5405a22c9c0063d0d12d48922a04adb (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
46
47
48
49
50
51
52
53
54
55
-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Prompt.Layout
-- Copyright   :  (C) 2007 Andrea Rossato, David Roundy
-- License     :  BSD3
-- 
-- Maintainer  :  droundy@darcs.net
-- Stability   :  unstable
-- Portability :  unportable
--
-- A layout-selection prompt for XMonad
--
-----------------------------------------------------------------------------

module XMonad.Prompt.Layout (
                             -- * Usage
                             -- $usage
                             layoutPrompt
                            ) where

import Control.Monad.State ( gets )
import Data.List ( sort, nub )
import XMonad hiding ( workspaces )
import XMonad.Operations ( sendMessage )
import XMonad.Prompt
import XMonad.StackSet ( workspaces, layout )
import XMonad.Layout.LayoutCombinators ( JumpToLayout(..) )

-- $usage
-- You can use this module with the following in your Config.hs file:
--
-- > import XMonad.Prompt
-- > import XMonad.Prompt.Layout
--
-- >   , ((modMask x .|. shiftMask, xK_m     ), layoutPrompt defaultXPConfig)

-- WARNING: This prompt won't display all possible layouts, because the
-- code to enable this was rejected from xmonad core.  It only displays
-- layouts that are actually in use.  Also, you can only select layouts if
-- you are using NewSelect, rather than the Select defined in xmonad core
-- (which doesn't have this feature).  So all in all, this module is really
-- more a proof-of-principle than something you can actually use
-- productively.

data Wor = Wor String

instance XPrompt Wor where
    showXPrompt (Wor x) = x

layoutPrompt :: XPConfig -> X ()
layoutPrompt c = do ls <- gets (map (description . layout) . workspaces . windowset)
                    mkXPrompt (Wor "") c (mkCompl $ sort $ nub ls) (sendMessage . JumpToLayout)

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