summaryrefslogtreecommitdiffstats
path: root/lass/5pkgs/xmonad-lass/Util/PerWorkspaceConfig.hs
blob: bba7c8c60d5170aebfb852515b59e7ef8a4e6108 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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