diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2021-11-02 23:20:35 -0600 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2022-10-09 12:19:45 -0600 |
| commit | 6f831fdf58715087a609d4743cbcdd1ed5bb52cc (patch) | |
| tree | 0ff95668117a7b78cbd91b29a94c9904995b90ac /src/Internal/Marking.hs | |
| parent | 80522aff9bcc601b8250024fb517d153dc189024 (diff) | |
| download | rde-6f831fdf58715087a609d4743cbcdd1ed5bb52cc.tar.gz rde-6f831fdf58715087a609d4743cbcdd1ed5bb52cc.tar.bz2 rde-6f831fdf58715087a609d4743cbcdd1ed5bb52cc.zip | |
Rework keys
Finally removed the buggy hjkl navigation in favor of a more traditional
key bindings:
- h,l move between windows like Tab and S-Tab
- j,k adjust the master window size
Added ability to swap current window with a marked window using
S-'-<mark>.
Diffstat (limited to 'src/Internal/Marking.hs')
| -rw-r--r-- | src/Internal/Marking.hs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/Internal/Marking.hs b/src/Internal/Marking.hs index e5cf696..606b55e 100644 --- a/src/Internal/Marking.hs +++ b/src/Internal/Marking.hs @@ -2,6 +2,7 @@ module Internal.Marking where import XMonad +import XMonad.StackSet hiding (focus) import Data.IORef import Data.Map (Map) @@ -77,3 +78,58 @@ jumpToMark ctx@(MarkContext ioref) mark = do focus w saveMarkState =<< liftIO (readIORef ioref) + +mapWindows :: (Ord a, Ord b) => (a -> b) -> StackSet i l a s sd -> StackSet i l b s sd +mapWindows fn (StackSet cur vis hid float) = + StackSet + (mapWindowsScreen cur) + (map mapWindowsScreen vis) + (map mapWindowsWorkspace hid) + (Map.mapKeys fn float) + where + mapWindowsScreen (Screen work a b) = Screen (mapWindowsWorkspace work) a b + mapWindowsWorkspace (Workspace t l stack) = + Workspace t l (fmap (mapStack fn) stack) + +-- | What genius decided to hide the instances for the Stack type!!??? +mapStack :: (a -> b) -> Stack a -> Stack b +mapStack fn (Stack focus up down) = Stack (fn focus) (map fn up) (map fn down) + +setFocusedWindow :: a -> StackSet i l a s sd -> StackSet i l a s sd +setFocusedWindow + window + (StackSet (Screen (Workspace t l stack) a b) vis hid float) = + let newStack = + case stack of + Nothing -> Nothing + Just (Stack _ up down) -> Just (Stack window up down) in + (StackSet (Screen (Workspace t l newStack) a b) vis hid float) + +swapWithFocused :: (Ord a) => a -> StackSet i l a s sd -> StackSet i l a s sd +swapWithFocused winToSwap stackSet = + case peek stackSet of + Nothing -> stackSet + Just focused -> do + setFocusedWindow winToSwap $ + mapWindows ( + \w -> if w == winToSwap then focused else w) stackSet + +swapWithLastMark :: MarkContext -> X () +swapWithLastMark ctx@(MarkContext ioref) = do + MarkState {markStateMap = m} <- liftIO $ readIORef ioref + m <- markLast <$> (liftIO $ readIORef ioref) + saveLastMark ctx + + case m of + Nothing -> return () + Just win -> windows $ swapWithFocused win + +swapWithMark :: MarkContext -> Mark -> X () +swapWithMark ctx@(MarkContext ioref) mark = do + MarkState {markStateMap = m} <- liftIO $ readIORef ioref + saveLastMark ctx + + case Map.lookup mark m of + Nothing -> return () + Just winToSwap -> + windows $ swapWithFocused winToSwap |