aboutsummaryrefslogtreecommitdiff
path: root/src/Rahm/Desktop/History.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Rahm/Desktop/History.hs')
-rw-r--r--src/Rahm/Desktop/History.hs37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/Rahm/Desktop/History.hs b/src/Rahm/Desktop/History.hs
index 5e15fe6..9195a92 100644
--- a/src/Rahm/Desktop/History.hs
+++ b/src/Rahm/Desktop/History.hs
@@ -9,10 +9,9 @@ import Data.Default
import qualified XMonad.Util.ExtensibleState as XS
import Data.Foldable (toList)
-import Rahm.Desktop.Workspaces (gotoWorkspace)
import Rahm.Desktop.Hooks.WindowChange
+import Rahm.Desktop.Common
import Rahm.Desktop.Logger
-import Rahm.Desktop.Marking
import Data.Sequence (Seq(..))
import qualified Data.Sequence as Seq
@@ -60,6 +59,20 @@ instance ExtensionClass History where
initialValue = def
-- extensionType = PersistentExtension
+pastHistory :: Int -> X (Maybe Location)
+pastHistory i = do
+ History (BoundedSeqZipper _ _ t) <- XS.get
+ return $ t Seq.!? i
+
+getMostRecentLocationInHistory :: X (Maybe Location)
+getMostRecentLocationInHistory = do
+ History z <- XS.get
+ case z of
+ (BoundedSeqZipper _ (_ :|> h) _) -> return $ Just h
+ (BoundedSeqZipper _ _ (t :<| _)) -> return $ Just t
+ _ -> return Nothing
+
+
historyBack :: X ()
historyBack = do
History z <- XS.get
@@ -74,19 +87,19 @@ historyForward = do
mapM_ focusLocation (getZipper z')
XS.put (History z')
-lastWindow :: X (Maybe Location)
-lastWindow = getZipper . zipperBack . currentZipper <$> XS.get
+lastLocation :: X (Maybe Location)
+lastLocation = getZipper . zipperBack . currentZipper <$> XS.get
-jumpToLastLocation :: X ()
-jumpToLastLocation = mapM_ focusLocation =<< lastWindow
+nextLocation :: X (Maybe Location)
+nextLocation = getZipper . zipperForward . currentZipper <$> XS.get
+jumpToLastLocation :: X ()
+jumpToLastLocation = mapM_ focusLocation =<< lastLocation
-historyHook :: Location -> Location -> X ()
-historyHook (Location ws _) l@(Location ws' _) | ws /= ws' = do
+historyHook :: Maybe Location -> Location -> X ()
+historyHook Nothing loc =
+ XS.modify $ \(History z) -> History (pushZipper loc z)
+historyHook (Just (Location ws _)) l@(Location ws' _) | ws /= ws' = do
XS.modify $ \(History z) -> History (pushZipper l z)
historyHook _ _ = return ()
-
-focusLocation :: Location -> X ()
-focusLocation (Location ws Nothing) = gotoWorkspace ws
-focusLocation (Location _ (Just win)) = windows $ W.focusWindow win