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 :: [(WorkspaceId, X ())] -> Map WorkspaceId (X ())
commandMap = [(WorkspaceId, X ())] -> Map WorkspaceId (X ())
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
workspaceCommands :: X [(String, X ())]
workspaceCommands :: X [(WorkspaceId, X ())]
workspaceCommands = (XConf -> [WorkspaceId]) -> X [WorkspaceId]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (XConfig Layout -> [WorkspaceId]
forall (l :: * -> *). XConfig l -> [WorkspaceId]
workspaces (XConfig Layout -> [WorkspaceId])
-> (XConf -> XConfig Layout) -> XConf -> [WorkspaceId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConf -> XConfig Layout
config) X [WorkspaceId]
-> ([WorkspaceId] -> X [(WorkspaceId, X ())])
-> X [(WorkspaceId, X ())]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[WorkspaceId]
spaces -> [(WorkspaceId, X ())] -> X [(WorkspaceId, X ())]
forall (m :: * -> *) a. Monad m => a -> m a
return
[( WorkspaceId
m WorkspaceId -> WorkspaceId -> WorkspaceId
forall a. [a] -> [a] -> [a]
++ WorkspaceId -> WorkspaceId
forall a. Show a => a -> WorkspaceId
show WorkspaceId
i, (WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ WorkspaceId -> WindowSet -> WindowSet
f WorkspaceId
i)
| WorkspaceId
i <- [WorkspaceId]
spaces
, (WorkspaceId -> WindowSet -> WindowSet
f, WorkspaceId
m) <- [(WorkspaceId -> 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, WorkspaceId
"view"), (WorkspaceId -> 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, WorkspaceId
"shift")] ]
screenCommands :: [(String, X ())]
screenCommands :: [(WorkspaceId, X ())]
screenCommands = [( WorkspaceId
m WorkspaceId -> WorkspaceId -> WorkspaceId
forall a. [a] -> [a] -> [a]
++ Int -> WorkspaceId
forall a. Show a => a -> WorkspaceId
show Int
sc, ScreenId -> X (Maybe WorkspaceId)
screenWorkspace (Int -> ScreenId
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
sc) X (Maybe WorkspaceId) -> (Maybe WorkspaceId -> X ()) -> X ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Maybe WorkspaceId -> (WorkspaceId -> X ()) -> X ())
-> (WorkspaceId -> X ()) -> Maybe WorkspaceId -> X ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Maybe WorkspaceId -> (WorkspaceId -> X ()) -> X ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust ((WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WorkspaceId -> WindowSet -> WindowSet) -> WorkspaceId -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WorkspaceId -> WindowSet -> WindowSet
f))
| Int
sc <- [Int
0, Int
1]::[Int]
, (WorkspaceId -> WindowSet -> WindowSet
f, WorkspaceId
m) <- [(WorkspaceId -> 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, WorkspaceId
"screen"), (WorkspaceId -> 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, WorkspaceId
"screen-to-")]
]
defaultCommands :: X [(String, X ())]
defaultCommands :: X [(WorkspaceId, X ())]
defaultCommands = do
[(WorkspaceId, X ())]
wscmds <- X [(WorkspaceId, X ())]
workspaceCommands
[(WorkspaceId, X ())] -> X [(WorkspaceId, X ())]
forall (m :: * -> *) a. Monad m => a -> m a
return ([(WorkspaceId, X ())] -> X [(WorkspaceId, X ())])
-> [(WorkspaceId, X ())] -> X [(WorkspaceId, X ())]
forall a b. (a -> b) -> a -> b
$ [(WorkspaceId, X ())]
wscmds [(WorkspaceId, X ())]
-> [(WorkspaceId, X ())] -> [(WorkspaceId, X ())]
forall a. [a] -> [a] -> [a]
++ [(WorkspaceId, X ())]
screenCommands [(WorkspaceId, X ())]
-> [(WorkspaceId, X ())] -> [(WorkspaceId, X ())]
forall a. [a] -> [a] -> [a]
++ [(WorkspaceId, X ())]
otherCommands
where
otherCommands :: [(WorkspaceId, X ())]
otherCommands =
[ (WorkspaceId
"shrink" , Resize -> X ()
forall a. Message a => a -> X ()
sendMessage Resize
Shrink )
, (WorkspaceId
"expand" , Resize -> X ()
forall a. Message a => a -> X ()
sendMessage Resize
Expand )
, (WorkspaceId
"next-layout" , ChangeLayout -> X ()
forall a. Message a => a -> X ()
sendMessage ChangeLayout
NextLayout )
, (WorkspaceId
"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 (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Layout Window -> X ()
setLayout )
, (WorkspaceId
"restart-wm" , WorkspaceId -> Bool -> X ()
restart WorkspaceId
"xmonad" Bool
True )
, (WorkspaceId
"restart-wm-no-resume", WorkspaceId -> Bool -> X ()
restart WorkspaceId
"xmonad" Bool
False )
, (WorkspaceId
"xterm" , WorkspaceId -> X ()
forall (m :: * -> *). MonadIO m => WorkspaceId -> m ()
spawn (WorkspaceId -> X ()) -> X WorkspaceId -> X ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (XConf -> WorkspaceId) -> X WorkspaceId
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (XConfig Layout -> WorkspaceId
forall (l :: * -> *). XConfig l -> WorkspaceId
terminal (XConfig Layout -> WorkspaceId)
-> (XConf -> XConfig Layout) -> XConf -> WorkspaceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConf -> XConfig Layout
config) )
, (WorkspaceId
"run" , WorkspaceId -> X ()
forall (m :: * -> *). MonadIO m => WorkspaceId -> m ()
spawn WorkspaceId
"exe=`dmenu_path | dmenu -b` && exec $exe" )
, (WorkspaceId
"kill" , X ()
kill )
, (WorkspaceId
"refresh" , X ()
refresh )
, (WorkspaceId
"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 )
, (WorkspaceId
"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 )
, (WorkspaceId
"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 )
, (WorkspaceId
"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 )
, (WorkspaceId
"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 )
, (WorkspaceId
"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 )
, (WorkspaceId
"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 :: [(WorkspaceId, X ())] -> X ()
runCommand = ([WorkspaceId] -> X WorkspaceId) -> [(WorkspaceId, X ())] -> X ()
runCommandConfig [WorkspaceId] -> X WorkspaceId
forall (m :: * -> *). MonadIO m => [WorkspaceId] -> m WorkspaceId
dmenu
runCommandConfig :: ([String] -> X String) -> [(String, X ())] -> X()
runCommandConfig :: ([WorkspaceId] -> X WorkspaceId) -> [(WorkspaceId, X ())] -> X ()
runCommandConfig [WorkspaceId] -> X WorkspaceId
f [(WorkspaceId, X ())]
cl = do
let m :: Map WorkspaceId (X ())
m = [(WorkspaceId, X ())] -> Map WorkspaceId (X ())
commandMap [(WorkspaceId, X ())]
cl
WorkspaceId
choice <- [WorkspaceId] -> X WorkspaceId
f (Map WorkspaceId (X ()) -> [WorkspaceId]
forall k a. Map k a -> [k]
M.keys Map WorkspaceId (X ())
m)
X () -> Maybe (X ()) -> X ()
forall a. a -> Maybe a -> a
fromMaybe (() -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (WorkspaceId -> Map WorkspaceId (X ()) -> Maybe (X ())
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup WorkspaceId
choice Map WorkspaceId (X ())
m)
runCommand' :: String -> X ()
runCommand' :: WorkspaceId -> X ()
runCommand' WorkspaceId
c = do
Map WorkspaceId (X ())
m <- ([(WorkspaceId, X ())] -> Map WorkspaceId (X ()))
-> X [(WorkspaceId, X ())] -> X (Map WorkspaceId (X ()))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [(WorkspaceId, X ())] -> Map WorkspaceId (X ())
commandMap X [(WorkspaceId, X ())]
defaultCommands
X () -> Maybe (X ()) -> X ()
forall a. a -> Maybe a -> a
fromMaybe (() -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (WorkspaceId -> Map WorkspaceId (X ()) -> Maybe (X ())
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup WorkspaceId
c Map WorkspaceId (X ())
m)