mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 03:20:21 -07:00
add withWorkspace prompt, which automatically creates workspace if nonexistent.
This commit is contained in:
parent
283001699d
commit
77be696976
@ -17,6 +17,7 @@ module XMonad.Actions.DynamicWorkspaces (
|
|||||||
-- * Usage
|
-- * Usage
|
||||||
-- $usage
|
-- $usage
|
||||||
addWorkspace, removeWorkspace,
|
addWorkspace, removeWorkspace,
|
||||||
|
withWorkspace,
|
||||||
selectWorkspace, renameWorkspace,
|
selectWorkspace, renameWorkspace,
|
||||||
toNthWorkspace, withNthWorkspace
|
toNthWorkspace, withNthWorkspace
|
||||||
) where
|
) where
|
||||||
@ -25,12 +26,11 @@ import Control.Monad.Reader ( asks )
|
|||||||
import Control.Monad.State ( gets )
|
import Control.Monad.State ( gets )
|
||||||
import Data.List ( sort )
|
import Data.List ( sort )
|
||||||
|
|
||||||
import XMonad ( X, XState(..), Layout, WorkspaceId, WindowSet, config, layoutHook )
|
import XMonad ( X, XState(..), WindowSet, config, layoutHook )
|
||||||
import XMonad.Operations
|
import XMonad.Operations
|
||||||
import XMonad.StackSet hiding (filter, modify, delete)
|
import XMonad.StackSet hiding (filter, modify, delete)
|
||||||
import Graphics.X11.Xlib ( Window )
|
|
||||||
import XMonad.Prompt.Workspace
|
import XMonad.Prompt.Workspace
|
||||||
import XMonad.Prompt ( XPConfig )
|
import XMonad.Prompt ( XPConfig, mkXPrompt, XPrompt(..) )
|
||||||
|
|
||||||
-- $usage
|
-- $usage
|
||||||
-- You can use this module with the following in your Config.hs file:
|
-- You can use this module with the following in your Config.hs file:
|
||||||
@ -48,8 +48,20 @@ import XMonad.Prompt ( XPConfig )
|
|||||||
-- > ++
|
-- > ++
|
||||||
-- > zip (zip (repeat (modMask .|. shiftMask)) [xK_1..xK_9]) (map (withNthWorkspace W.shift) [0..])
|
-- > zip (zip (repeat (modMask .|. shiftMask)) [xK_1..xK_9]) (map (withNthWorkspace W.shift) [0..])
|
||||||
|
|
||||||
allPossibleTags :: [WorkspaceId]
|
data Wor = Wor String
|
||||||
allPossibleTags = map (:"") ['0'..]
|
|
||||||
|
instance XPrompt Wor where
|
||||||
|
showXPrompt (Wor x) = x
|
||||||
|
|
||||||
|
mkCompl :: [String] -> String -> IO [String]
|
||||||
|
mkCompl l s = return $ filter (\x -> take (length s) x == s) l
|
||||||
|
|
||||||
|
withWorkspace :: XPConfig -> (String -> X ()) -> X ()
|
||||||
|
withWorkspace c job = do ws <- gets (workspaces . windowset)
|
||||||
|
let ts = sort $ map tag ws
|
||||||
|
job' t | t `elem` ts = job t
|
||||||
|
| otherwise = addHiddenWorkspace t >> job t
|
||||||
|
mkXPrompt (Wor "") c (mkCompl ts) job'
|
||||||
|
|
||||||
renameWorkspace :: XPConfig -> X ()
|
renameWorkspace :: XPConfig -> X ()
|
||||||
renameWorkspace conf = workspacePrompt conf $ \w ->
|
renameWorkspace conf = workspacePrompt conf $ \w ->
|
||||||
@ -72,15 +84,17 @@ withNthWorkspace job wnum = do ws <- gets (sort . map tag . workspaces . windows
|
|||||||
|
|
||||||
selectWorkspace :: XPConfig -> X ()
|
selectWorkspace :: XPConfig -> X ()
|
||||||
selectWorkspace conf = workspacePrompt conf $ \w ->
|
selectWorkspace conf = workspacePrompt conf $ \w ->
|
||||||
do l <- asks (layoutHook . config)
|
do s <- gets windowset
|
||||||
windows $ \s -> if tagMember w s
|
if tagMember w s
|
||||||
then greedyView w s
|
then windows $ greedyView w
|
||||||
else addWorkspace' w l s
|
else addWorkspace w
|
||||||
|
|
||||||
addWorkspace :: Layout Window -> X ()
|
addWorkspace :: String -> X ()
|
||||||
addWorkspace l = do s <- gets windowset
|
addWorkspace newtag = addHiddenWorkspace newtag >> windows (greedyView newtag)
|
||||||
let newtag:_ = filter (not . (`tagMember` s)) allPossibleTags
|
|
||||||
windows (addWorkspace' newtag l)
|
addHiddenWorkspace :: String -> X ()
|
||||||
|
addHiddenWorkspace newtag = do l <- asks (layoutHook . config)
|
||||||
|
windows (addHiddenWorkspace' newtag l)
|
||||||
|
|
||||||
removeWorkspace :: X ()
|
removeWorkspace :: X ()
|
||||||
removeWorkspace = do s <- gets windowset
|
removeWorkspace = do s <- gets windowset
|
||||||
@ -91,11 +105,8 @@ removeWorkspace = do s <- gets windowset
|
|||||||
windows (removeWorkspace' (tag torem))
|
windows (removeWorkspace' (tag torem))
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
|
|
||||||
addWorkspace' :: i -> l -> StackSet i l a sid sd -> StackSet i l a sid sd
|
addHiddenWorkspace' :: i -> l -> StackSet i l a sid sd -> StackSet i l a sid sd
|
||||||
addWorkspace' newtag l s@(StackSet { current = scr@(Screen { workspace = w })
|
addHiddenWorkspace' newtag l s@(StackSet { hidden = ws }) = s { hidden = Workspace newtag l Nothing:ws }
|
||||||
, hidden = ws })
|
|
||||||
= s { current = scr { workspace = Workspace newtag l Nothing }
|
|
||||||
, hidden = w:ws }
|
|
||||||
|
|
||||||
removeWorkspace' :: (Eq i) => i -> StackSet i l a sid sd -> StackSet i l a sid sd
|
removeWorkspace' :: (Eq i) => i -> StackSet i l a sid sd -> StackSet i l a sid sd
|
||||||
removeWorkspace' torem s@(StackSet { current = scr@(Screen { workspace = wc })
|
removeWorkspace' torem s@(StackSet { current = scr@(Screen { workspace = wc })
|
||||||
|
@ -43,7 +43,6 @@ import XMonad.Layout.WorkspaceDir
|
|||||||
import XMonad.Layout.ToggleLayouts
|
import XMonad.Layout.ToggleLayouts
|
||||||
|
|
||||||
import XMonad.Prompt
|
import XMonad.Prompt
|
||||||
import XMonad.Prompt.Workspace
|
|
||||||
import XMonad.Prompt.Shell
|
import XMonad.Prompt.Shell
|
||||||
|
|
||||||
import XMonad.Actions.CopyWindow
|
import XMonad.Actions.CopyWindow
|
||||||
@ -70,8 +69,6 @@ keys x = M.fromList $
|
|||||||
, ((modMask x, xK_space ), sendMessage NextLayout) -- %! Rotate through the available layout algorithms
|
, ((modMask x, xK_space ), sendMessage NextLayout) -- %! Rotate through the available layout algorithms
|
||||||
, ((modMask x .|. shiftMask, xK_space ), setLayout $ layoutHook x) -- %! Reset the layouts on the current workspace to default
|
, ((modMask x .|. shiftMask, xK_space ), setLayout $ layoutHook x) -- %! Reset the layouts on the current workspace to default
|
||||||
|
|
||||||
, ((modMask x, xK_n ), refresh) -- %! Resize viewed windows to the correct size
|
|
||||||
|
|
||||||
-- move focus up or down the window stack
|
-- move focus up or down the window stack
|
||||||
, ((modMask x, xK_Tab ), windows W.focusDown) -- %! Move focus to the next window
|
, ((modMask x, xK_Tab ), windows W.focusDown) -- %! Move focus to the next window
|
||||||
, ((modMask x, xK_j ), windows W.focusDown) -- %! Move focus to the next window
|
, ((modMask x, xK_j ), windows W.focusDown) -- %! Move focus to the next window
|
||||||
@ -112,15 +109,12 @@ keys x = M.fromList $
|
|||||||
, ((modMask x .|. shiftMask, xK_x ), changeDir myXPConfig)
|
, ((modMask x .|. shiftMask, xK_x ), changeDir myXPConfig)
|
||||||
, ((modMask x .|. shiftMask, xK_BackSpace), removeWorkspace)
|
, ((modMask x .|. shiftMask, xK_BackSpace), removeWorkspace)
|
||||||
, ((modMask x .|. shiftMask, xK_v ), selectWorkspace myXPConfig)
|
, ((modMask x .|. shiftMask, xK_v ), selectWorkspace myXPConfig)
|
||||||
, ((modMask x, xK_m ), workspacePrompt myXPConfig (windows . W.shift))
|
, ((modMask x, xK_m ), withWorkspace myXPConfig (windows . W.shift))
|
||||||
, ((modMask x .|. shiftMask, xK_m ), workspacePrompt myXPConfig (windows . copy))
|
, ((modMask x .|. shiftMask, xK_m ), withWorkspace myXPConfig (windows . copy))
|
||||||
, ((modMask x .|. shiftMask, xK_r), renameWorkspace myXPConfig)
|
, ((modMask x .|. shiftMask, xK_r), renameWorkspace myXPConfig)
|
||||||
, ((modMask x .|. controlMask, xK_space), sendMessage ToggleLayout)
|
, ((modMask x .|. controlMask, xK_space), sendMessage ToggleLayout)
|
||||||
, ((modMask x .|. controlMask, xK_f), sendMessage (JumpToLayout "Full"))
|
|
||||||
]
|
]
|
||||||
|
|
||||||
-- % Extension-provided key bindings lists
|
|
||||||
|
|
||||||
++
|
++
|
||||||
zip (zip (repeat $ modMask x) [xK_F1..xK_F12]) (map (withNthWorkspace W.greedyView) [0..])
|
zip (zip (repeat $ modMask x) [xK_F1..xK_F12]) (map (withNthWorkspace W.greedyView) [0..])
|
||||||
++
|
++
|
||||||
@ -137,12 +131,8 @@ mouseBindings x = M.fromList $
|
|||||||
-- mod-button3 %! Set the window to floating mode and resize by dragging
|
-- mod-button3 %! Set the window to floating mode and resize by dragging
|
||||||
, ((modMask x, button3), (\w -> focus w >> mouseResizeWindow w))
|
, ((modMask x, button3), (\w -> focus w >> mouseResizeWindow w))
|
||||||
-- you may also bind events to the mouse scroll wheel (button4 and button5)
|
-- you may also bind events to the mouse scroll wheel (button4 and button5)
|
||||||
|
|
||||||
-- % Extension-provided mouse bindings
|
|
||||||
]
|
]
|
||||||
|
|
||||||
-- % Extension-provided definitions
|
|
||||||
|
|
||||||
config :: XConfig
|
config :: XConfig
|
||||||
config = defaultConfig
|
config = defaultConfig
|
||||||
{ borderWidth = 1 -- Width of the window border in pixels.
|
{ borderWidth = 1 -- Width of the window border in pixels.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user