module XMonad.Util.Dmenu (
dmenu, dmenuXinerama, dmenuMap, menu, menuArgs, menuMap, menuMapArgs
) where
import XMonad
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import XMonad.Util.Run
dmenuXinerama :: [String] -> X String
[String]
opts = do
Int
curscreen <-
ScreenId -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ScreenId -> Int)
-> (StackSet String (Layout Window) Window ScreenId ScreenDetail
-> ScreenId)
-> StackSet String (Layout Window) Window ScreenId ScreenDetail
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen String (Layout Window) Window ScreenId ScreenDetail
-> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
W.screen (Screen String (Layout Window) Window ScreenId ScreenDetail
-> ScreenId)
-> (StackSet String (Layout Window) Window ScreenId ScreenDetail
-> Screen String (Layout Window) Window ScreenId ScreenDetail)
-> StackSet String (Layout Window) Window ScreenId ScreenDetail
-> ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet String (Layout Window) Window ScreenId ScreenDetail
-> Screen String (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (StackSet String (Layout Window) Window ScreenId ScreenDetail
-> Int)
-> X (StackSet String (Layout Window) Window ScreenId ScreenDetail)
-> X Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (XState
-> StackSet String (Layout Window) Window ScreenId ScreenDetail)
-> X (StackSet String (Layout Window) Window ScreenId ScreenDetail)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState
-> StackSet String (Layout Window) Window ScreenId ScreenDetail
windowset :: X Int
String
_ <-
String -> [String] -> String -> X String
forall (m :: * -> *).
MonadIO m =>
String -> [String] -> String -> m String
runProcessWithInput String
"dmenu" [String
"-xs", Int -> String
forall a. Show a => a -> String
show (Int
curscreenInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)] ([String] -> String
unlines [String]
opts)
String -> [String] -> [String] -> X String
forall (m :: * -> *).
MonadIO m =>
String -> [String] -> [String] -> m String
menuArgs String
"dmenu" [String
"-xs", Int -> String
forall a. Show a => a -> String
show (Int
curscreenInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)] [String]
opts
dmenu :: MonadIO m => [String] -> m String
= String -> [String] -> m String
forall (m :: * -> *). MonadIO m => String -> [String] -> m String
menu String
"dmenu"
menu :: MonadIO m => String -> [String] -> m String
String
menuCmd = String -> [String] -> [String] -> m String
forall (m :: * -> *).
MonadIO m =>
String -> [String] -> [String] -> m String
menuArgs String
menuCmd []
menuArgs :: MonadIO m => String -> [String] -> [String] -> m String
String
menuCmd [String]
args [String]
opts = (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/=Char
'\n') (String -> String) -> m String -> m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
String -> [String] -> String -> m String
forall (m :: * -> *).
MonadIO m =>
String -> [String] -> String -> m String
runProcessWithInput String
menuCmd [String]
args ([String] -> String
unlines [String]
opts)
menuMap :: MonadIO m => String -> M.Map String a -> m (Maybe a)
String
menuCmd = String -> [String] -> Map String a -> m (Maybe a)
forall (m :: * -> *) a.
MonadIO m =>
String -> [String] -> Map String a -> m (Maybe a)
menuMapArgs String
menuCmd []
menuMapArgs :: MonadIO m => String -> [String] -> M.Map String a ->
m (Maybe a)
String
menuCmd [String]
args Map String a
selectionMap = do
String
selection <- [String] -> m String
menuFunction (Map String a -> [String]
forall k a. Map k a -> [k]
M.keys Map String a
selectionMap)
Maybe a -> m (Maybe a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> m (Maybe a)) -> Maybe a -> m (Maybe a)
forall a b. (a -> b) -> a -> b
$ String -> Map String a -> Maybe a
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup String
selection Map String a
selectionMap
where
menuFunction :: [String] -> m String
menuFunction = String -> [String] -> [String] -> m String
forall (m :: * -> *).
MonadIO m =>
String -> [String] -> [String] -> m String
menuArgs String
menuCmd [String]
args
dmenuMap :: MonadIO m => M.Map String a -> m (Maybe a)
= String -> Map String a -> m (Maybe a)
forall (m :: * -> *) a.
MonadIO m =>
String -> Map String a -> m (Maybe a)
menuMap String
"dmenu"