-----------------------------------------------------------------------------
-- |
-- 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.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
-- <https://xmonad.org/TUTORIAL.html#customizing-xmonad the tutorial>.

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 <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall i l a s sd. StackSet i l a s sd -> [Workspace i l a]
workspaces forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> WindowSet
windowset)
                           WorkspaceSort
sort <- X WorkspaceSort
getSortByIndex
                           let ts :: [String]
ts = forall a b. (a -> b) -> [a] -> [b]
map forall i l a. Workspace i l a -> i
tag forall a b. (a -> b) -> a -> b
$ WorkspaceSort
sort [Workspace String (Layout Window) Window]
ws
                           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