diff options
| -rw-r--r-- | src/Rahm/Desktop/History.hs | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/src/Rahm/Desktop/History.hs b/src/Rahm/Desktop/History.hs index 8b8e879..6383ed6 100644 --- a/src/Rahm/Desktop/History.hs +++ b/src/Rahm/Desktop/History.hs @@ -24,6 +24,7 @@ import qualified Data.Sequence as Seq (length, (!?)) import Rahm.Desktop.Common (Location (Location, locationWindow), focusLocation, getCurrentScreen, getCurrentWorkspace, locationWorkspace) import Rahm.Desktop.Hooks.WindowChange import Rahm.Desktop.Logger +import qualified Rahm.Desktop.StackSet as W import Text.Printf (printf) import XMonad (ExtensionClass (extensionType, initialValue), ScreenId, StateExtension (..), Window, X, withWindowSet) import XMonad.StackSet @@ -58,7 +59,7 @@ zipperDbgPrint _ = "<empty>" pushZipper :: a -> BoundedSeqZipper a -> BoundedSeqZipper a pushZipper e (BoundedSeqZipper maxSize _ (tail :|> _)) | maxSize <= Seq.length tail = - BoundedSeqZipper maxSize mempty (e :<| tail) + BoundedSeqZipper maxSize mempty (e :<| tail) pushZipper e (BoundedSeqZipper maxSize _ tail) = BoundedSeqZipper maxSize mempty (e :<| tail) @@ -114,13 +115,26 @@ lastLocation = do XS.modify $ \(History byScreen) -> History (Map.adjust popSeqZipper screenId byScreen) - t <- withWindowSet $ \ws -> - return $ flip findTag ws =<< (locationWindow =<< ret) + maybeTag <- withWindowSet $ \ws -> + return $ do + tg <- flip findTag ws =<< (locationWindow =<< ret) + return (isVisible tg ws, tg) -- The last location should not return the last location. - if t == Just "*" || (locationWorkspace <$> ret) == Just "*" - then lastLocation - else return ret + case maybeTag of + Just (visible, t) -> + -- Avoid jumping to a visible workspace. It causes unintuitive behavior. + -- Likewise, avoid jumping to the hidden workspace (*). In these cases, + -- go to the "next" lastLocation. + if t == "*" || (locationWorkspace <$> ret) == Just "*" || visible + then lastLocation + else return ret + Nothing -> + return Nothing + where + isVisible t (visibleWorkspaces -> ws) = t `elem` ws + visibleWorkspaces = + map (W.tag . W.workspace) . W.visible nextLocation :: X (Maybe Location) nextLocation = do @@ -165,18 +179,19 @@ historyHook = StackChangeHook $ \lastWindowSet currentWindowSet -> do -- In case of 2, we want to add the old workspace to the history of the -- screen that changed. case () of - () | nws `visibleIn` lastWindowSet, - (Just oscr) <- screenOf nws lastWindowSet -> - -- The last workspace was on a different screen. Swap the current - -- screen's history with the history from the last screen the - -- workspace was on. - XS.modify $ \(History byScreen) -> - History - ( Map.alter - (const $ Map.lookup oscr hist) - sid - byScreen - ) + () + | nws `visibleIn` lastWindowSet, + (Just oscr) <- screenOf nws lastWindowSet -> + -- The last workspace was on a different screen. Swap the current + -- screen's history with the history from the last screen the + -- workspace was on. + XS.modify $ \(History byScreen) -> + History + ( Map.alter + (const $ Map.lookup oscr hist) + sid + byScreen + ) -- The new workspace was not originally visible, add to history () | not (nws `visibleIn` lastWindowSet) -> XS.modify $ \(History byScreen) -> |