summaryrefslogtreecommitdiffstats
path: root/lass/5pkgs/xmonad-lass/Util/PerWorkspaceConfig.hs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2015-12-20 19:37:46 +0100
committertv <tv@krebsco.de>2015-12-20 19:37:46 +0100
commitc89907175546aa0c39bc6b2c4960f0ea6e6db8c9 (patch)
tree158bf1a5938fc37efc466b00b3f0906ac2a50d9f /lass/5pkgs/xmonad-lass/Util/PerWorkspaceConfig.hs
parentc09bc6a29f21f1c6bd21575e385b8b3bc5c89b8a (diff)
parent5821d8438578db623a3e248c52fefa424fad0b51 (diff)
Merge remote-tracking branch 'gum/master'
Diffstat (limited to 'lass/5pkgs/xmonad-lass/Util/PerWorkspaceConfig.hs')
-rw-r--r--lass/5pkgs/xmonad-lass/Util/PerWorkspaceConfig.hs52
1 files changed, 52 insertions, 0 deletions
diff --git a/lass/5pkgs/xmonad-lass/Util/PerWorkspaceConfig.hs b/lass/5pkgs/xmonad-lass/Util/PerWorkspaceConfig.hs
new file mode 100644
index 000000000..bba7c8c60
--- /dev/null
+++ b/lass/5pkgs/xmonad-lass/Util/PerWorkspaceConfig.hs
@@ -0,0 +1,52 @@
+module Util.PerWorkspaceConfig
+ ( WorkspaceConfig (..)
+ , WorkspaceConfigs
+ , switchToWorkspace
+ , defaultWorkspaceConfig
+ , perWorkspaceAction
+ , perWorkspaceTermAction
+-- , myLayoutHack
+ )
+where
+
+import XMonad
+import XMonad.Core (LayoutClass)
+import Control.Monad (when)
+
+import qualified Data.Map as M
+import qualified XMonad.StackSet as W
+
+data WorkspaceConfig l =
+ WorkspaceConfig
+ { switchAction :: X ()
+ , startAction :: X ()
+ , keyAction :: X ()
+ , termAction :: X ()
+ }
+
+type WorkspaceConfigs l = M.Map WorkspaceId (WorkspaceConfig l)
+
+defaultWorkspaceConfig = WorkspaceConfig
+ { switchAction = return ()
+ , startAction = return ()
+ , keyAction = return ()
+ , termAction = spawn "urxvtc"
+ }
+
+whenLookup wsId cfg a =
+ when (M.member wsId cfg) (a $ cfg M.! wsId)
+
+switchToWorkspace :: WorkspaceConfigs l -> WorkspaceId -> X ()
+switchToWorkspace cfg wsId = do
+ windows $ W.greedyView wsId
+ wins <- gets (W.integrate' . W.stack . W.workspace . W.current . windowset)
+ when (null wins) $ whenLookup wsId cfg startAction
+ whenLookup wsId cfg switchAction
+
+perWorkspaceAction :: WorkspaceConfigs l -> X ()
+perWorkspaceAction cfg = withWindowSet $ \s -> whenLookup (W.currentTag s) cfg keyAction
+
+perWorkspaceTermAction :: WorkspaceConfigs l -> X ()
+perWorkspaceTermAction cfg = withWindowSet $ \s -> case M.lookup (W.currentTag s) cfg of
+ Just x -> termAction x
+ _ -> termAction defaultWorkspaceConfig