mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
X.L.Master: Add FixMaster layout modifier
This layout modifier is useful for the case if you desire to add a master pane that has fixed width (it's fixed even if there is just one window opened). Especially nice feature if you don't want to have too wide terminal in a master pane. The layout is implemented as an addition to Master layout, so it reuses most of the code.
This commit is contained in:
parent
3b6d0c2458
commit
201c25e7a4
@ -18,6 +18,7 @@ module XMonad.Layout.Master (
|
|||||||
-- $usage
|
-- $usage
|
||||||
|
|
||||||
mastered,
|
mastered,
|
||||||
|
fixMastered,
|
||||||
multimastered,
|
multimastered,
|
||||||
AddMaster,
|
AddMaster,
|
||||||
) where
|
) where
|
||||||
@ -25,6 +26,7 @@ module XMonad.Layout.Master (
|
|||||||
import XMonad
|
import XMonad
|
||||||
import qualified XMonad.StackSet as S
|
import qualified XMonad.StackSet as S
|
||||||
import XMonad.Layout.LayoutModifier
|
import XMonad.Layout.LayoutModifier
|
||||||
|
import Control.Monad
|
||||||
|
|
||||||
-- $usage
|
-- $usage
|
||||||
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
|
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
|
||||||
@ -36,6 +38,10 @@ import XMonad.Layout.LayoutModifier
|
|||||||
--
|
--
|
||||||
-- > mastered (1/100) (1/2) $ Grid
|
-- > mastered (1/100) (1/2) $ Grid
|
||||||
--
|
--
|
||||||
|
-- Or if you prefer to have a master with fixed width:
|
||||||
|
--
|
||||||
|
-- > fixMastered (1/100) (1/2) $ Grid
|
||||||
|
--
|
||||||
-- Or if you want multiple (here two) master windows from the beginning:
|
-- Or if you want multiple (here two) master windows from the beginning:
|
||||||
--
|
--
|
||||||
-- > multimastered 2 (1/100) (1/2) $ Grid
|
-- > multimastered 2 (1/100) (1/2) $ Grid
|
||||||
@ -53,7 +59,6 @@ import XMonad.Layout.LayoutModifier
|
|||||||
-- layout
|
-- layout
|
||||||
data AddMaster a = AddMaster Int Rational Rational deriving (Show, Read)
|
data AddMaster a = AddMaster Int Rational Rational deriving (Show, Read)
|
||||||
|
|
||||||
-- | Modifier which converts given layout to a mastered one
|
|
||||||
multimastered :: (LayoutClass l a) =>
|
multimastered :: (LayoutClass l a) =>
|
||||||
Int -- ^ @k@, number of master windows
|
Int -- ^ @k@, number of master windows
|
||||||
-> Rational -- ^ @delta@, the ratio of the screen to resize by
|
-> Rational -- ^ @delta@, the ratio of the screen to resize by
|
||||||
@ -70,7 +75,7 @@ mastered :: (LayoutClass l a) =>
|
|||||||
mastered delta frac = multimastered 1 delta frac
|
mastered delta frac = multimastered 1 delta frac
|
||||||
|
|
||||||
instance LayoutModifier AddMaster Window where
|
instance LayoutModifier AddMaster Window where
|
||||||
modifyLayout (AddMaster k delta frac) = applyMaster k delta frac
|
modifyLayout (AddMaster k delta frac) = applyMaster False k delta frac
|
||||||
modifierDescription _ = "Mastered"
|
modifierDescription _ = "Mastered"
|
||||||
|
|
||||||
pureMess (AddMaster k delta frac) m
|
pureMess (AddMaster k delta frac) m
|
||||||
@ -80,19 +85,34 @@ instance LayoutModifier AddMaster Window where
|
|||||||
|
|
||||||
pureMess _ _ = Nothing
|
pureMess _ _ = Nothing
|
||||||
|
|
||||||
|
data FixMaster a = FixMaster (AddMaster a) deriving (Show, Read)
|
||||||
|
|
||||||
|
instance LayoutModifier FixMaster Window where
|
||||||
|
modifyLayout (FixMaster (AddMaster k d f)) = applyMaster True k d f
|
||||||
|
modifierDescription (FixMaster a) = "Fix" ++ modifierDescription a
|
||||||
|
pureMess (FixMaster a) m = liftM FixMaster (pureMess a m)
|
||||||
|
|
||||||
|
fixMastered :: (LayoutClass l a) =>
|
||||||
|
Rational -- ^ @delta@, the ratio of the screen to resize by
|
||||||
|
-> Rational -- ^ @frac@, what portion of the screen to use for the master window
|
||||||
|
-> l a -- ^ the layout to be modified
|
||||||
|
-> ModifiedLayout FixMaster l a
|
||||||
|
fixMastered delta frac = ModifiedLayout . FixMaster $ AddMaster 1 delta frac
|
||||||
|
|
||||||
-- | Internal function for adding a master window and let the modified
|
-- | Internal function for adding a master window and let the modified
|
||||||
-- layout handle the rest of the windows
|
-- layout handle the rest of the windows
|
||||||
applyMaster :: (LayoutClass l Window) =>
|
applyMaster :: (LayoutClass l Window) =>
|
||||||
Int
|
Bool
|
||||||
|
-> Int
|
||||||
-> Rational
|
-> Rational
|
||||||
-> Rational
|
-> Rational
|
||||||
-> S.Workspace WorkspaceId (l Window) Window
|
-> S.Workspace WorkspaceId (l Window) Window
|
||||||
-> Rectangle
|
-> Rectangle
|
||||||
-> X ([(Window, Rectangle)], Maybe (l Window))
|
-> X ([(Window, Rectangle)], Maybe (l Window))
|
||||||
applyMaster k _ frac wksp rect = do
|
applyMaster f k _ frac wksp rect = do
|
||||||
let st= S.stack wksp
|
let st= S.stack wksp
|
||||||
let ws = S.integrate' $ st
|
let ws = S.integrate' $ st
|
||||||
let n = length ws
|
let n = length ws + fromEnum f
|
||||||
if n > 1 then do
|
if n > 1 then do
|
||||||
if(n<=k) then
|
if(n<=k) then
|
||||||
return ((divideCol rect ws), Nothing)
|
return ((divideCol rect ws), Nothing)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user