diff options
| author | Josh Rahm <rahm@google.com> | 2024-10-14 14:36:41 -0600 |
|---|---|---|
| committer | Josh Rahm <rahm@google.com> | 2024-10-14 14:36:41 -0600 |
| commit | 0d4619c28d9940a0a8e7835e41671edc3e81f40e (patch) | |
| tree | d048d5e92f73e791d0896b2825c1ef4390d72e13 | |
| parent | 9b0750ba68aee61aacf7538b5b14d8f265e934e5 (diff) | |
| download | rde-0d4619c28d9940a0a8e7835e41671edc3e81f40e.tar.gz rde-0d4619c28d9940a0a8e7835e41671edc3e81f40e.tar.bz2 rde-0d4619c28d9940a0a8e7835e41671edc3e81f40e.zip | |
Change history behavior.
Now going to the last history location will avoid jumping to already
visible workspaces. This avoids the weirdness where it switches screens
and messes with the rest of the history.
| -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) -> |