Add onlyOnTopPart layout modifier to xmonad

This commit is contained in:
elkowar 2021-10-27 10:47:50 +02:00
parent 0588853042
commit 9fcad51633
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F

View file

@ -146,7 +146,9 @@ myLayout = noBorders
where where
-- | if the screen is wider than 1900px it's horizontal, so use horizontal layouts. -- | if the screen is wider than 1900px it's horizontal, so use horizontal layouts.
-- if it's not, it's vertical, so use layouts for vertical screens. -- if it's not, it's vertical, so use layouts for vertical screens.
layouts = PerScreen.ifWider 1900 (PerScreen.ifWider 3000 chonkyScreenLayouts horizScreenLayouts) vertScreenLayouts layouts = PerScreen.ifWider 1900
(PerScreen.ifWider 3000 chonkyScreenLayouts (MTog.mkToggle1 ONLYONTOPHALF horizScreenLayouts))
vertScreenLayouts
chonkyScreenLayouts = (rn "UltraTall" $ withGaps $ centeredIfSingle 0.6 resizableThreeCol) chonkyScreenLayouts = (rn "UltraTall" $ withGaps $ centeredIfSingle 0.6 resizableThreeCol)
||| horizScreenLayouts ||| horizScreenLayouts
@ -183,17 +185,9 @@ myLayout = noBorders
-- | window decoration layout modifier. this needs you to add `dragginVisualizer` yourself -- | window decoration layout modifier. this needs you to add `dragginVisualizer` yourself
data WINDOWDECORATION = WINDOWDECORATION deriving (Read, Show, Eq, Typeable) data WINDOWDECORATION = WINDOWDECORATION deriving (Read, Show, Eq, Typeable)
instance MTog.Transformer WINDOWDECORATION Window where instance MTog.Transformer WINDOWDECORATION Window where
transform WINDOWDECORATION x k = k transform WINDOWDECORATION layout k = k (windowSwitcherDecoration EmptyShrinker myTabTheme layout) (const layout)
(windowSwitcherDecoration EmptyShrinker (myTabTheme { activeBorderColor = "#1d2021" }) $ x)
(const x)
-- | Layout modifier that tells layouts to only use a percentage of the screen, leaving space on the sides.
newtype Smaller a = Smaller Double
deriving (Show, Read)
instance LayoutModifier Smaller a where
modifyLayout (Smaller ratio) workspace rect = runLayout workspace (rectangleCenterPiece ratio rect)
-- | Layout Modifier that places a window in the center of the screen, -- | Layout Modifier that places a window in the center of the screen,
-- leaving room on the left and right, if there is only a single window -- leaving room on the left and right, if there is only a single window
newtype CenteredIfSingle a = CenteredIfSingle Double deriving (Show, Read) newtype CenteredIfSingle a = CenteredIfSingle Double deriving (Show, Read)
@ -206,7 +200,6 @@ instance LayoutModifier CenteredIfSingle Window where
centeredIfSingle :: Double -> l a -> ModifiedLayout CenteredIfSingle l a centeredIfSingle :: Double -> l a -> ModifiedLayout CenteredIfSingle l a
centeredIfSingle ratio = ModifiedLayout (CenteredIfSingle ratio) centeredIfSingle ratio = ModifiedLayout (CenteredIfSingle ratio)
-- | Give the center piece of a rectangle by taking the given percentage -- | Give the center piece of a rectangle by taking the given percentage
-- of the rectangle and taking that in the middle. -- of the rectangle and taking that in the middle.
rectangleCenterPiece :: Double -> Rectangle -> Rectangle rectangleCenterPiece :: Double -> Rectangle -> Rectangle
@ -216,6 +209,25 @@ rectangleCenterPiece ratio (Rectangle rx ry rw rh) = Rectangle start ry width rh
start = (fi rx) + sides start = (fi rx) + sides
width = fi $ (fi rw) - (sides * 2) width = fi $ (fi rw) - (sides * 2)
-- Layout modifier that restricts windows to only display on the top part of the monitor
-- I use this because sometimes I have my bottom monitor obscure part of the top monitor,
-- thus having windows only be placed on the visible part of the screen is a good thing.
data ONLYONTOPHALF = ONLYONTOPHALF deriving (Read, Show, Eq, Typeable)
instance MTog.Transformer ONLYONTOPHALF Window where
transform ONLYONTOPHALF layout k = k (onlyOnTopHalf 0.62 layout) (const layout)
newtype OnlyOnTopHalf a = OnlyOnTopHalf Double deriving (Show, Read)
instance LayoutModifier OnlyOnTopHalf Window where
pureModifier (OnlyOnTopHalf ratio) _screenRect _ wins = (fmap (second (rectangleTopHalf ratio)) wins, Nothing)
onlyOnTopHalf :: Double -> l a -> ModifiedLayout OnlyOnTopHalf l a
onlyOnTopHalf ratio = ModifiedLayout (OnlyOnTopHalf ratio)
-- | Calculate the top part of a rectangle by a given ratio
rectangleTopHalf :: Double -> Rectangle -> Rectangle
rectangleTopHalf ratio (Rectangle rx ry rw rh) = Rectangle rx (floor $ (fi ry) * ratio) rw (floor $ (fi rh) * ratio)
fi :: (Integral a, Num b) => a -> b fi :: (Integral a, Num b) => a -> b
fi = fromIntegral fi = fromIntegral
@ -473,7 +485,7 @@ myKeys = concat [ zoomRowBindings, tabbedBindings, multiMonitorBindings, program
, ("Kill all other copies", killAllOtherCopies) , ("Kill all other copies", killAllOtherCopies)
, ("get debug data", debugStackFullString >>= (\str -> safeSpawn "xmessage" [str])) , ("get debug data", debugStackFullString >>= (\str -> safeSpawn "xmessage" [str]))
, ("get full stackset", withWindowSet (\ws -> spawn $ "echo '" ++ show (W.floating ws) ++ "\n" ++ show (W.current ws) ++ "' | xclip -in -selection clipboard")) , ("get full stackset", withWindowSet (\ws -> spawn $ "echo '" ++ show (W.floating ws) ++ "\n" ++ show (W.current ws) ++ "' | xclip -in -selection clipboard"))
, ("asdf", windows (\ws -> ws {W.floating = M.empty })) , ("toggle top screen halving", sendMessage $ MTog.Toggle ONLYONTOPHALF)
] ]