module XMonad.Actions.Commands (
commandMap,
runCommand,
runCommandConfig,
runCommand',
workspaceCommands,
screenCommands,
defaultCommands
) where
import XMonad
import XMonad.StackSet hiding (workspaces)
import XMonad.Util.Dmenu (dmenu)
import qualified Data.Map as M
import System.Exit
import XMonad.Prelude
commandMap :: [(String, X ())] -> M.Map String (X ())
commandMap :: [([Char], X ())] -> Map [Char] (X ())
commandMap = [([Char], X ())] -> Map [Char] (X ())
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
workspaceCommands :: X [(String, X ())]
workspaceCommands :: X [([Char], X ())]
workspaceCommands = (XConf -> [[Char]]) -> X [[Char]]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (XConfig Layout -> [[Char]]
forall (l :: * -> *). XConfig l -> [[Char]]
workspaces (XConfig Layout -> [[Char]])
-> (XConf -> XConfig Layout) -> XConf -> [[Char]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConf -> XConfig Layout
config) X [[Char]]
-> ([[Char]] -> X [([Char], X ())]) -> X [([Char], X ())]
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[[Char]]
spaces -> [([Char], X ())] -> X [([Char], X ())]
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return
[( [Char]
m [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char] -> [Char]
forall a. Show a => a -> [Char]
show [Char]
i, (WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ [Char] -> WindowSet -> WindowSet
f [Char]
i)
| [Char]
i <- [[Char]]
spaces
, ([Char] -> WindowSet -> WindowSet
f, [Char]
m) <- [([Char] -> WindowSet -> WindowSet
forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
view, [Char]
"view"), ([Char] -> WindowSet -> WindowSet
forall a s i l sd.
(Ord a, Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
shift, [Char]
"shift")] ]
screenCommands :: [(String, X ())]
screenCommands :: [([Char], X ())]
screenCommands = [( [Char]
m [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
sc, ScreenId -> X (Maybe [Char])
screenWorkspace (Int -> ScreenId
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
sc) X (Maybe [Char]) -> (Maybe [Char] -> X ()) -> X ()
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Maybe [Char] -> ([Char] -> X ()) -> X ())
-> ([Char] -> X ()) -> Maybe [Char] -> X ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Maybe [Char] -> ([Char] -> X ()) -> X ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust ((WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> ([Char] -> WindowSet -> WindowSet) -> [Char] -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> WindowSet -> WindowSet
f))
| Int
sc <- [Int
0, Int
1]::[Int]
, ([Char] -> WindowSet -> WindowSet
f, [Char]
m) <- [([Char] -> WindowSet -> WindowSet
forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
view, [Char]
"screen"), ([Char] -> WindowSet -> WindowSet
forall a s i l sd.
(Ord a, Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
shift, [Char]
"screen-to-")]
]
defaultCommands :: X [(String, X ())]
defaultCommands :: X [([Char], X ())]
defaultCommands = do
wscmds <- X [([Char], X ())]
workspaceCommands
return $ wscmds ++ screenCommands ++ otherCommands
where
otherCommands :: [([Char], X ())]
otherCommands =
[ ([Char]
"shrink" , Resize -> X ()
forall a. Message a => a -> X ()
sendMessage Resize
Shrink )
, ([Char]
"expand" , Resize -> X ()
forall a. Message a => a -> X ()
sendMessage Resize
Expand )
, ([Char]
"next-layout" , ChangeLayout -> X ()
forall a. Message a => a -> X ()
sendMessage ChangeLayout
NextLayout )
, ([Char]
"default-layout" , (XConf -> Layout Window) -> X (Layout Window)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (XConfig Layout -> Layout Window
forall (l :: * -> *). XConfig l -> l Window
layoutHook (XConfig Layout -> Layout Window)
-> (XConf -> XConfig Layout) -> XConf -> Layout Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConf -> XConfig Layout
config) X (Layout Window) -> (Layout Window -> X ()) -> X ()
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Layout Window -> X ()
setLayout )
, ([Char]
"restart-wm" , [Char] -> Bool -> X ()
restart [Char]
"xmonad" Bool
True )
, ([Char]
"restart-wm-no-resume", [Char] -> Bool -> X ()
restart [Char]
"xmonad" Bool
False )
, ([Char]
"xterm" , [Char] -> X ()
forall (m :: * -> *). MonadIO m => [Char] -> m ()
spawn ([Char] -> X ()) -> X [Char] -> X ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (XConf -> [Char]) -> X [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (XConfig Layout -> [Char]
forall (l :: * -> *). XConfig l -> [Char]
terminal (XConfig Layout -> [Char])
-> (XConf -> XConfig Layout) -> XConf -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConf -> XConfig Layout
config) )
, ([Char]
"run" , [Char] -> X ()
forall (m :: * -> *). MonadIO m => [Char] -> m ()
spawn [Char]
"exe=`dmenu_path | dmenu -b` && exec $exe" )
, ([Char]
"kill" , X ()
kill )
, ([Char]
"refresh" , X ()
refresh )
, ([Char]
"focus-up" , (WindowSet -> WindowSet) -> X ()
windows WindowSet -> WindowSet
forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
focusUp )
, ([Char]
"focus-down" , (WindowSet -> WindowSet) -> X ()
windows WindowSet -> WindowSet
forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
focusDown )
, ([Char]
"swap-up" , (WindowSet -> WindowSet) -> X ()
windows WindowSet -> WindowSet
forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
swapUp )
, ([Char]
"swap-down" , (WindowSet -> WindowSet) -> X ()
windows WindowSet -> WindowSet
forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
swapDown )
, ([Char]
"swap-master" , (WindowSet -> WindowSet) -> X ()
windows WindowSet -> WindowSet
forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
swapMaster )
, ([Char]
"sink" , (Window -> X ()) -> X ()
withFocused ((Window -> X ()) -> X ()) -> (Window -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ (WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (Window -> WindowSet -> WindowSet) -> Window -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> WindowSet -> WindowSet
forall a i l s sd.
Ord a =>
a -> StackSet i l a s sd -> StackSet i l a s sd
sink )
, ([Char]
"quit-wm" , IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io IO ()
forall a. IO a
exitSuccess )
]
runCommand :: [(String, X ())] -> X ()
runCommand :: [([Char], X ())] -> X ()
runCommand = ([[Char]] -> X [Char]) -> [([Char], X ())] -> X ()
runCommandConfig [[Char]] -> X [Char]
forall (m :: * -> *). MonadIO m => [[Char]] -> m [Char]
dmenu
runCommandConfig :: ([String] -> X String) -> [(String, X ())] -> X()
runCommandConfig :: ([[Char]] -> X [Char]) -> [([Char], X ())] -> X ()
runCommandConfig [[Char]] -> X [Char]
f [([Char], X ())]
cl = do
let m :: Map [Char] (X ())
m = [([Char], X ())] -> Map [Char] (X ())
commandMap [([Char], X ())]
cl
choice <- [[Char]] -> X [Char]
f (Map [Char] (X ()) -> [[Char]]
forall k a. Map k a -> [k]
M.keys Map [Char] (X ())
m)
fromMaybe (return ()) (M.lookup choice m)
runCommand' :: String -> X ()
runCommand' :: [Char] -> X ()
runCommand' [Char]
c = do
m <- ([([Char], X ())] -> Map [Char] (X ()))
-> X [([Char], X ())] -> X (Map [Char] (X ()))
forall a b. (a -> b) -> X a -> X b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [([Char], X ())] -> Map [Char] (X ())
commandMap X [([Char], X ())]
defaultCommands
fromMaybe (return ()) (M.lookup c m)