From 7ebe017965626cf2c476826363023aa3d6b5d293 Mon Sep 17 00:00:00 2001 From: Norbert Zeh Date: Wed, 6 Apr 2011 16:02:13 +0200 Subject: Support for scratchpad applications with multiple windows Ignore-this: 4c7d5f2ff95292438464e0b1060ab324 I recently found that I use xpad to add sticky notes to my desktop. I wanted to be able to show/hide these in the same fashion as regular scratchpads. This patch adds a function that allows to do this while reusing most of the existing NamedScratchpad code. darcs-hash:20110406140213-18a2b-402b9e2fdd26d4bb06bc50b094079b74e76c0208.gz --- XMonad/Util/NamedScratchpad.hs | 47 ++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/XMonad/Util/NamedScratchpad.hs b/XMonad/Util/NamedScratchpad.hs index 7269103..6fc226d 100644 --- a/XMonad/Util/NamedScratchpad.hs +++ b/XMonad/Util/NamedScratchpad.hs @@ -22,6 +22,7 @@ module XMonad.Util.NamedScratchpad ( customFloating, NamedScratchpads, namedScratchpadAction, + allNamedScratchpadAction, namedScratchpadManageHook, namedScratchpadFilterOutWorkspace ) where @@ -116,29 +117,35 @@ runApplication = spawn . cmd namedScratchpadAction :: NamedScratchpads -- ^ Named scratchpads configuration -> String -- ^ Scratchpad name -> X () -namedScratchpadAction confs n +namedScratchpadAction = someNamedScratchpadAction (\f ws -> f $ head ws) + +allNamedScratchpadAction :: NamedScratchpads + -> String + -> X () +allNamedScratchpadAction = someNamedScratchpadAction mapM_ + +someNamedScratchpadAction :: ((Window -> X ()) -> [Window] -> X ()) + -> NamedScratchpads + -> String + -> X () +someNamedScratchpadAction f confs n | Just conf <- findByName confs n = withWindowSet $ \s -> do - -- try to find it on the current workspace - filterCurrent <- filterM (runQuery (query conf)) - ( (maybe [] W.integrate . W.stack . - W.workspace . W.current) s) - case filterCurrent of - (x:_) -> do - -- create hidden workspace if it doesn't exist - if null (filter ((== scratchpadWorkspaceTag) . W.tag) (W.workspaces s)) - then addHiddenWorkspace scratchpadWorkspaceTag - else return () - -- push window there - windows $ W.shiftWin scratchpadWorkspaceTag x - [] -> do - -- try to find it on all workspaces - filterAll <- filterM (runQuery (query conf)) (W.allWindows s) - case filterAll of - (x:_) -> windows $ W.shiftWin (W.currentTag s) x - [] -> runApplication conf - + filterCurrent <- filterM (runQuery (query conf)) + ((maybe [] W.integrate . W.stack . W.workspace . W.current) s) + filterAll <- filterM (runQuery (query conf)) (W.allWindows s) + case filterCurrent of + [] -> do + case filterAll of + [] -> runApplication conf + _ -> f (windows . W.shiftWin (W.currentTag s)) filterAll + _ -> do + if null (filter ((== scratchpadWorkspaceTag) . W.tag) (W.workspaces s)) + then addHiddenWorkspace scratchpadWorkspaceTag + else return () + f (windows . W.shiftWin scratchpadWorkspaceTag) filterAll | otherwise = return () + -- tag of the scratchpad workspace scratchpadWorkspaceTag :: String scratchpadWorkspaceTag = "NSP" -- cgit v1.2.3