-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Prompt.Workspace
-- Description :  A workspace prompt.
-- Copyright   :  (C) 2007 Andrea Rossato, David Roundy
-- License     :  BSD3
--
-- Maintainer  :
-- Stability   :  unstable
-- Portability :  unportable
--
-- A workspace prompt for XMonad
--
-----------------------------------------------------------------------------

module XMonad.Prompt.Workspace (
                             -- * Usage
                             -- $usage
                             workspacePrompt,

                             -- * For developers
                             Wor(Wor),
                              ) where

import XMonad hiding ( workspaces )
import XMonad.Prompt
import XMonad.StackSet ( workspaces, tag )
import XMonad.Util.WorkspaceCompare ( getSortByIndex )

-- $usage
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
--
-- > import XMonad.Prompt
-- > import XMonad.Prompt.Workspace
--
-- >   , ((modm .|. shiftMask, xK_m     ), workspacePrompt def (windows . W.shift))
--
-- For detailed instruction on editing the key binding see
-- "XMonad.Doc.Extending#Editing_key_bindings".

newtype Wor = Wor String

instance XPrompt Wor where
    showXPrompt :: Wor -> String
showXPrompt (Wor String
x) = String
x

workspacePrompt :: XPConfig -> (String -> X ()) -> X ()
workspacePrompt :: XPConfig -> (String -> X ()) -> X ()
workspacePrompt XPConfig
c String -> X ()
job = do [Workspace String (Layout Window) Window]
ws <- (XState -> [Workspace String (Layout Window) Window])
-> X [Workspace String (Layout Window) Window]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (StackSet String (Layout Window) Window ScreenId ScreenDetail
-> [Workspace String (Layout Window) Window]
forall i l a s sd. StackSet i l a s sd -> [Workspace i l a]
workspaces (StackSet String (Layout Window) Window ScreenId ScreenDetail
 -> [Workspace String (Layout Window) Window])
-> (XState
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> [Workspace String (Layout Window) Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet String (Layout Window) Window ScreenId ScreenDetail
windowset)
                           WorkspaceSort
sort <- X WorkspaceSort
getSortByIndex
                           let ts :: [String]
ts = (Workspace String (Layout Window) Window -> String)
-> [Workspace String (Layout Window) Window] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Workspace String (Layout Window) Window -> String
forall i l a. Workspace i l a -> i
tag ([Workspace String (Layout Window) Window] -> [String])
-> [Workspace String (Layout Window) Window] -> [String]
forall a b. (a -> b) -> a -> b
$ WorkspaceSort
sort [Workspace String (Layout Window) Window]
ws
                           Wor -> XPConfig -> ComplFunction -> (String -> X ()) -> X ()
forall p.
XPrompt p =>
p -> XPConfig -> ComplFunction -> (String -> X ()) -> X ()
mkXPrompt (String -> Wor
Wor String
"") XPConfig
c (XPConfig -> [String] -> ComplFunction
mkComplFunFromList' XPConfig
c [String]
ts) String -> X ()
job