X.A.WorkspaceNames: add getWorkspaceNames'

This commit is contained in:
Tomas Janousek
2016-11-07 20:57:45 +01:00
parent ec5f9a9e59
commit 7ada94df42

View File

@@ -24,6 +24,7 @@ module XMonad.Actions.WorkspaceNames (
-- * Workspace naming -- * Workspace naming
renameWorkspace, renameWorkspace,
workspaceNamesPP, workspaceNamesPP,
getWorkspaceNames',
getWorkspaceNames, getWorkspaceNames,
getWorkspaceName, getWorkspaceName,
getCurrentWorkspaceName, getCurrentWorkspaceName,
@@ -90,20 +91,22 @@ instance ExtensionClass WorkspaceNames where
initialValue = WorkspaceNames M.empty initialValue = WorkspaceNames M.empty
extensionType = PersistentExtension extensionType = PersistentExtension
-- | Returns a lookup function that maps workspace tags to workspace names.
getWorkspaceNames' :: X (WorkspaceId -> Maybe String)
getWorkspaceNames' = do
WorkspaceNames m <- XS.get
return (`M.lookup` m)
-- | Returns a function that maps workspace tag @\"t\"@ to @\"t:name\"@ for -- | Returns a function that maps workspace tag @\"t\"@ to @\"t:name\"@ for
-- workspaces with a name, and to @\"t\"@ otherwise. -- workspaces with a name, and to @\"t\"@ otherwise.
getWorkspaceNames :: X (WorkspaceId -> String) getWorkspaceNames :: X (WorkspaceId -> String)
getWorkspaceNames = do getWorkspaceNames = do
WorkspaceNames m <- XS.get lookup <- getWorkspaceNames'
return $ \wks -> case M.lookup wks m of return $ \wks -> wks ++ maybe "" (':' :) (lookup wks)
Nothing -> wks
Just s -> wks ++ ":" ++ s
-- | Gets the name of a workspace, if set, otherwise returns nothing. -- | Gets the name of a workspace, if set, otherwise returns nothing.
getWorkspaceName :: WorkspaceId -> X (Maybe String) getWorkspaceName :: WorkspaceId -> X (Maybe String)
getWorkspaceName w = do getWorkspaceName w = ($ w) `fmap` getWorkspaceNames'
WorkspaceNames m <- XS.get
return $ M.lookup w m
-- | Gets the name of the current workspace. See 'getWorkspaceName' -- | Gets the name of the current workspace. See 'getWorkspaceName'
getCurrentWorkspaceName :: X (Maybe String) getCurrentWorkspaceName :: X (Maybe String)