From d1587d44209f924682f25dffff584d6e052029a4 Mon Sep 17 00:00:00 2001 From: David Roundy Date: Wed, 17 Oct 2007 00:33:47 +0200 Subject: add modules to deal with Workspaces (select, etc) by name using XPrompt. darcs-hash:20071016223347-72aca-a0a6ab2a43a33f5901640fa2f192e0af3ef61a74.gz --- DynamicWorkspaces.hs | 16 +++++++++++++--- WorkspacePrompt.hs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 WorkspacePrompt.hs diff --git a/DynamicWorkspaces.hs b/DynamicWorkspaces.hs index f212cab..e9bd06c 100644 --- a/DynamicWorkspaces.hs +++ b/DynamicWorkspaces.hs @@ -16,7 +16,8 @@ module XMonadContrib.DynamicWorkspaces ( -- * Usage -- $usage - addWorkspace, removeWorkspace + addWorkspace, removeWorkspace, + selectWorkspace ) where import Control.Monad.State ( gets ) @@ -25,18 +26,27 @@ import XMonad ( X, XState(..), Layout, WorkspaceId ) import Operations import StackSet hiding (filter, modify, delete) import Graphics.X11.Xlib ( Window ) +import XMonadContrib.WorkspacePrompt +import XMonadContrib.XPrompt ( XPConfig ) -- $usage -- You can use this module with the following in your Config.hs file: -- -- > import XMonadContrib.DynamicWorkspaces -- --- > , ((modMask .|. shiftMask, xK_Up), addWorkspace layouts) --- > , ((modMask .|. shiftMask, xK_Down), removeWorkspace) +-- > , ((modMask .|. shiftMask, xK_n), selectWorkspace defaultXPConfig layoutHook) +-- > , ((modMask .|. shiftMask, xK_BackSpace), removeWorkspace) allPossibleTags :: [WorkspaceId] allPossibleTags = map (:"") ['0'..] +selectWorkspace :: XPConfig -> Layout Window -> X () +selectWorkspace conf l = workspacePrompt conf $ \w -> + do s <- gets windowset + if tagMember w s + then windows $ greedyView w + else windows $ addWorkspace' w l + addWorkspace :: Layout Window -> X () addWorkspace l = do s <- gets windowset let newtag:_ = filter (not . (`tagMember` s)) allPossibleTags diff --git a/WorkspacePrompt.hs b/WorkspacePrompt.hs new file mode 100644 index 0000000..005d96a --- /dev/null +++ b/WorkspacePrompt.hs @@ -0,0 +1,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 -- cgit v1.2.3