aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Actions/PerWorkspaceKeys.hs
diff options
context:
space:
mode:
authorRoman Cheplyaka <roma@ro-che.info>2008-03-02 21:23:46 +0100
committerRoman Cheplyaka <roma@ro-che.info>2008-03-02 21:23:46 +0100
commitab9b9ba8ca23858eafd0d9b152bea50ef1a958dc (patch)
tree70b73eb3ff3c3439b85c7341acd5e978a5564f0c /XMonad/Actions/PerWorkspaceKeys.hs
parentcf341f3a0af4f6bd64b3c5e7a2113eea548cf874 (diff)
downloadXMonadContrib-ab9b9ba8ca23858eafd0d9b152bea50ef1a958dc.tar.gz
XMonadContrib-ab9b9ba8ca23858eafd0d9b152bea50ef1a958dc.tar.xz
XMonadContrib-ab9b9ba8ca23858eafd0d9b152bea50ef1a958dc.zip
Add XMonad.Actions.PerWorkspaceKeys
darcs-hash:20080302202346-3ebed-e62add839eb2d1449b6f6edf3b4d1b13961a7e4b.gz
Diffstat (limited to 'XMonad/Actions/PerWorkspaceKeys.hs')
-rw-r--r--XMonad/Actions/PerWorkspaceKeys.hs50
1 files changed, 50 insertions, 0 deletions
diff --git a/XMonad/Actions/PerWorkspaceKeys.hs b/XMonad/Actions/PerWorkspaceKeys.hs
new file mode 100644
index 0000000..9dd6a5d
--- /dev/null
+++ b/XMonad/Actions/PerWorkspaceKeys.hs
@@ -0,0 +1,50 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonad.Actions.PerWorkspaceKeys
+-- Copyright : (c) Roman Cheplyaka, 2008
+-- License : BSD3-style (see LICENSE)
+--
+-- Maintainer : Roman Cheplyaka <roma@ro-che.info>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- Define key-bindings on per-workspace basis.
+--
+-----------------------------------------------------------------------------
+
+module XMonad.Actions.PerWorkspaceKeys (
+ -- * Usage
+ -- $usage
+ chooseAction,
+ bindOn
+ ) where
+
+import XMonad
+import XMonad.StackSet as S
+import Data.List (find)
+
+-- $usage
+--
+-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
+--
+-- > import XMonad.Actions.PerWorkspaceKeys
+--
+-- > ,((0, xK_F2), bindOn [("1", spawn "rxvt"), ("2", spawn "xeyes"), ("", spawn "xmessage hello")])
+--
+-- For detailed instructions on editing your key bindings, see
+-- "XMonad.Doc.Extending#Editing_key_bindings".
+
+-- | Uses supplied function to decide which action to run depending on current workspace name.
+chooseAction :: (String->X()) -> X()
+chooseAction f = withWindowSet (f . S.tag . S.workspace . S.current)
+
+-- | If current workspace is listed, run appropriate action (only the first match counts!)
+-- If it isn't listed, then run default action (marked with empty string, \"\"), or do nothing if default isn't supplied.
+bindOn :: [(String, X())] -> X()
+bindOn bindings = chooseAction chooser where
+ chooser ws = case find ((ws==).fst) bindings of
+ Just (_, action) -> action
+ Nothing -> case find ((""==).fst) bindings of
+ Just (_, action) -> action
+ Nothing -> return ()
+