X.A.GroupNavigation, X.H.WorkspaceHistory: Leak fix cleanups

Simplify stuff a bit. Prevent memory leaks additionally in:
`workspaceHistoryTransaction` and `workspaceHistoryModify`.

Related: https://github.com/xmonad/xmonad-contrib/pull/653
This commit is contained in:
Tomas Janousek
2022-01-15 19:12:32 +00:00
parent 981166a2ab
commit 201a14718e
2 changed files with 7 additions and 9 deletions

View File

@@ -169,9 +169,7 @@ instance ExtensionClass HistoryDB where
-- | Action that needs to be executed as a logHook to maintain the
-- focus history of all windows as the WindowSet changes.
historyHook :: X ()
historyHook = do
db' <- XS.get >>= updateHistory
db' `deepseq` XS.put db'
historyHook = (XS.put $!) . force =<< updateHistory =<< XS.get
-- Updates the history in response to a WindowSet change
updateHistory :: HistoryDB -> X HistoryDB

View File

@@ -84,10 +84,10 @@ workspaceHistoryHook = workspaceHistoryHookExclude []
-- | Like 'workspaceHistoryHook', but with the ability to exclude
-- certain workspaces.
workspaceHistoryHookExclude :: [WorkspaceId] -> X ()
workspaceHistoryHookExclude ws = do
s <- gets windowset
let update' = force . updateLastActiveOnEachScreenExclude ws s
XS.modify' update'
workspaceHistoryHookExclude ws = XS.modify' . update =<< gets windowset
where
update :: WindowSet -> WorkspaceHistory -> WorkspaceHistory
update s = force . updateLastActiveOnEachScreenExclude ws s
workspaceHistoryWithScreen :: X [(ScreenId, WorkspaceId)]
workspaceHistoryWithScreen = XS.gets history
@@ -110,7 +110,7 @@ workspaceHistoryTransaction action = do
startingHistory <- XS.gets history
action
new <- flip updateLastActiveOnEachScreen (WorkspaceHistory startingHistory) <$> gets windowset
XS.put new
XS.put $! force new
-- | Update the last visible workspace on each monitor if needed
-- already there, or move it to the front if it is.
@@ -134,4 +134,4 @@ updateLastActiveOnEachScreenExclude ws StackSet {current = cur, visible = vis} w
-- | Modify a the workspace history with a given pure function.
workspaceHistoryModify :: ([(ScreenId, WorkspaceId)] -> [(ScreenId, WorkspaceId)]) -> X ()
workspaceHistoryModify action = XS.modify $ WorkspaceHistory . action . history
workspaceHistoryModify action = XS.modify' $ force . WorkspaceHistory . action . history