mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 03:20:21 -07:00
X.A.TopicSpace: More aggressively use X.H.WorkspaceHistory
Ever since ce5aae54035957846baa68f8980218cd11334722 TopicSpace uses the history implementation of X.H.WorkspaceHistory instead of something hand-rolled. This, however, did not go far enough; at this point, we can deprecate essentially all of TopicSpace's redundant history handling and explicitly tell users to use the more modular X.H.WorkspaceHistory instead.
This commit is contained in:
parent
280c1a8ed5
commit
3c4f42d2da
@ -29,7 +29,6 @@ module XMonad.Actions.TopicSpace
|
||||
|
||||
-- * Switching and Shifting Topics
|
||||
, switchTopic
|
||||
, switchTopicWith
|
||||
, switchNthLastFocused
|
||||
, switchNthLastFocusedByScreen
|
||||
, switchNthLastFocusedExclude
|
||||
@ -42,12 +41,17 @@ module XMonad.Actions.TopicSpace
|
||||
|
||||
-- * Getting the Topic History
|
||||
, getLastFocusedTopics
|
||||
, getLastFocusedTopicsByScreen
|
||||
, workspaceHistory
|
||||
, workspaceHistoryByScreen
|
||||
|
||||
-- * Modifying the Topic History
|
||||
, setLastFocusedTopic
|
||||
, reverseLastFocusedTopics
|
||||
|
||||
-- * History hooks
|
||||
, workspaceHistoryHook
|
||||
, workspaceHistoryHookExclude
|
||||
|
||||
-- * Pretty Printing
|
||||
, pprWindowSet
|
||||
|
||||
@ -78,6 +82,8 @@ import XMonad.Hooks.UrgencyHook (readUrgents)
|
||||
import XMonad.Hooks.WorkspaceHistory
|
||||
( workspaceHistory
|
||||
, workspaceHistoryByScreen
|
||||
, workspaceHistoryHook
|
||||
, workspaceHistoryHookExclude
|
||||
, workspaceHistoryModify
|
||||
)
|
||||
|
||||
@ -113,6 +119,12 @@ import XMonad.Util.Run (spawnPipe)
|
||||
-- * Replace the @workspaces@ field in your 'XConfig' with a list of your
|
||||
-- topics names
|
||||
--
|
||||
-- * Optionally, if you want to use the history features, add
|
||||
-- 'workspaceHistoryHook' from "XMonad.Hooks.WorkspaceHistory"
|
||||
-- (re-exported by this module) or an equivalent function to your
|
||||
-- @logHook@. See the documentation of
|
||||
-- "XMonad.Hooks.WorkspaceHistory" for further details
|
||||
--
|
||||
-- Let us go through a full example together. Given the following topic names
|
||||
--
|
||||
-- > -- The list of all topics/workspaces of your xmonad configuration.
|
||||
@ -272,6 +284,7 @@ data TopicConfig = TopicConfig { topicDirs :: M.Map Topic Dir
|
||||
-- usually 10 is a good default since we can bind all of
|
||||
-- them using numeric keypad.
|
||||
}
|
||||
{-# DEPRECATED maxTopicHistory "This field will be removed in the future; history is now handled by XMonad.Hooks.WorkspaceHistory" #-}
|
||||
|
||||
instance Default TopicConfig where
|
||||
def = TopicConfig { topicDirs = M.empty
|
||||
@ -284,10 +297,7 @@ instance Default TopicConfig where
|
||||
-- | Return the (possibly empty) list of last focused topics.
|
||||
getLastFocusedTopics :: X [Topic]
|
||||
getLastFocusedTopics = workspaceHistory
|
||||
|
||||
-- | Like 'getLastFocusedTopics', but group the topics by their screen-id's.
|
||||
getLastFocusedTopicsByScreen :: X [(ScreenId, [Topic])]
|
||||
getLastFocusedTopicsByScreen = workspaceHistoryByScreen
|
||||
{-# DEPRECATED getLastFocusedTopics "Use XMonad.Hooks.WorkspaceHistory.workspaceHistory (re-exported by this module) instead" #-}
|
||||
|
||||
-- | Given a 'TopicConfig', a topic, and a predicate to select topics that one
|
||||
-- wants to keep, this function will cons the topic in front of the list of
|
||||
@ -298,6 +308,7 @@ setLastFocusedTopic tc w predicate = do
|
||||
sid <- gets $ W.screen . W.current . windowset
|
||||
workspaceHistoryModify $
|
||||
take (maxTopicHistory tc) . nub . filter (predicate . snd) . ((sid, w) :)
|
||||
{-# DEPRECATED setLastFocusedTopic "Use XMonad.Hooks.WorkspaceHistory instead" #-}
|
||||
|
||||
-- | Reverse the list of "last focused topics"
|
||||
reverseLastFocusedTopics :: X ()
|
||||
@ -315,7 +326,7 @@ pprWindowSet tg pp = do
|
||||
setLastFocusedTopic tg
|
||||
(W.tag . W.workspace . W.current $ winset)
|
||||
(`notElem` empty_workspaces)
|
||||
lastWs <- getLastFocusedTopics
|
||||
lastWs <- workspaceHistory
|
||||
let depth topic = fromJust $ elemIndex topic (lastWs ++ [topic])
|
||||
add_depth proj topic = proj pp . (((topic++":")++) . show) . depth $ topic
|
||||
pp' = pp { ppHidden = add_depth ppHidden, ppVisible = add_depth ppVisible }
|
||||
@ -337,19 +348,13 @@ currentTopicAction tg = topicAction tg =<< gets (W.tag . W.workspace . W.current
|
||||
|
||||
-- | Switch to the given topic.
|
||||
switchTopic :: TopicConfig -> Topic -> X ()
|
||||
switchTopic = switchTopicWith (const True)
|
||||
|
||||
-- | Like 'switchTopic', but give a custom filtering function to
|
||||
-- 'setLastFocusedTopic'.
|
||||
switchTopicWith :: (Topic -> Bool) -> TopicConfig -> Topic -> X ()
|
||||
switchTopicWith predicate tg topic = do
|
||||
switchTopic tc topic = do
|
||||
-- Switch to topic and add it to the last seen topics
|
||||
windows $ W.greedyView topic
|
||||
setLastFocusedTopic tg topic predicate
|
||||
|
||||
-- If applicable, execute the topic action
|
||||
wins <- gets (W.integrate' . W.stack . W.workspace . W.current . windowset)
|
||||
when (null wins) $ topicAction tg topic
|
||||
when (null wins) $ topicAction tc topic
|
||||
|
||||
-- | Switch to the Nth last focused topic or fall back to the 'defaultTopic'.
|
||||
switchNthLastFocused :: TopicConfig -> Int -> X ()
|
||||
@ -358,7 +363,7 @@ switchNthLastFocused = switchNthLastFocusedExclude []
|
||||
-- | Like 'switchNthLastFocused', but also filter out certain topics.
|
||||
switchNthLastFocusedExclude :: [Topic] -> TopicConfig -> Int -> X ()
|
||||
switchNthLastFocusedExclude excludes tc depth = do
|
||||
lastWs <- filter (`notElem` excludes) <$> getLastFocusedTopics
|
||||
lastWs <- filter (`notElem` excludes) <$> workspaceHistory
|
||||
switchTopic tc $ (lastWs ++ repeat (defaultTopic tc)) !! depth
|
||||
|
||||
-- | Like 'switchNthLastFocused', but only consider topics that used to
|
||||
@ -376,13 +381,13 @@ switchNthLastFocusedByScreen tc depth = do
|
||||
. listToMaybe
|
||||
. map snd
|
||||
. filter ((== sid) . fst)
|
||||
<$> getLastFocusedTopicsByScreen
|
||||
<$> workspaceHistoryByScreen
|
||||
switchTopic tc $ (sws ++ repeat (defaultTopic tc)) !! depth
|
||||
|
||||
-- | Shift the focused window to the Nth last focused topic, or fall back to doing nothing.
|
||||
shiftNthLastFocused :: Int -> X ()
|
||||
shiftNthLastFocused n = do
|
||||
ws <- fmap (listToMaybe . drop n) getLastFocusedTopics
|
||||
ws <- fmap (listToMaybe . drop n) workspaceHistory
|
||||
whenJust ws $ windows . W.shift
|
||||
|
||||
-- | Return the directory associated with the current topic, or return the empty
|
||||
|
Loading…
x
Reference in New Issue
Block a user