module XMonad.Layout.NoBorders (
noBorders,
smartBorders,
withBorder
) where
import XMonad
import XMonad.Layout.LayoutModifier
import qualified XMonad.StackSet as W
import Data.List ((\\))
import qualified Data.Map as M
data WithBorder a = WithBorder Dimension [a] deriving ( Read, Show )
instance LayoutModifier WithBorder Window where
unhook (WithBorder _ s) = asks (borderWidth . config) >>= setBorders s
redoLayout (WithBorder n s) _ _ wrs = do
asks (borderWidth . config) >>= setBorders (s \\ ws)
setBorders ws n
return (wrs, Just $ WithBorder n ws)
where
ws = map fst wrs
noBorders :: LayoutClass l Window => l Window -> ModifiedLayout WithBorder l Window
noBorders = withBorder 0
withBorder :: LayoutClass l a => Dimension -> l a -> ModifiedLayout WithBorder l a
withBorder b = ModifiedLayout $ WithBorder b []
setBorders :: [Window] -> Dimension -> X ()
setBorders ws bw = withDisplay $ \d -> mapM_ (\w -> io $ setWindowBorderWidth d w bw) ws
data SmartBorder a = SmartBorder [a] deriving (Read, Show)
instance LayoutModifier SmartBorder Window where
unhook (SmartBorder s) = asks (borderWidth . config) >>= setBorders s
redoLayout (SmartBorder s) _ st wrs = do
wset <- gets windowset
let managedwindows = W.integrate st
screens = filter (nonzerorect . screenRect . W.screenDetail) . W.screens $ wset
ws = tiled ++ floating
tiled = case filter (`elem` managedwindows) $ map fst wrs of
[w] | singleton screens -> [w]
_ -> []
floating =
[ w |
(w, W.RationalRect px py wx wy) <- M.toList . W.floating $ wset,
px <= 0, py <= 0,
wx + px >= 1, wy + py >= 1
]
asks (borderWidth . config) >>= setBorders (s \\ ws)
setBorders ws 0
return (wrs, Just $ SmartBorder ws)
where
singleton = null . drop 1
nonzerorect (Rectangle _ _ 0 0) = False
nonzerorect _ = True
smartBorders :: LayoutClass l a => l a -> ModifiedLayout SmartBorder l a
smartBorders = ModifiedLayout (SmartBorder [])