xmonad: refactor TabbedFix.hs

This commit is contained in:
Ingolf Wagner 2019-11-12 00:49:27 +01:00
parent ba7825cc30
commit 54a55c14a7
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
3 changed files with 44 additions and 29 deletions

View file

@ -492,6 +492,7 @@ myTerm = nixStartTerminal
-- make sure we never select a boring window -- make sure we never select a boring window
-- when we select another workspace. -- when we select another workspace.
updateBoring :: X()
updateBoring = do focusUp updateBoring = do focusUp
focusDown focusDown

View file

@ -43,47 +43,52 @@ historyLayout = ModifiedLayout FocusLayout
instance LayoutModifier FocusLayout Window where instance LayoutModifier FocusLayout Window where
modifyLayout _ workspace rectangle = do modifyLayout _ workspace rectangle = do
oldWindow <- getFocused currentFocusedWindow <- getFocused
history <- getFocusHistory <$> ES.get windowHistory <- getFocusHistory <$> ES.get
newWindow <- windowHistoryHook oldWindow newWindow <- windowHistoryHook currentFocusedWindow
case newWindow of case newWindow of
Nothing -> runLayout workspace rectangle Nothing -> runLayout workspace rectangle
Just window -> do Just window -> do
let oldstack = W.stack workspace let currentStack = W.stack workspace
let mw = L.find (`elem` W.integrate' oldstack) history let lastFocusedWindow =
L.find (`elem` W.integrate' currentStack) windowHistory
let focusWindow windowToFocus =
until ((windowToFocus ==) . W.focus) W.focusUp' <$> currentStack
let newstack = let newstack =
if window `elem` (W.integrate' oldstack) if window `elem` W.integrate' currentStack
then until ((window ==) . W.focus) W.focusUp' <$> oldstack then focusWindow window
else case mw of else case lastFocusedWindow of
Just window' -> Just window' -> focusWindow window'
until ((window' ==) . W.focus) W.focusUp' <$> oldstack Nothing -> currentStack
Nothing -> oldstack
modifyWindowSet (W.focusWindow window) modifyWindowSet (W.focusWindow window)
addAction $ do addAction $ do
maybe (return ()) makeBorderNormal oldWindow maybe (return ()) makeBorderNormal currentFocusedWindow
windows id windows id
runLayout workspace {W.stack = newstack} rectangle runLayout workspace {W.stack = newstack} rectangle
windowHistoryHook :: Maybe Window -> X (Maybe Window) windowHistoryHook :: Maybe Window -> X (Maybe Window)
windowHistoryHook Nothing = return Nothing windowHistoryHook Nothing = return Nothing
windowHistoryHook (Just window') = do windowHistoryHook (Just currentFocusedWindow) = do
history <- getFocusHistory <$> ES.get currentWindows <- gets $ W.index . windowset
currentWindowSet <- gets $ W.index . windowset windowHistory <- getFocusHistory <$> ES.get
withWindowSet $ \allWindows -> withWindowSet $ \windowSet ->
case history of case windowHistory of
[] -> do [] -> do
ES.put $ FocusHistory [window'] ES.put $ FocusHistory [currentFocusedWindow]
return Nothing return Nothing
(prev:xs) (prevFocusedWindow:focusedWindows)
| prev == window' -> return Nothing | prevFocusedWindow == currentFocusedWindow -> return Nothing
-- Previous focus was removed from ws, focus on previous existing window in current ws -- Previous focus was removed from windowSet focus on previous existing window in current windowSet
| prev `notElem` currentWindowSet -> do | prevFocusedWindow `notElem` currentWindows -> do
let history' = filter (`W.member` allWindows) xs let windowHistory' = filter (`W.member` windowSet) focusedWindows
ES.put (FocusHistory $ force history') ES.put (FocusHistory $ force windowHistory')
return $ L.find (`elem` currentWindowSet) history' return $ L.find (`elem` currentWindows) windowHistory'
-- Add current focus to history -- Add current focus to windowHistory
| otherwise -> do | otherwise -> do
ES.put $ FocusHistory $ force $ window' : L.delete window' history ES.put $
FocusHistory $
force $
currentFocusedWindow : L.delete currentFocusedWindow windowHistory
return Nothing return Nothing
makeBorderRed :: Window -> X () makeBorderRed :: Window -> X ()

View file

@ -11,8 +11,17 @@ category: Graphics
executable palos-xmonad executable palos-xmonad
main-is: Main.hs main-is: Main.hs
-- other-modules: other-extensions:
other-extensions: TypeSynonymInstances, MultiParamTypeClasses MultiParamTypeClasses
, TypeSynonymInstances
other-modules:
BoringWindows
, FloatKeys
, NixCommands
, SolarizedLight
, SubLayouts
, TabbedFix
build-depends: base build-depends: base
, xmonad , xmonad
, containers , containers