From 54a55c14a7f07f3233c60abcb3d1dcc2595e3958 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Tue, 12 Nov 2019 00:49:27 +0100 Subject: [PATCH] xmonad: refactor TabbedFix.hs --- system/desktop/home-manager/xmonad/Main.hs | 1 + .../desktop/home-manager/xmonad/TabbedFix.hs | 59 ++++++++++--------- .../home-manager/xmonad/palos-xmonad.cabal | 13 +++- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/system/desktop/home-manager/xmonad/Main.hs b/system/desktop/home-manager/xmonad/Main.hs index 3d1f0ef..e5f1222 100644 --- a/system/desktop/home-manager/xmonad/Main.hs +++ b/system/desktop/home-manager/xmonad/Main.hs @@ -492,6 +492,7 @@ myTerm = nixStartTerminal -- make sure we never select a boring window -- when we select another workspace. +updateBoring :: X() updateBoring = do focusUp focusDown diff --git a/system/desktop/home-manager/xmonad/TabbedFix.hs b/system/desktop/home-manager/xmonad/TabbedFix.hs index 3f1d1ee..b1f2836 100644 --- a/system/desktop/home-manager/xmonad/TabbedFix.hs +++ b/system/desktop/home-manager/xmonad/TabbedFix.hs @@ -43,47 +43,52 @@ historyLayout = ModifiedLayout FocusLayout instance LayoutModifier FocusLayout Window where modifyLayout _ workspace rectangle = do - oldWindow <- getFocused - history <- getFocusHistory <$> ES.get - newWindow <- windowHistoryHook oldWindow + currentFocusedWindow <- getFocused + windowHistory <- getFocusHistory <$> ES.get + newWindow <- windowHistoryHook currentFocusedWindow case newWindow of Nothing -> runLayout workspace rectangle Just window -> do - let oldstack = W.stack workspace - let mw = L.find (`elem` W.integrate' oldstack) history + let currentStack = W.stack workspace + let lastFocusedWindow = + L.find (`elem` W.integrate' currentStack) windowHistory + let focusWindow windowToFocus = + until ((windowToFocus ==) . W.focus) W.focusUp' <$> currentStack let newstack = - if window `elem` (W.integrate' oldstack) - then until ((window ==) . W.focus) W.focusUp' <$> oldstack - else case mw of - Just window' -> - until ((window' ==) . W.focus) W.focusUp' <$> oldstack - Nothing -> oldstack + if window `elem` W.integrate' currentStack + then focusWindow window + else case lastFocusedWindow of + Just window' -> focusWindow window' + Nothing -> currentStack modifyWindowSet (W.focusWindow window) addAction $ do - maybe (return ()) makeBorderNormal oldWindow + maybe (return ()) makeBorderNormal currentFocusedWindow windows id runLayout workspace {W.stack = newstack} rectangle windowHistoryHook :: Maybe Window -> X (Maybe Window) windowHistoryHook Nothing = return Nothing -windowHistoryHook (Just window') = do - history <- getFocusHistory <$> ES.get - currentWindowSet <- gets $ W.index . windowset - withWindowSet $ \allWindows -> - case history of +windowHistoryHook (Just currentFocusedWindow) = do + currentWindows <- gets $ W.index . windowset + windowHistory <- getFocusHistory <$> ES.get + withWindowSet $ \windowSet -> + case windowHistory of [] -> do - ES.put $ FocusHistory [window'] + ES.put $ FocusHistory [currentFocusedWindow] return Nothing - (prev:xs) - | prev == window' -> return Nothing - -- Previous focus was removed from ws, focus on previous existing window in current ws - | prev `notElem` currentWindowSet -> do - let history' = filter (`W.member` allWindows) xs - ES.put (FocusHistory $ force history') - return $ L.find (`elem` currentWindowSet) history' - -- Add current focus to history + (prevFocusedWindow:focusedWindows) + | prevFocusedWindow == currentFocusedWindow -> return Nothing + -- Previous focus was removed from windowSet focus on previous existing window in current windowSet + | prevFocusedWindow `notElem` currentWindows -> do + let windowHistory' = filter (`W.member` windowSet) focusedWindows + ES.put (FocusHistory $ force windowHistory') + return $ L.find (`elem` currentWindows) windowHistory' + -- Add current focus to windowHistory | otherwise -> do - ES.put $ FocusHistory $ force $ window' : L.delete window' history + ES.put $ + FocusHistory $ + force $ + currentFocusedWindow : L.delete currentFocusedWindow windowHistory return Nothing makeBorderRed :: Window -> X () diff --git a/system/desktop/home-manager/xmonad/palos-xmonad.cabal b/system/desktop/home-manager/xmonad/palos-xmonad.cabal index 2a6f0fa..cde78b3 100644 --- a/system/desktop/home-manager/xmonad/palos-xmonad.cabal +++ b/system/desktop/home-manager/xmonad/palos-xmonad.cabal @@ -11,8 +11,17 @@ category: Graphics executable palos-xmonad main-is: Main.hs - -- other-modules: - other-extensions: TypeSynonymInstances, MultiParamTypeClasses + other-extensions: + MultiParamTypeClasses + , TypeSynonymInstances + other-modules: + BoringWindows + , FloatKeys + , NixCommands + , SolarizedLight + , SubLayouts + , TabbedFix + build-depends: base , xmonad , containers