1
0
mirror of https://github.com/xmonad/xmonad-contrib.git synced 2025-07-28 10:41:52 -07:00

simplify WindowBringer code, and change greedyView to focusWindow

This commit is contained in:
Devin Mullins
2008-08-11 03:31:37 +00:00
parent 1c03ecc596
commit e58933b9c1
2 changed files with 20 additions and 21 deletions
XMonad

@@ -17,7 +17,8 @@
module XMonad.Actions.WindowBringer ( module XMonad.Actions.WindowBringer (
-- * Usage -- * Usage
-- $usage -- $usage
gotoMenu, bringMenu, windowMapWith gotoMenu, bringMenu, windowMap,
bringWindow
) where ) where
import Data.Char (toLower) import Data.Char (toLower)
@@ -47,29 +48,29 @@ import XMonad.Util.NamedWindows (getName)
-- | Pops open a dmenu with window titles. Choose one, and you will be -- | Pops open a dmenu with window titles. Choose one, and you will be
-- taken to the corresponding workspace. -- taken to the corresponding workspace.
gotoMenu :: X () gotoMenu :: X ()
gotoMenu = workspaceMap >>= actionMenu (windows . W.greedyView) gotoMenu = actionMenu W.focusWindow
where workspaceMap = windowMapWith (W.tag . fst)
-- | Pops open a dmenu with window titles. Choose one, and it will be -- | Pops open a dmenu with window titles. Choose one, and it will be
-- dragged, kicking and screaming, into your current workspace. -- dragged, kicking and screaming, into your current workspace.
bringMenu :: X () bringMenu :: X ()
bringMenu = windowMap >>= actionMenu (windows . bringWindow) bringMenu = actionMenu bringWindow
where windowMap = windowMapWith snd
bringWindow w ws = W.shiftWin (W.tag . W.workspace . W.current $ ws) w ws
-- | Calls dmenuMap to grab the appropriate element from the Map, and hands it -- | Brings the specified window into the current workspace.
-- off to action if found. bringWindow :: Window -> X.WindowSet -> X.WindowSet
actionMenu :: (a -> X ()) -> M.Map String a -> X () bringWindow w ws = W.shiftWin (W.tag . W.workspace . W.current $ ws) w ws
actionMenu action windowMap = dmenuMap windowMap >>= flip X.whenJust action
-- | Generates a Map from window name to \<whatever you specify\>. For -- | Calls dmenuMap to grab the appropriate Window, and hands it off to action
-- use with dmenuMap. -- if found.
windowMapWith :: ((X.WindowSpace, Window) -> a) -> X (M.Map String a) actionMenu :: (Window -> X.WindowSet -> X.WindowSet) -> X()
windowMapWith value = do -- TODO: extract the pure, creamy center. actionMenu action = windowMap >>= dmenuMap >>= flip X.whenJust (windows . action)
-- | A map from window names to Windows.
windowMap :: X (M.Map String Window)
windowMap = do
ws <- gets X.windowset ws <- gets X.windowset
M.fromList `fmap` concat `fmap` mapM keyValuePairs (W.workspaces ws) M.fromList `fmap` concat `fmap` mapM keyValuePairs (W.workspaces ws)
where keyValuePairs ws = mapM (keyValuePair ws) $ W.integrate' (W.stack ws) where keyValuePairs ws = mapM (keyValuePair ws) $ W.integrate' (W.stack ws)
keyValuePair ws w = flip (,) (value (ws, w)) `fmap` decorateName ws w keyValuePair ws w = flip (,) w `fmap` decorateName ws w
-- | Returns the window name as will be listed in dmenu. -- | Returns the window name as will be listed in dmenu.
-- Lowercased, for your convenience (since dmenu is case-sensitive). -- Lowercased, for your convenience (since dmenu is case-sensitive).

@@ -73,16 +73,14 @@ windowPromptBring c = doPrompt Bring c
doPrompt :: WindowPrompt -> XPConfig -> X () doPrompt :: WindowPrompt -> XPConfig -> X ()
doPrompt t c = do doPrompt t c = do
a <- case t of a <- case t of
Goto -> return . gotoAction =<< windowMapWith (W.tag . fst) Goto -> fmap gotoAction windowMap
Bring -> return . bringAction =<< windowMapWith snd Bring -> fmap bringAction windowMap
wm <- windowMapWith id wm <- windowMap
mkXPrompt t c (compList wm) a mkXPrompt t c (compList wm) a
where where
winAction a m = flip whenJust (windows . a) . flip M.lookup m winAction a m = flip whenJust (windows . a) . flip M.lookup m
gotoAction = winAction W.greedyView gotoAction = winAction W.focusWindow
bringAction = winAction bringWindow bringAction = winAction bringWindow
bringWindow w ws = W.shiftWin (W.tag . W.workspace . W.current $ ws) w ws
compList m s = return . filter (isPrefixOf s) . map fst . M.toList $ m compList m s = return . filter (isPrefixOf s) . map fst . M.toList $ m