mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-01 12:41:52 -07:00
PerWorkspace: add modWorkspace(s) combinators, for selectively applying layout modifiers to certain workspaces but not others
This commit is contained in:
@@ -10,18 +10,22 @@
|
|||||||
-- Stability : unstable
|
-- Stability : unstable
|
||||||
-- Portability : unportable
|
-- Portability : unportable
|
||||||
--
|
--
|
||||||
-- Configure layouts on a per-workspace basis.
|
-- Configure layouts on a per-workspace basis: use layouts and apply
|
||||||
|
-- layout modifiers selectively, depending on the workspace.
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
module XMonad.Layout.PerWorkspace
|
module XMonad.Layout.PerWorkspace
|
||||||
( -- * Usage
|
( -- * Usage
|
||||||
-- $usage
|
-- $usage
|
||||||
onWorkspace, onWorkspaces
|
onWorkspace, onWorkspaces,
|
||||||
|
modWorkspace, modWorkspaces
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import qualified XMonad.StackSet as W
|
import qualified XMonad.StackSet as W
|
||||||
|
|
||||||
|
import XMonad.Layout.LayoutModifier
|
||||||
|
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
-- $usage
|
-- $usage
|
||||||
@@ -31,12 +35,15 @@ import Data.Maybe (fromMaybe)
|
|||||||
--
|
--
|
||||||
-- and modifying your layoutHook as follows (for example):
|
-- and modifying your layoutHook as follows (for example):
|
||||||
--
|
--
|
||||||
-- > layoutHook = onWorkspace "foo" l1 $ -- layout l1 will be used on workspace "foo".
|
-- > 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".
|
-- > onWorkspaces ["bar","6"] l2 $ -- layout l2 will be used on workspaces "bar" and "6".
|
||||||
-- > l3 -- layout l3 will be used on all other workspaces.
|
-- > l3 -- layout l3 will be used on all other workspaces.
|
||||||
--
|
--
|
||||||
-- Note that @l1@, @l2@, and @l3@ can be arbitrarily complicated layouts,
|
-- Note that @l1@, @l2@, and @l3@ can be arbitrarily complicated
|
||||||
-- e.g. @(Full ||| smartBorders $ tabbed shrinkText defaultTConf ||| ...)@
|
-- 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
|
-- In another scenario, suppose you wanted to have layouts A, B, and C
|
||||||
-- available on all workspaces, except that on workspace foo you want
|
-- available on all workspaces, except that on workspace foo you want
|
||||||
@@ -52,7 +59,7 @@ onWorkspace :: (LayoutClass l1 a, LayoutClass l2 a)
|
|||||||
-> (l1 a) -- ^ layout to use on the matched workspace
|
-> (l1 a) -- ^ layout to use on the matched workspace
|
||||||
-> (l2 a) -- ^ layout to use everywhere else
|
-> (l2 a) -- ^ layout to use everywhere else
|
||||||
-> PerWorkspace l1 l2 a
|
-> PerWorkspace l1 l2 a
|
||||||
onWorkspace wsId l1 l2 = PerWorkspace [wsId] False l1 l2
|
onWorkspace wsId = onWorkspaces [wsId]
|
||||||
|
|
||||||
-- | Specify one layout to use on a particular set of workspaces, and
|
-- | Specify one layout to use on a particular set of workspaces, and
|
||||||
-- another to use on all other workspaces.
|
-- another to use on all other workspaces.
|
||||||
@@ -63,6 +70,25 @@ onWorkspaces :: (LayoutClass l1 a, LayoutClass l2 a)
|
|||||||
-> PerWorkspace l1 l2 a
|
-> PerWorkspace l1 l2 a
|
||||||
onWorkspaces wsIds l1 l2 = PerWorkspace wsIds False l1 l2
|
onWorkspaces wsIds l1 l2 = PerWorkspace wsIds False l1 l2
|
||||||
|
|
||||||
|
-- | Specify a layout modifier to apply to a particular workspace; layouts
|
||||||
|
-- on all other workspaces will remain unmodified.
|
||||||
|
modWorkspace :: (LayoutClass l a)
|
||||||
|
=> WorkspaceId -- ^ tag of the workspace to match
|
||||||
|
-> (l a -> ModifiedLayout lm l a) -- ^ the modifier to apply on the matching workspace
|
||||||
|
-> l a -- ^ the base layout
|
||||||
|
-> PerWorkspace (ModifiedLayout lm l) l a
|
||||||
|
modWorkspace wsId = modWorkspaces [wsId]
|
||||||
|
|
||||||
|
-- | Specify a layout modifier to apply to a particular set of
|
||||||
|
-- workspaces; layouts on all other workspaces will remain
|
||||||
|
-- unmodified.
|
||||||
|
modWorkspaces :: (LayoutClass l a)
|
||||||
|
=> [WorkspaceId] -- ^ tags of the workspaces to match
|
||||||
|
-> (l a -> ModifiedLayout lm l a) -- ^ the modifier to apply on the matching workspaces
|
||||||
|
-> l a -- ^ the base layout
|
||||||
|
-> PerWorkspace (ModifiedLayout lm l) l a
|
||||||
|
modWorkspaces wsIds f l = PerWorkspace wsIds False (f l) l
|
||||||
|
|
||||||
-- | Structure for representing a workspace-specific layout along with
|
-- | Structure for representing a workspace-specific layout along with
|
||||||
-- a layout for all other workspaces. We store the tags of workspaces
|
-- 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
|
-- to be matched, and the two layouts. We save the layout choice in
|
||||||
@@ -97,3 +123,4 @@ mkNewPerWorkspaceF :: PerWorkspace l1 l2 a -> Maybe (l2 a) ->
|
|||||||
PerWorkspace l1 l2 a
|
PerWorkspace l1 l2 a
|
||||||
mkNewPerWorkspaceF (PerWorkspace wsIds _ lt lf) mlf' =
|
mkNewPerWorkspaceF (PerWorkspace wsIds _ lt lf) mlf' =
|
||||||
(\lf' -> PerWorkspace wsIds False lt lf') $ fromMaybe lf mlf'
|
(\lf' -> PerWorkspace wsIds False lt lf') $ fromMaybe lf mlf'
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user