mirror of
https://github.com/xmonad/xmonad.git
synced 2025-05-19 08:30:21 -07:00
Merge pull request #91 from pjones/pjones/remove-state-file
Remove the xmonad state file after reading it
This commit is contained in:
commit
bc320b69da
14
CHANGES.md
14
CHANGES.md
@ -1,5 +1,19 @@
|
||||
# Change Log / Release Notes
|
||||
|
||||
## 0.14 (Not Yet Released)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* The state file that xmonad uses while restarting itself is now
|
||||
removed after it is processed. This fixes a bug that manifested
|
||||
in several different ways:
|
||||
|
||||
- Names of old workspaces would be resurrected after a restart
|
||||
- Screen sizes would be wrong after changing monitor configuration (#90)
|
||||
- `spawnOnce` stopped working (xmonad/xmonad-contrib#155)
|
||||
- Focus did not follow when moving between workspaces (#87)
|
||||
- etc.
|
||||
|
||||
## 0.13 (February 10, 2017)
|
||||
|
||||
### Breaking Changes
|
||||
|
@ -465,14 +465,21 @@ writeStateToFile = do
|
||||
catchIO (writeFile path $ show stateData)
|
||||
|
||||
-- | Read the state of a previous xmonad instance from a file and
|
||||
-- return that state.
|
||||
-- return that state. The state file is removed after reading it.
|
||||
readStateFile :: (LayoutClass l Window, Read (l Window)) => XConfig l -> X (Maybe XState)
|
||||
readStateFile xmc = do
|
||||
path <- stateFileName
|
||||
raw <- userCode $ io (readFile path)
|
||||
|
||||
-- I'm trying really hard here to make sure we read the entire
|
||||
-- contents of the file before it is removed from the file system.
|
||||
sf' <- userCode . io $ do
|
||||
raw <- withFile path ReadMode readStrict
|
||||
return $! maybeRead reads raw
|
||||
|
||||
io (removeFile path)
|
||||
|
||||
return $ do
|
||||
sf <- maybeRead reads =<< raw
|
||||
sf <- join sf'
|
||||
|
||||
let winset = W.ensureTags layout (workspaces xmc) $ W.mapLayout (fromMaybe layout . maybeRead lreads) (sfWins sf)
|
||||
extState = M.fromList . map (second Left) $ sfExt sf
|
||||
@ -491,6 +498,9 @@ readStateFile xmc = do
|
||||
[(x, "")] -> Just x
|
||||
_ -> Nothing
|
||||
|
||||
readStrict :: Handle -> IO String
|
||||
readStrict h = hGetContents h >>= \s -> length s `seq` return s
|
||||
|
||||
-- | Migrate state from a previously running xmonad instance that used
|
||||
-- the older @--resume@ technique.
|
||||
{-# DEPRECATED migrateState "will be removed some point in the future." #-}
|
||||
|
Loading…
x
Reference in New Issue
Block a user