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
-- when we select another workspace.
updateBoring :: X()
updateBoring = do focusUp
focusDown

View file

@ -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 ()

View file

@ -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