{-# LANGUAGE NamedFieldPuns #-}
module XMonad.Actions.TopicSpace
(
Topic
, Dir
, TopicConfig(..)
, TopicItem(..)
, topicNames
, tiActions
, tiDirs
, noAction
, inHome
, switchTopic
, switchNthLastFocused
, switchNthLastFocusedByScreen
, switchNthLastFocusedExclude
, shiftNthLastFocused
, topicActionWithPrompt
, topicAction
, currentTopicAction
, getLastFocusedTopics
, workspaceHistory
, workspaceHistoryByScreen
, setLastFocusedTopic
, reverseLastFocusedTopics
, workspaceHistoryHook
, workspaceHistoryHookExclude
, pprWindowSet
, currentTopicDir
, checkTopicConfig
, (>*>)
)
where
import XMonad
import XMonad.Prelude
import qualified Data.Map.Strict as M
import qualified XMonad.Hooks.StatusBar.PP as SBPP
import qualified XMonad.StackSet as W
import Data.Map (Map)
import XMonad.Prompt (XPConfig)
import XMonad.Prompt.Workspace (workspacePrompt)
import XMonad.Hooks.StatusBar.PP (PP(ppHidden, ppVisible))
import XMonad.Hooks.UrgencyHook (readUrgents)
import XMonad.Hooks.WorkspaceHistory
( workspaceHistory
, workspaceHistoryByScreen
, workspaceHistoryHook
, workspaceHistoryHookExclude
, workspaceHistoryModify
)
(>*>) :: Monad m => m a -> Int -> m ()
>*> :: forall (m :: * -> *) a. Monad m => m a -> Int -> m ()
(>*>) = (Int -> m a -> m ()) -> m a -> Int -> m ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Int -> m a -> m ()
forall (m :: * -> *) a. Applicative m => Int -> m a -> m ()
replicateM_
infix >*>
type Topic = WorkspaceId
type Dir = FilePath
data TopicConfig = TopicConfig { TopicConfig -> Map Topic Topic
topicDirs :: Map Topic Dir
, TopicConfig -> Map Topic (X ())
topicActions :: Map Topic (X ())
, TopicConfig -> Topic -> X ()
defaultTopicAction :: Topic -> X ()
, TopicConfig -> Topic
defaultTopic :: Topic
, TopicConfig -> Int
maxTopicHistory :: Int
}
{-# DEPRECATED maxTopicHistory "This field will be removed in the future; history is now handled by XMonad.Hooks.WorkspaceHistory" #-}
instance Default TopicConfig where
def :: TopicConfig
def = TopicConfig { topicDirs :: Map Topic Topic
topicDirs = Map Topic Topic
forall k a. Map k a
M.empty
, topicActions :: Map Topic (X ())
topicActions = Map Topic (X ())
forall k a. Map k a
M.empty
, defaultTopicAction :: Topic -> X ()
defaultTopicAction = X () -> Topic -> X ()
forall a b. a -> b -> a
const (X XConf
forall r (m :: * -> *). MonadReader r m => m r
ask X XConf -> (XConf -> X ()) -> X ()
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Topic -> X ()
forall (m :: * -> *). MonadIO m => Topic -> m ()
spawn (Topic -> X ()) -> (XConf -> Topic) -> XConf -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConfig Layout -> Topic
forall (l :: * -> *). XConfig l -> Topic
terminal (XConfig Layout -> Topic)
-> (XConf -> XConfig Layout) -> XConf -> Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XConf -> XConfig Layout
config)
, defaultTopic :: Topic
defaultTopic = Topic
"1"
, maxTopicHistory :: Int
maxTopicHistory = Int
10
}
getLastFocusedTopics :: X [Topic]
getLastFocusedTopics :: X [Topic]
getLastFocusedTopics = X [Topic]
workspaceHistory
{-# DEPRECATED getLastFocusedTopics "Use XMonad.Hooks.WorkspaceHistory.workspaceHistory (re-exported by this module) instead" #-}
setLastFocusedTopic :: TopicConfig -> Topic -> (Topic -> Bool) -> X ()
setLastFocusedTopic :: TopicConfig -> Topic -> (Topic -> Bool) -> X ()
setLastFocusedTopic TopicConfig
tc Topic
w Topic -> Bool
predicate = do
ScreenId
sid <- (XState -> ScreenId) -> X ScreenId
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> ScreenId) -> X ScreenId)
-> (XState -> ScreenId) -> X ScreenId
forall a b. (a -> b) -> a -> b
$ Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
W.screen (Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> ScreenId)
-> (XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> (XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
windowset
([(ScreenId, Topic)] -> [(ScreenId, Topic)]) -> X ()
workspaceHistoryModify (([(ScreenId, Topic)] -> [(ScreenId, Topic)]) -> X ())
-> ([(ScreenId, Topic)] -> [(ScreenId, Topic)]) -> X ()
forall a b. (a -> b) -> a -> b
$
Int -> [(ScreenId, Topic)] -> [(ScreenId, Topic)]
forall a. Int -> [a] -> [a]
take (TopicConfig -> Int
maxTopicHistory TopicConfig
tc) ([(ScreenId, Topic)] -> [(ScreenId, Topic)])
-> ([(ScreenId, Topic)] -> [(ScreenId, Topic)])
-> [(ScreenId, Topic)]
-> [(ScreenId, Topic)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(ScreenId, Topic)] -> [(ScreenId, Topic)]
forall a. Eq a => [a] -> [a]
nub ([(ScreenId, Topic)] -> [(ScreenId, Topic)])
-> ([(ScreenId, Topic)] -> [(ScreenId, Topic)])
-> [(ScreenId, Topic)]
-> [(ScreenId, Topic)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ScreenId, Topic) -> Bool)
-> [(ScreenId, Topic)] -> [(ScreenId, Topic)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Topic -> Bool
predicate (Topic -> Bool)
-> ((ScreenId, Topic) -> Topic) -> (ScreenId, Topic) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScreenId, Topic) -> Topic
forall a b. (a, b) -> b
snd) ([(ScreenId, Topic)] -> [(ScreenId, Topic)])
-> ([(ScreenId, Topic)] -> [(ScreenId, Topic)])
-> [(ScreenId, Topic)]
-> [(ScreenId, Topic)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ScreenId
sid, Topic
w) (ScreenId, Topic) -> [(ScreenId, Topic)] -> [(ScreenId, Topic)]
forall a. a -> [a] -> [a]
:)
{-# DEPRECATED setLastFocusedTopic "Use XMonad.Hooks.WorkspaceHistory instead" #-}
reverseLastFocusedTopics :: X ()
reverseLastFocusedTopics :: X ()
reverseLastFocusedTopics = ([(ScreenId, Topic)] -> [(ScreenId, Topic)]) -> X ()
workspaceHistoryModify [(ScreenId, Topic)] -> [(ScreenId, Topic)]
forall a. [a] -> [a]
reverse
pprWindowSet :: TopicConfig -> PP -> X String
pprWindowSet :: TopicConfig -> PP -> X Topic
pprWindowSet TopicConfig
tg PP
pp = do
StackSet Topic (Layout Window) Window ScreenId ScreenDetail
winset <- (XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> X (StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
windowset
[Window]
urgents <- X [Window]
readUrgents
let empty_workspaces :: [Topic]
empty_workspaces = (Workspace Topic (Layout Window) Window -> Topic)
-> [Workspace Topic (Layout Window) Window] -> [Topic]
forall a b. (a -> b) -> [a] -> [b]
map Workspace Topic (Layout Window) Window -> Topic
forall i l a. Workspace i l a -> i
W.tag ([Workspace Topic (Layout Window) Window] -> [Topic])
-> [Workspace Topic (Layout Window) Window] -> [Topic]
forall a b. (a -> b) -> a -> b
$ (Workspace Topic (Layout Window) Window -> Bool)
-> [Workspace Topic (Layout Window) Window]
-> [Workspace Topic (Layout Window) Window]
forall a. (a -> Bool) -> [a] -> [a]
filter (Maybe (Stack Window) -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe (Stack Window) -> Bool)
-> (Workspace Topic (Layout Window) Window -> Maybe (Stack Window))
-> Workspace Topic (Layout Window) Window
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace Topic (Layout Window) Window -> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack) ([Workspace Topic (Layout Window) Window]
-> [Workspace Topic (Layout Window) Window])
-> [Workspace Topic (Layout Window) Window]
-> [Workspace Topic (Layout Window) Window]
forall a b. (a -> b) -> a -> b
$ StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> [Workspace Topic (Layout Window) Window]
forall i l a s sd. StackSet i l a s sd -> [Workspace i l a]
W.workspaces StackSet Topic (Layout Window) Window ScreenId ScreenDetail
winset
maxDepth :: Int
maxDepth = TopicConfig -> Int
maxTopicHistory TopicConfig
tg
TopicConfig -> Topic -> (Topic -> Bool) -> X ()
setLastFocusedTopic TopicConfig
tg
(Workspace Topic (Layout Window) Window -> Topic
forall i l a. Workspace i l a -> i
W.tag (Workspace Topic (Layout Window) Window -> Topic)
-> (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window)
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window)
-> (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Topic)
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Topic
forall a b. (a -> b) -> a -> b
$ StackSet Topic (Layout Window) Window ScreenId ScreenDetail
winset)
(Topic -> [Topic] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Topic]
empty_workspaces)
[Topic]
lastWs <- X [Topic]
workspaceHistory
let depth :: Topic -> Int
depth Topic
topic = Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Int -> Int) -> Maybe Int -> Int
forall a b. (a -> b) -> a -> b
$ Topic -> [Topic] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex Topic
topic ([Topic]
lastWs [Topic] -> [Topic] -> [Topic]
forall a. [a] -> [a] -> [a]
++ [Topic
topic])
add_depth :: (PP -> Topic -> c) -> Topic -> c
add_depth PP -> Topic -> c
proj Topic
topic = PP -> Topic -> c
proj PP
pp (Topic -> c) -> (Topic -> Topic) -> Topic -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (((Topic
topicTopic -> Topic -> Topic
forall a. [a] -> [a] -> [a]
++Topic
":")Topic -> Topic -> Topic
forall a. [a] -> [a] -> [a]
++) (Topic -> Topic) -> (Int -> Topic) -> Int -> Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Topic
forall a. Show a => a -> Topic
show) (Int -> Topic) -> (Topic -> Int) -> Topic -> Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Topic -> Int
depth (Topic -> c) -> Topic -> c
forall a b. (a -> b) -> a -> b
$ Topic
topic
pp' :: PP
pp' = PP
pp { ppHidden = add_depth ppHidden, ppVisible = add_depth ppVisible }
sortWindows :: [Workspace Topic l a] -> [Workspace Topic l a]
sortWindows = Int -> [Workspace Topic l a] -> [Workspace Topic l a]
forall a. Int -> [a] -> [a]
take Int
maxDepth ([Workspace Topic l a] -> [Workspace Topic l a])
-> ([Workspace Topic l a] -> [Workspace Topic l a])
-> [Workspace Topic l a]
-> [Workspace Topic l a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Workspace Topic l a -> Int)
-> [Workspace Topic l a] -> [Workspace Topic l a]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (Topic -> Int
depth (Topic -> Int)
-> (Workspace Topic l a -> Topic) -> Workspace Topic l a -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace Topic l a -> Topic
forall i l a. Workspace i l a -> i
W.tag)
Topic -> X Topic
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Topic -> X Topic) -> Topic -> X Topic
forall a b. (a -> b) -> a -> b
$ ([Workspace Topic (Layout Window) Window]
-> [Workspace Topic (Layout Window) Window])
-> [Window]
-> PP
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Topic
SBPP.pprWindowSet [Workspace Topic (Layout Window) Window]
-> [Workspace Topic (Layout Window) Window]
forall {l} {a}. [Workspace Topic l a] -> [Workspace Topic l a]
sortWindows [Window]
urgents PP
pp' StackSet Topic (Layout Window) Window ScreenId ScreenDetail
winset
topicActionWithPrompt :: XPConfig -> TopicConfig -> X ()
topicActionWithPrompt :: XPConfig -> TopicConfig -> X ()
topicActionWithPrompt XPConfig
xp TopicConfig
tg = XPConfig -> (Topic -> X ()) -> X ()
workspacePrompt XPConfig
xp ((X () -> X () -> X ())
-> (Topic -> X ()) -> (Topic -> X ()) -> Topic -> X ()
forall a b c.
(a -> b -> c) -> (Topic -> a) -> (Topic -> b) -> Topic -> c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 X () -> X () -> X ()
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) (TopicConfig -> Topic -> X ()
switchTopic TopicConfig
tg) (TopicConfig -> Topic -> X ()
topicAction TopicConfig
tg))
topicAction :: TopicConfig -> Topic -> X ()
topicAction :: TopicConfig -> Topic -> X ()
topicAction TopicConfig
tg Topic
topic = X () -> Maybe (X ()) -> X ()
forall a. a -> Maybe a -> a
fromMaybe (TopicConfig -> Topic -> X ()
defaultTopicAction TopicConfig
tg Topic
topic) (Maybe (X ()) -> X ()) -> Maybe (X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ Topic -> Map Topic (X ()) -> Maybe (X ())
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Topic
topic (Map Topic (X ()) -> Maybe (X ()))
-> Map Topic (X ()) -> Maybe (X ())
forall a b. (a -> b) -> a -> b
$ TopicConfig -> Map Topic (X ())
topicActions TopicConfig
tg
currentTopicAction :: TopicConfig -> X ()
currentTopicAction :: TopicConfig -> X ()
currentTopicAction TopicConfig
tg = TopicConfig -> Topic -> X ()
topicAction TopicConfig
tg (Topic -> X ()) -> X Topic -> X ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (XState -> Topic) -> X Topic
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (Workspace Topic (Layout Window) Window -> Topic
forall i l a. Workspace i l a -> i
W.tag (Workspace Topic (Layout Window) Window -> Topic)
-> (XState -> Workspace Topic (Layout Window) Window)
-> XState
-> Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window)
-> (XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Workspace Topic (Layout Window) Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> (XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
windowset)
switchTopic :: TopicConfig -> Topic -> X ()
switchTopic :: TopicConfig -> Topic -> X ()
switchTopic TopicConfig
tc Topic
topic = do
(StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> X ()
windows ((StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> X ())
-> (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> X ()
forall a b. (a -> b) -> a -> b
$ Topic
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.greedyView Topic
topic
[Window]
wins <- (XState -> [Window]) -> X [Window]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (Maybe (Stack Window) -> [Window]
forall a. Maybe (Stack a) -> [a]
W.integrate' (Maybe (Stack Window) -> [Window])
-> (XState -> Maybe (Stack Window)) -> XState -> [Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace Topic (Layout Window) Window -> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack (Workspace Topic (Layout Window) Window -> Maybe (Stack Window))
-> (XState -> Workspace Topic (Layout Window) Window)
-> XState
-> Maybe (Stack Window)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window)
-> (XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Workspace Topic (Layout Window) Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> (XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
windowset)
Bool -> X () -> X ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Window] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Window]
wins) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ TopicConfig -> Topic -> X ()
topicAction TopicConfig
tc Topic
topic
switchNthLastFocused :: TopicConfig -> Int -> X ()
switchNthLastFocused :: TopicConfig -> Int -> X ()
switchNthLastFocused = [Topic] -> TopicConfig -> Int -> X ()
switchNthLastFocusedExclude []
switchNthLastFocusedExclude :: [Topic] -> TopicConfig -> Int -> X ()
switchNthLastFocusedExclude :: [Topic] -> TopicConfig -> Int -> X ()
switchNthLastFocusedExclude [Topic]
excludes TopicConfig
tc Int
depth = do
[Topic]
lastWs <- (Topic -> Bool) -> [Topic] -> [Topic]
forall a. (a -> Bool) -> [a] -> [a]
filter (Topic -> [Topic] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Topic]
excludes) ([Topic] -> [Topic]) -> X [Topic] -> X [Topic]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> X [Topic]
workspaceHistory
TopicConfig -> Topic -> X ()
switchTopic TopicConfig
tc (Topic -> X ()) -> Topic -> X ()
forall a b. (a -> b) -> a -> b
$ ([Topic]
lastWs [Topic] -> [Topic] -> [Topic]
forall a. [a] -> [a] -> [a]
++ Topic -> [Topic]
forall a. a -> [a]
repeat (TopicConfig -> Topic
defaultTopic TopicConfig
tc)) [Topic] -> Int -> Topic
forall a. HasCallStack => [a] -> Int -> a
!! Int
depth
switchNthLastFocusedByScreen :: TopicConfig -> Int -> X ()
switchNthLastFocusedByScreen :: TopicConfig -> Int -> X ()
switchNthLastFocusedByScreen TopicConfig
tc Int
depth = do
ScreenId
sid <- (XState -> ScreenId) -> X ScreenId
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> ScreenId) -> X ScreenId)
-> (XState -> ScreenId) -> X ScreenId
forall a b. (a -> b) -> a -> b
$ Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
W.screen (Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> ScreenId)
-> (XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> ScreenId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> (XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
windowset
[Topic]
sws <- [Topic] -> Maybe [Topic] -> [Topic]
forall a. a -> Maybe a -> a
fromMaybe []
(Maybe [Topic] -> [Topic])
-> ([(ScreenId, [Topic])] -> Maybe [Topic])
-> [(ScreenId, [Topic])]
-> [Topic]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Topic]] -> Maybe [Topic]
forall a. [a] -> Maybe a
listToMaybe
([[Topic]] -> Maybe [Topic])
-> ([(ScreenId, [Topic])] -> [[Topic]])
-> [(ScreenId, [Topic])]
-> Maybe [Topic]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ScreenId, [Topic]) -> [Topic])
-> [(ScreenId, [Topic])] -> [[Topic]]
forall a b. (a -> b) -> [a] -> [b]
map (ScreenId, [Topic]) -> [Topic]
forall a b. (a, b) -> b
snd
([(ScreenId, [Topic])] -> [[Topic]])
-> ([(ScreenId, [Topic])] -> [(ScreenId, [Topic])])
-> [(ScreenId, [Topic])]
-> [[Topic]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ScreenId, [Topic]) -> Bool)
-> [(ScreenId, [Topic])] -> [(ScreenId, [Topic])]
forall a. (a -> Bool) -> [a] -> [a]
filter ((ScreenId -> ScreenId -> Bool
forall a. Eq a => a -> a -> Bool
== ScreenId
sid) (ScreenId -> Bool)
-> ((ScreenId, [Topic]) -> ScreenId) -> (ScreenId, [Topic]) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScreenId, [Topic]) -> ScreenId
forall a b. (a, b) -> a
fst)
([(ScreenId, [Topic])] -> [Topic])
-> X [(ScreenId, [Topic])] -> X [Topic]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> X [(ScreenId, [Topic])]
workspaceHistoryByScreen
TopicConfig -> Topic -> X ()
switchTopic TopicConfig
tc (Topic -> X ()) -> Topic -> X ()
forall a b. (a -> b) -> a -> b
$ ([Topic]
sws [Topic] -> [Topic] -> [Topic]
forall a. [a] -> [a] -> [a]
++ Topic -> [Topic]
forall a. a -> [a]
repeat (TopicConfig -> Topic
defaultTopic TopicConfig
tc)) [Topic] -> Int -> Topic
forall a. HasCallStack => [a] -> Int -> a
!! Int
depth
shiftNthLastFocused :: Int -> X ()
shiftNthLastFocused :: Int -> X ()
shiftNthLastFocused Int
n = do
Maybe Topic
ws <- ([Topic] -> Maybe Topic) -> X [Topic] -> X (Maybe Topic)
forall a b. (a -> b) -> X a -> X b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Topic] -> Maybe Topic
forall a. [a] -> Maybe a
listToMaybe ([Topic] -> Maybe Topic)
-> ([Topic] -> [Topic]) -> [Topic] -> Maybe Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Topic] -> [Topic]
forall a. Int -> [a] -> [a]
drop Int
n) X [Topic]
workspaceHistory
Maybe Topic -> (Topic -> X ()) -> X ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe Topic
ws ((Topic -> X ()) -> X ()) -> (Topic -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> X ()
windows ((StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> X ())
-> (Topic
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> Topic
-> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Topic
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
forall a s i l sd.
(Ord a, Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.shift
currentTopicDir :: TopicConfig -> X FilePath
currentTopicDir :: TopicConfig -> X Topic
currentTopicDir TopicConfig
tg = do
Topic
topic <- (XState -> Topic) -> X Topic
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (Workspace Topic (Layout Window) Window -> Topic
forall i l a. Workspace i l a -> i
W.tag (Workspace Topic (Layout Window) Window -> Topic)
-> (XState -> Workspace Topic (Layout Window) Window)
-> XState
-> Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen Topic (Layout Window) Window ScreenId ScreenDetail
-> Workspace Topic (Layout Window) Window)
-> (XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Workspace Topic (Layout Window) Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (StackSet Topic (Layout Window) Window ScreenId ScreenDetail
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail)
-> (XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> Screen Topic (Layout Window) Window ScreenId ScreenDetail
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet Topic (Layout Window) Window ScreenId ScreenDetail
windowset)
Topic -> X Topic
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Topic -> X Topic)
-> (Map Topic Topic -> Topic) -> Map Topic Topic -> X Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Topic -> Maybe Topic -> Topic
forall a. a -> Maybe a -> a
fromMaybe Topic
"" (Maybe Topic -> Topic)
-> (Map Topic Topic -> Maybe Topic) -> Map Topic Topic -> Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Topic -> Map Topic Topic -> Maybe Topic
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Topic
topic (Map Topic Topic -> X Topic) -> Map Topic Topic -> X Topic
forall a b. (a -> b) -> a -> b
$ TopicConfig -> Map Topic Topic
topicDirs TopicConfig
tg
checkTopicConfig :: [Topic] -> TopicConfig -> IO ()
checkTopicConfig :: [Topic] -> TopicConfig -> IO ()
checkTopicConfig [Topic]
tags TopicConfig
tg = do
let
seenTopics :: [Topic]
seenTopics = [Topic] -> [Topic]
forall a. Eq a => [a] -> [a]
nub ([Topic] -> [Topic]) -> [Topic] -> [Topic]
forall a b. (a -> b) -> a -> b
$ [Topic] -> [Topic]
forall a. Ord a => [a] -> [a]
sort ([Topic] -> [Topic]) -> [Topic] -> [Topic]
forall a b. (a -> b) -> a -> b
$ Map Topic Topic -> [Topic]
forall k a. Map k a -> [k]
M.keys (TopicConfig -> Map Topic Topic
topicDirs TopicConfig
tg) [Topic] -> [Topic] -> [Topic]
forall a. [a] -> [a] -> [a]
++ Map Topic (X ()) -> [Topic]
forall k a. Map k a -> [k]
M.keys (TopicConfig -> Map Topic (X ())
topicActions TopicConfig
tg)
dups :: [Topic]
dups = [Topic]
tags [Topic] -> [Topic] -> [Topic]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Topic] -> [Topic]
forall a. Eq a => [a] -> [a]
nub [Topic]
tags
diffTopic :: [Topic]
diffTopic = [Topic]
seenTopics [Topic] -> [Topic] -> [Topic]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Topic] -> [Topic]
forall a. Ord a => [a] -> [a]
sort [Topic]
tags
check :: t a -> Topic -> f ()
check t a
lst Topic
msg = Bool -> f () -> f ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (t a -> Bool
forall a. t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null t a
lst) (f () -> f ()) -> f () -> f ()
forall a b. (a -> b) -> a -> b
$ Topic -> f ()
forall (m :: * -> *). MonadIO m => Topic -> m ()
xmessage (Topic -> f ()) -> Topic -> f ()
forall a b. (a -> b) -> a -> b
$ Topic
msg Topic -> Topic -> Topic
forall a. [a] -> [a] -> [a]
++ Topic
" (tags): " Topic -> Topic -> Topic
forall a. [a] -> [a] -> [a]
++ t a -> Topic
forall a. Show a => a -> Topic
show t a
lst
[Topic] -> Topic -> IO ()
forall {f :: * -> *} {t :: * -> *} {a}.
(Foldable t, MonadIO f, Show (t a)) =>
t a -> Topic -> f ()
check [Topic]
diffTopic Topic
"Seen but missing topics/workspaces"
[Topic] -> Topic -> IO ()
forall {f :: * -> *} {t :: * -> *} {a}.
(Foldable t, MonadIO f, Show (t a)) =>
t a -> Topic -> f ()
check [Topic]
dups Topic
"Duplicate topics/workspaces"
data TopicItem = TI
{ TopicItem -> Topic
tiName :: !Topic
, TopicItem -> Topic
tiDir :: !Dir
, TopicItem -> X ()
tiAction :: !(X ())
}
topicNames :: [TopicItem] -> [Topic]
topicNames :: [TopicItem] -> [Topic]
topicNames = (TopicItem -> Topic) -> [TopicItem] -> [Topic]
forall a b. (a -> b) -> [a] -> [b]
map TopicItem -> Topic
tiName
tiDirs :: [TopicItem] -> Map Topic Dir
tiDirs :: [TopicItem] -> Map Topic Topic
tiDirs = [(Topic, Topic)] -> Map Topic Topic
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(Topic, Topic)] -> Map Topic Topic)
-> ([TopicItem] -> [(Topic, Topic)])
-> [TopicItem]
-> Map Topic Topic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TopicItem -> (Topic, Topic)) -> [TopicItem] -> [(Topic, Topic)]
forall a b. (a -> b) -> [a] -> [b]
map (\TI{ Topic
tiName :: TopicItem -> Topic
tiName :: Topic
tiName, Topic
tiDir :: TopicItem -> Topic
tiDir :: Topic
tiDir } -> (Topic
tiName, Topic
tiDir))
tiActions :: [TopicItem] -> Map Topic (X ())
tiActions :: [TopicItem] -> Map Topic (X ())
tiActions = [(Topic, X ())] -> Map Topic (X ())
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(Topic, X ())] -> Map Topic (X ()))
-> ([TopicItem] -> [(Topic, X ())])
-> [TopicItem]
-> Map Topic (X ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TopicItem -> (Topic, X ())) -> [TopicItem] -> [(Topic, X ())]
forall a b. (a -> b) -> [a] -> [b]
map (\TI{ Topic
tiName :: TopicItem -> Topic
tiName :: Topic
tiName, X ()
tiAction :: TopicItem -> X ()
tiAction :: X ()
tiAction } -> (Topic
tiName, X ()
tiAction))
noAction :: Topic -> Dir -> TopicItem
noAction :: Topic -> Topic -> TopicItem
noAction Topic
n Topic
d = Topic -> Topic -> X () -> TopicItem
TI Topic
n Topic
d (() -> X ()
forall a. a -> X a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
inHome :: Topic -> X () -> TopicItem
inHome :: Topic -> X () -> TopicItem
inHome Topic
n = Topic -> Topic -> X () -> TopicItem
TI Topic
n Topic
"."