Make the width of the fst column configurable

This commit is contained in:
jecaro 2024-05-20 20:54:47 +02:00 committed by brandon s allbery kf8nh
parent da3e4bef33
commit b57212cc18

View File

@ -17,12 +17,11 @@
-- A layout which tiles the windows in columns. The windows can be moved and -- A layout which tiles the windows in columns. The windows can be moved and
-- resized in every directions. -- resized in every directions.
-- --
-- The first window appears: -- The first window appears in a single column in the center of the screen. Its
-- width is configurable (See 'coOneWindowWidth').
-- --
-- * in the center on wide screens -- The second window appears in a second column. Starting with two columns, they
-- * fullscreen otherwise -- fill up the screen.
--
-- The second window appears on a second column.
-- --
-- Subsequent windows appear on the bottom of the last columns. -- Subsequent windows appear on the bottom of the last columns.
module XMonad.Layout.Columns module XMonad.Layout.Columns
@ -78,7 +77,7 @@ import qualified XMonad.StackSet as StackSet
-- $usage -- $usage
-- Add 'Columns' to your @layoutHook@ with an initial empty state: -- Add 'Columns' to your @layoutHook@ with an initial empty state:
-- --
-- > myLayout = Full ||| Columns [] -- > myLayout = Full ||| Columns 1 []
-- --
-- Here is an example of keybindings: -- Here is an example of keybindings:
-- --
@ -156,37 +155,40 @@ type Column = [(Rational, Window)]
-- | The layout is a list of 'Column' with their relative horizontal dimensions. -- | The layout is a list of 'Column' with their relative horizontal dimensions.
type Columns = [(Rational, Column)] type Columns = [(Rational, Column)]
newtype ColumnsLayout a = Columns Columns data ColumnsLayout a = Columns
{ -- | With of the first column when there is only one window. Usefull on wide
-- screens.
coOneWindowWidth :: Rational,
-- | The current state
coColumns :: Columns
}
deriving (Show, Read) deriving (Show, Read)
instance LayoutClass ColumnsLayout Window where instance LayoutClass ColumnsLayout Window where
description _ = layoutDescription description _ = layoutDescription
emptyLayout _ _ = pure ([], Just $ Columns []) doLayout (Columns oneWindowWidth columns) rectangle stack =
pure (rectangles, Just (Columns oneWindowWidth columns'))
doLayout (Columns columns) rectangle stack =
pure (rectangles, Just (Columns columns'))
where where
hackedColumns = hackForTabs columns stack hackedColumns = hackForTabs columns stack
columns' = updateWindowList hackedColumns stack columns' = updateWindowList hackedColumns stack
rectangles = toRectangles rectangle' columns' rectangles = toRectangles rectangle' columns'
-- If there is only one window and the screen is big, we reduce the -- If there is only one window, we set the destination rectangle according
-- destination rectangle to put the window on the center of the screen. -- to the width in the layout setting.
rectangle' rectangle'
| rect_width rectangle > 2000 && (length . toList $ stack) == 1 = | (length . toList $ stack) == 1 =
scaleRationalRect rectangle singleColumnRR scaleRationalRect rectangle singleColumnRR
| otherwise = rectangle | otherwise = rectangle
singleColumnWidth = 1 % 2 singleColumnOffset = (1 - oneWindowWidth) / 2
singleColumnOffset = (1 - singleColumnWidth) / 2 singleColumnRR = RationalRect singleColumnOffset 0 oneWindowWidth 1
singleColumnRR = RationalRect singleColumnOffset 0 singleColumnWidth 1
handleMessage layout@(Columns columns) message = do handleMessage layout@(Columns oneWindowWidth columns) message = do
mbStack <- runMaybeT $ handleFocus' =<< getStack mbStack <- runMaybeT $ handleFocus' =<< getStack
changedFocus <- traverse updateStack' mbStack changedFocus <- traverse updateStack' mbStack
movedOrResized <- movedOrResized <-
runMaybeT $ runMaybeT $
Columns Columns oneWindowWidth
<$> (handleMoveOrResize' =<< peekFocus) <$> (handleMoveOrResize' =<< peekFocus)
pure $ movedOrResized <|> changedFocus pure $ movedOrResized <|> changedFocus