aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2022-04-04 17:49:01 -0600
committerJosh Rahm <rahm@google.com>2022-04-04 17:49:01 -0600
commit20aaf1e159b6128ad136c0bcf489c0ac0ebc76f5 (patch)
tree284d3f07c5a5eeac086a950dc8b34a76825306a0 /src
parent522a993840f5fd8fd414c54a00b871ec2689216f (diff)
downloadrde-20aaf1e159b6128ad136c0bcf489c0ac0ebc76f5.tar.gz
rde-20aaf1e159b6128ad136c0bcf489c0ac0ebc76f5.tar.bz2
rde-20aaf1e159b6128ad136c0bcf489c0ac0ebc76f5.zip
Make both Tags and Windows as valid history targets
Diffstat (limited to 'src')
-rw-r--r--src/Internal/Marking.hs65
1 files changed, 45 insertions, 20 deletions
diff --git a/src/Internal/Marking.hs b/src/Internal/Marking.hs
index 9bf58cd..3ffb411 100644
--- a/src/Internal/Marking.hs
+++ b/src/Internal/Marking.hs
@@ -66,11 +66,25 @@ historyLast :: History a -> Maybe a
historyLast (History _ (t :<| _)) = Just t
historyLast _ = Nothing
+data Spot =
+ WindowSpot Window | -- Focus is on a window.
+ TagSpot String -- Focus is on an (empty) tag
+ deriving (Read, Show, Eq, Ord)
+
+greedyFocus :: Spot -> X ()
+greedyFocus (WindowSpot win) = do
+ ws <- withWindowSet $ \ss ->
+ return $ getLocationWorkspace =<< findWindow ss win
+
+ mapM_ (windows . greedyView . tag) ws
+ focus win
+greedyFocus (TagSpot tag) =
+ windows $ greedyView tag
data MarkState =
MarkState {
markStateMap :: Map Mark Window
- , windowHistory :: History Window
+ , windowHistory :: History Spot
} deriving (Read, Show)
@@ -78,21 +92,24 @@ instance ExtensionClass MarkState where
initialValue = MarkState Map.empty def
extensionType = PersistentExtension
-changeHistory :: (History Window -> History Window) -> (MarkState -> MarkState)
+changeHistory :: (History Spot -> History Spot) -> (MarkState -> MarkState)
changeHistory fn ms = ms { windowHistory = fn (windowHistory ms)}
+withMaybeFocused :: (Maybe Window -> X ()) -> X ()
+withMaybeFocused f = withWindowSet $ f . peek
+
normalizeWindows :: X ()
normalizeWindows = do
MarkState { windowHistory = h } <- XS.get
mapM_ greedyFocus (historyCurrent h)
-greedyFocus :: Window -> X ()
-greedyFocus win = do
- ws <- withWindowSet $ \ss ->
- return $ getLocationWorkspace =<< findWindow ss win
-
- mapM_ (windows . greedyView . tag) ws
- focus win
+-- greedyFocus :: Window -> X ()
+-- greedyFocus win = do
+-- ws <- withWindowSet $ \ss ->
+-- return $ getLocationWorkspace =<< findWindow ss win
+--
+-- mapM_ (windows . greedyView . tag) ws
+-- focus win
markCurrentWindow :: Mark -> X ()
markCurrentWindow mark = do
@@ -104,16 +121,25 @@ markCurrentWindow mark = do
pushHistory :: X () -> X ()
pushHistory fn = do
- withFocused $ \windowBefore -> do
- withHistory $ \hist ->
- XS.modify $ changeHistory (historyPush windowBefore)
+ withMaybeFocused $ \maybeWindowBefore -> do
+ case maybeWindowBefore of
+ (Just windowBefore) ->
+ XS.modify $ changeHistory (historyPush (WindowSpot windowBefore))
+ Nothing ->
+ withWindowSet $ \ws ->
+ XS.modify $ changeHistory (historyPush (TagSpot (currentTag ws)))
fn
- withFocused $ \windowAfter ->
- XS.modify $ changeHistory (historyPush windowAfter)
+ withMaybeFocused $ \maybeWindowAfter ->
+ case maybeWindowAfter of
+ Just windowAfter ->
+ XS.modify $ changeHistory (historyPush $ WindowSpot windowAfter)
+ Nothing ->
+ withWindowSet $ \ws ->
+ XS.modify $ changeHistory (historyPush $ TagSpot $ currentTag ws)
-withHistory :: (History Window -> X ()) -> X ()
+withHistory :: (History Spot -> X ()) -> X ()
withHistory fn = do
MarkState { windowHistory = w } <- XS.get
fn w
@@ -128,9 +154,8 @@ jumpToMark mark = do
MarkState {markStateMap = m} <- XS.get
case Map.lookup mark m of
Nothing -> return ()
- Just w -> do
- XS.modify $ changeHistory (historyPush w)
- greedyFocus w
+ Just w -> pushHistory $
+ greedyFocus (WindowSpot w)
setFocusedWindow :: a -> StackSet i l a s sd -> StackSet i l a s sd
setFocusedWindow
@@ -155,9 +180,9 @@ swapWithLastMark :: X ()
swapWithLastMark = pushHistory $ withHistory $ \hist -> do
case historyLast hist of
- Nothing -> return ()
- Just win ->
+ Just (WindowSpot win) ->
windows $ swapWithFocused win
+ Nothing -> return ()
swapWithMark :: Mark -> X ()
swapWithMark mark = pushHistory $ do