generic menu and window bringer

This commit is contained in:
Travis B. Hartwell
2008-10-27 00:55:23 +00:00
parent 1e30ffe2c6
commit b849ccb29e
2 changed files with 32 additions and 15 deletions

View File

@@ -15,11 +15,11 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module XMonad.Actions.WindowBringer ( module XMonad.Actions.WindowBringer (
-- * Usage -- * Usage
-- $usage -- $usage
gotoMenu, bringMenu, windowMap, gotoMenu, gotoMenu', bringMenu, windowMap,
bringWindow bringWindow
) where ) where
import Data.Char (toLower) import Data.Char (toLower)
import qualified Data.Map as M import qualified Data.Map as M
@@ -27,7 +27,7 @@ import qualified Data.Map as M
import qualified XMonad.StackSet as W import qualified XMonad.StackSet as W
import XMonad import XMonad
import qualified XMonad as X import qualified XMonad as X
import XMonad.Util.Dmenu (dmenuMap) import XMonad.Util.Dmenu (menuMap)
import XMonad.Util.NamedWindows (getName) import XMonad.Util.NamedWindows (getName)
-- $usage -- $usage
@@ -50,6 +50,9 @@ import XMonad.Util.NamedWindows (getName)
gotoMenu :: X () gotoMenu :: X ()
gotoMenu = actionMenu W.focusWindow gotoMenu = actionMenu W.focusWindow
gotoMenu' :: String -> X ()
gotoMenu' menuCmd = actionMenu' menuCmd W.focusWindow
-- | 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 ()
@@ -62,7 +65,13 @@ bringWindow w ws = W.shiftWin (W.currentTag ws) w ws
-- | Calls dmenuMap to grab the appropriate Window, and hands it off to action -- | Calls dmenuMap to grab the appropriate Window, and hands it off to action
-- if found. -- if found.
actionMenu :: (Window -> X.WindowSet -> X.WindowSet) -> X() actionMenu :: (Window -> X.WindowSet -> X.WindowSet) -> X()
actionMenu action = windowMap >>= dmenuMap >>= flip X.whenJust (windows . action) actionMenu action = actionMenu' "dmenu" action
actionMenu' :: String -> (Window -> X.WindowSet -> X.WindowSet) -> X()
actionMenu' menuCmd action = windowMap >>= menuMapFunction >>= flip X.whenJust (windows . action)
where
menuMapFunction :: M.Map String a -> X (Maybe a)
menuMapFunction selectionMap = menuMap menuCmd selectionMap
-- | A map from window names to Windows. -- | A map from window names to Windows.
windowMap :: X (M.Map String Window) windowMap :: X (M.Map String Window)

View File

@@ -15,10 +15,10 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module XMonad.Util.Dmenu ( module XMonad.Util.Dmenu (
-- * Usage -- * Usage
-- $usage -- $usage
dmenu, dmenuXinerama, dmenuMap dmenu, dmenuXinerama, dmenuMap, menu, menuMap
) where ) where
import XMonad import XMonad
import qualified XMonad.StackSet as W import qualified XMonad.StackSet as W
@@ -40,9 +40,17 @@ dmenuXinerama opts = do
io $ runProcessWithInput "dmenu" ["-xs", show (curscreen+1)] (unlines opts) io $ runProcessWithInput "dmenu" ["-xs", show (curscreen+1)] (unlines opts)
dmenu :: [String] -> X String dmenu :: [String] -> X String
dmenu opts = io $ runProcessWithInput "dmenu" [] (unlines opts) dmenu opts = menu "dmenu" opts
menu :: String -> [String] -> X String
menu menuCmd opts = io $ runProcessWithInput menuCmd [] (unlines opts)
menuMap :: String -> M.Map String a -> X (Maybe a)
menuMap menuCmd selectionMap = do
selection <- menuFunction (M.keys selectionMap)
return $ M.lookup selection selectionMap
where
menuFunction = menu menuCmd
dmenuMap :: M.Map String a -> X (Maybe a) dmenuMap :: M.Map String a -> X (Maybe a)
dmenuMap selectionMap = do dmenuMap selectionMap = menuMap "dmenu" selectionMap
selection <- dmenu (M.keys selectionMap)
return $ M.lookup selection selectionMap