{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}------------------------------------------------------------------------------- |-- Module : XMonad.Layout.PerWorkspace-- Copyright : (c) Brent Yorgey-- License : BSD-style (see LICENSE)---- Maintainer : <byorgey@gmail.com>-- Stability : unstable-- Portability : unportable---- Configure layouts on a per-workspace basis: use layouts and apply-- layout modifiers selectively, depending on the workspace.-----------------------------------------------------------------------------moduleXMonad.Layout.PerWorkspace(-- * Usage-- $usagePerWorkspace,onWorkspace,onWorkspaces,modWorkspace,modWorkspaces)whereimportXMonadimportqualifiedXMonad.StackSetasWimportXMonad.Layout.LayoutModifierimportData.Maybe(fromMaybe)-- $usage-- You can use this module by importing it into your ~\/.xmonad\/xmonad.hs file:---- > import XMonad.Layout.PerWorkspace---- and modifying your layoutHook as follows (for example):---- > layoutHook = modWorkspace "baz" m1 $ -- apply layout modifier m1 to all layouts on workspace "baz"-- > onWorkspace "foo" l1 $ -- layout l1 will be used on workspace "foo".-- > onWorkspaces ["bar","6"] l2 $ -- layout l2 will be used on workspaces "bar" and "6".-- > l3 -- layout l3 will be used on all other workspaces.---- Note that @l1@, @l2@, and @l3@ can be arbitrarily complicated-- layouts, e.g. @(Full ||| smartBorders $ tabbed shrinkText-- defaultTConf ||| ...)@, and @m1@ can be any layout modifier, i.e. a-- function of type @(l a -> ModifiedLayout lm l a)@.---- In another scenario, suppose you wanted to have layouts A, B, and C-- available on all workspaces, except that on workspace foo you want-- layout D instead of C. You could do that as follows:---- > layoutHook = A ||| B ||| onWorkspace "foo" D C-- | Specify one layout to use on a particular workspace, and another-- to use on all others. The second layout can be another call to-- 'onWorkspace', and so on.onWorkspace::(LayoutClassl1a,LayoutClassl2a)=>WorkspaceId-- ^ the tag of the workspace to match->(l1a)-- ^ layout to use on the matched workspace->(l2a)-- ^ layout to use everywhere else->PerWorkspacel1l2aonWorkspacewsId=onWorkspaces[wsId]-- | Specify one layout to use on a particular set of workspaces, and-- another to use on all other workspaces.onWorkspaces::(LayoutClassl1a,LayoutClassl2a)=>[WorkspaceId]-- ^ tags of workspaces to match->(l1a)-- ^ layout to use on matched workspaces->(l2a)-- ^ layout to use everywhere else->PerWorkspacel1l2aonWorkspaceswsIdsl1l2=PerWorkspacewsIdsFalsel1l2-- | Specify a layout modifier to apply to a particular workspace; layouts-- on all other workspaces will remain unmodified.modWorkspace::(LayoutClassla)=>WorkspaceId-- ^ tag of the workspace to match->(la->ModifiedLayoutlmla)-- ^ the modifier to apply on the matching workspace->la-- ^ the base layout->PerWorkspace(ModifiedLayoutlml)lamodWorkspacewsId=modWorkspaces[wsId]-- | Specify a layout modifier to apply to a particular set of-- workspaces; layouts on all other workspaces will remain-- unmodified.modWorkspaces::(LayoutClassla)=>[WorkspaceId]-- ^ tags of the workspaces to match->(la->ModifiedLayoutlmla)-- ^ the modifier to apply on the matching workspaces->la-- ^ the base layout->PerWorkspace(ModifiedLayoutlml)lamodWorkspaceswsIdsfl=PerWorkspacewsIdsFalse(fl)l-- | Structure for representing a workspace-specific layout along with-- a layout for all other workspaces. We store the tags of workspaces-- to be matched, and the two layouts. We save the layout choice in-- the Bool, to be used to implement description.dataPerWorkspacel1l2a=PerWorkspace[WorkspaceId]Bool(l1a)(l2a)deriving(Read,Show)instance(LayoutClassl1a,LayoutClassl2a,Showa)=>LayoutClass(PerWorkspacel1l2)awhererunLayout(W.Workspaceip@(PerWorkspacewsIds_ltlf)ms)r|i`elem`wsIds=do(wrs,mlt')<-runLayout(W.Workspaceiltms)rreturn(wrs,Just$mkNewPerWorkspaceTpmlt')|otherwise=do(wrs,mlt')<-runLayout(W.Workspaceilfms)rreturn(wrs,Just$mkNewPerWorkspaceFpmlt')handleMessage(PerWorkspacewsIdsboolltlf)m|bool=handleMessageltm>>=maybe(returnNothing)(\nt->return.Just$PerWorkspacewsIdsboolntlf)|otherwise=handleMessagelfm>>=maybe(returnNothing)(\nf->return.Just$PerWorkspacewsIdsboolltnf)description(PerWorkspace_Truel1_)=descriptionl1description(PerWorkspace___l2)=descriptionl2-- | Construct new PerWorkspace values with possibly modified layouts.mkNewPerWorkspaceT::PerWorkspacel1l2a->Maybe(l1a)->PerWorkspacel1l2amkNewPerWorkspaceT(PerWorkspacewsIds_ltlf)mlt'=(\lt'->PerWorkspacewsIdsTruelt'lf)$fromMaybeltmlt'mkNewPerWorkspaceF::PerWorkspacel1l2a->Maybe(l2a)->PerWorkspacel1l2amkNewPerWorkspaceF(PerWorkspacewsIds_ltlf)mlf'=(\lf'->PerWorkspacewsIdsFalseltlf')$fromMaybelfmlf'