xmonad: refactorings

This commit is contained in:
Ingolf Wagner 2019-11-10 18:13:03 +01:00
parent 91bc17caa8
commit ab165dc2b5
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
3 changed files with 52 additions and 48 deletions

View file

@ -30,5 +30,8 @@ in {
home.file.".xmonad/lib/FloatKeys.hs".source = ./xmonad/FloatKeys.hs; home.file.".xmonad/lib/FloatKeys.hs".source = ./xmonad/FloatKeys.hs;
home.file.".xmonad/lib/TabbedFix.hs".source = ./xmonad/TabbedFix.hs; home.file.".xmonad/lib/TabbedFix.hs".source = ./xmonad/TabbedFix.hs;
home.file.".xmonad/lib/BoringWindows.hs".source = ./xmonad/BoringWindows.hs; home.file.".xmonad/lib/BoringWindows.hs".source = ./xmonad/BoringWindows.hs;
home.file.".xmonad/xmonad.cabal".source = ./xmonad/palos-xmonad.cabal;
home.file.".xmonad/Main.hs".source = ./xmonad/Main.hs;
}; };
} }

View file

@ -73,9 +73,6 @@ nonSelectionColor = Solarized.base02
-- http://hackage.haskell.org/package/xmonad-contrib-0.15/docs/XMonad-Layout-Tabbed.html#t:Theme -- http://hackage.haskell.org/package/xmonad-contrib-0.15/docs/XMonad-Layout-Tabbed.html#t:Theme
-- todo : when there is only one window there should not be a decoration bar, when there are 2 there should be a decoration bar
-- ResizableTall is same as Tall but has resizable rightside window
myLayout = (windowConfiguration $ myTabbed $ mySubLayout $ boringWindows resizeableTall) ||| noBorders Full myLayout = (windowConfiguration $ myTabbed $ mySubLayout $ boringWindows resizeableTall) ||| noBorders Full
-- needed for rebuild sometimes -- needed for rebuild sometimes
-- myLayout = dwmStyle shrinkText def ( layoutHook def ) ||| noBorders Full -- myLayout = dwmStyle shrinkText def ( layoutHook def ) ||| noBorders Full
@ -92,7 +89,7 @@ myLayout = (windowConfiguration $ myTabbed $ mySubLayout $ boringWindows resize
myTabbed x = smartBorders $ addTabsAlways shrinkText tabDecoration x myTabbed x = smartBorders $ addTabsAlways shrinkText tabDecoration x
mySubLayout x = subLayout [] Simplest x mySubLayout = subLayout [] Simplest
tabDecoration = def { activeColor = selectionColor tabDecoration = def { activeColor = selectionColor
, activeBorderColor = selectionColor , activeBorderColor = selectionColor

View file

@ -1,25 +1,24 @@
-- A fix to refocus windows in a sublayout
-- copied and manipulated from https://github.com/wz1000/xmonad-config/blob/master/xmonad.hs
-- thx wz1000
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeSynonymInstances #-}
module TabbedFix (historyLayout, runAllPending) where module TabbedFix (historyLayout, runAllPending) where
import XMonad
import qualified XMonad.StackSet as W
import qualified Data.List as L
import qualified XMonad.Util.ExtensibleState as ES
import Control.DeepSeq (force) import Control.DeepSeq (force)
import XMonad.Layout.LayoutModifier (LayoutModifier, ModifiedLayout(ModifiedLayout), modifyLayout) import qualified Data.List as L
import XMonad
import XMonad.Layout.LayoutModifier (LayoutModifier,
ModifiedLayout (ModifiedLayout),
modifyLayout)
import qualified XMonad.StackSet as W
import qualified XMonad.Util.ExtensibleState as ES
newtype PendingActions =
PendingActions [X ()]
newtype PendingActions = PendingActions { getPending :: [X()] }
instance ExtensionClass PendingActions where instance ExtensionClass PendingActions where
initialValue = PendingActions [] initialValue = PendingActions []
-- Add action to stack
addAction :: X () -> X () addAction :: X () -> X ()
addAction x = ES.modify (\(PendingActions xs) -> PendingActions (x:xs)) addAction x = ES.modify (\(PendingActions xs) -> PendingActions (x:xs))
@ -43,45 +42,48 @@ historyLayout :: l Window -> ModifiedLayout FocusLayout l Window
historyLayout = ModifiedLayout FocusLayout historyLayout = ModifiedLayout FocusLayout
instance LayoutModifier FocusLayout Window where instance LayoutModifier FocusLayout Window where
modifyLayout fh ws rct = do modifyLayout _ workspace rectangle = do
wold <- getFocused oldWindow <- getFocused
history <- getFocusHistory <$> ES.get history <- getFocusHistory <$> ES.get
wnew <- windowHistoryHook wold newWindow <- windowHistoryHook oldWindow
case wnew of case newWindow of
Nothing -> runLayout ws rct Nothing -> runLayout workspace rectangle
Just w -> do Just window -> do
let oldstack = W.stack ws let oldstack = W.stack workspace
let mw = L.find (`elem` W.integrate' oldstack) history let mw = L.find (`elem` W.integrate' oldstack) history
let newstack = if (w `elem` (W.integrate' oldstack)) let newstack =
then until ((w==) . W.focus) W.focusUp' <$> oldstack if window `elem` (W.integrate' oldstack)
then until ((window ==) . W.focus) W.focusUp' <$> oldstack
else case mw of else case mw of
Just w -> until ((w==) . W.focus) W.focusUp' <$> oldstack Just window' ->
until ((window' ==) . W.focus) W.focusUp' <$> oldstack
Nothing -> oldstack Nothing -> oldstack
modifyWindowSet (W.focusWindow w) modifyWindowSet (W.focusWindow window)
addAction $ do addAction $ do
maybe (return ()) makeBorderNormal wold maybe (return ()) makeBorderNormal oldWindow
windows id windows id
runLayout ws{W.stack = newstack} rct runLayout workspace {W.stack = newstack} rectangle
windowHistoryHook :: Maybe Window -> X (Maybe Window)
windowHistoryHook Nothing = return Nothing windowHistoryHook Nothing = return Nothing
windowHistoryHook (Just w) = do windowHistoryHook (Just window') = do
hist <- getFocusHistory <$> ES.get history <- getFocusHistory <$> ES.get
curws <- gets $ W.index . windowset currentWindowSet <- gets $ W.index . windowset
withWindowSet $ \allws -> withWindowSet $ \allWindows ->
case hist of case history of
[] -> do [] -> do
ES.put $ FocusHistory[w] ES.put $ FocusHistory [window']
return Nothing return Nothing
(prev:xs) (prev:xs)
| prev == w -> return Nothing | prev == window' -> return Nothing
-- Previous focus was removed from ws, focus on previous existing window in current ws -- Previous focus was removed from ws, focus on previous existing window in current ws
| not (prev `elem` curws) -> do | prev `notElem` currentWindowSet -> do
let hist' = filter (`W.member` allws) xs let history' = filter (`W.member` allWindows) xs
ES.put (FocusHistory $ force $ hist') ES.put (FocusHistory $ force history')
return $ L.find (\x -> x `elem` curws ) hist' return $ L.find (`elem` currentWindowSet) history'
-- Add current focus to history -- Add current focus to history
| otherwise -> do | otherwise -> do
ES.put $ FocusHistory $ force $ (w:L.delete w hist) ES.put $ FocusHistory $ force $ window' : L.delete window' history
return Nothing return Nothing
makeBorderRed :: Window -> X () makeBorderRed :: Window -> X ()
@ -90,10 +92,12 @@ makeBorderRed w =
setWindowBorder d w 0xff0000 setWindowBorder d w 0xff0000
-- wz1000: palo: btw, you will need to change the color in makeBorderNormal to your unfocused border color -- wz1000: palo: btw, you will need to change the color in makeBorderNormal to your unfocused border color
makeBorderNormal :: Window -> X ()
makeBorderNormal w = makeBorderNormal w =
withDisplay $ \d -> io $ do withDisplay $ \d -> io $ do
setWindowBorder d w 0x2b2b2b setWindowBorder d w 0x2b2b2b
makeBorderFocused :: Window -> X ()
makeBorderFocused w = makeBorderFocused w =
withDisplay $ \d -> io $ do withDisplay $ \d -> io $ do
setWindowBorder d w 0xcccccc setWindowBorder d w 0xcccccc