{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module XMonad.Layout.Cross {-# DEPRECATED "Use XMonad.Layout.Circle or XMonad.Layout.ThreeColumn.ThreeColMid instead" #-} (
simpleCross
, Cross(..) ) where
import XMonad( Dimension, Rectangle(..), LayoutClass(..), Resize(..), fromMessage )
import XMonad.StackSet( focus, up, down )
import XMonad.Prelude( msum )
(<%>) :: Dimension -> Rational -> Dimension
Dimension
d <%> :: Dimension -> Ratio Integer -> Dimension
<%> Ratio Integer
f = Ratio Integer -> Dimension
forall b. Integral b => Ratio Integer -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor (Ratio Integer -> Dimension) -> Ratio Integer -> Dimension
forall a b. (a -> b) -> a -> b
$ Ratio Integer
f Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* Dimension -> Ratio Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
d
data Cross a = Cross {
forall a. Cross a -> Ratio Integer
crossProp :: !Rational,
forall a. Cross a -> Ratio Integer
crossInc :: !Rational
}
deriving( Int -> Cross a -> ShowS
[Cross a] -> ShowS
Cross a -> String
(Int -> Cross a -> ShowS)
-> (Cross a -> String) -> ([Cross a] -> ShowS) -> Show (Cross a)
forall a. Int -> Cross a -> ShowS
forall a. [Cross a] -> ShowS
forall a. Cross a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> Cross a -> ShowS
showsPrec :: Int -> Cross a -> ShowS
$cshow :: forall a. Cross a -> String
show :: Cross a -> String
$cshowList :: forall a. [Cross a] -> ShowS
showList :: [Cross a] -> ShowS
Show, ReadPrec [Cross a]
ReadPrec (Cross a)
Int -> ReadS (Cross a)
ReadS [Cross a]
(Int -> ReadS (Cross a))
-> ReadS [Cross a]
-> ReadPrec (Cross a)
-> ReadPrec [Cross a]
-> Read (Cross a)
forall a. ReadPrec [Cross a]
forall a. ReadPrec (Cross a)
forall a. Int -> ReadS (Cross a)
forall a. ReadS [Cross a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Int -> ReadS (Cross a)
readsPrec :: Int -> ReadS (Cross a)
$creadList :: forall a. ReadS [Cross a]
readList :: ReadS [Cross a]
$creadPrec :: forall a. ReadPrec (Cross a)
readPrec :: ReadPrec (Cross a)
$creadListPrec :: forall a. ReadPrec [Cross a]
readListPrec :: ReadPrec [Cross a]
Read )
simpleCross :: Cross a
simpleCross :: forall a. Cross a
simpleCross = Ratio Integer -> Ratio Integer -> Cross a
forall a. Ratio Integer -> Ratio Integer -> Cross a
Cross (Ratio Integer
4Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
5) (Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
100)
instance LayoutClass Cross a where
pureLayout :: Cross a -> Rectangle -> Stack a -> [(a, Rectangle)]
pureLayout (Cross Ratio Integer
f Ratio Integer
_) Rectangle
r Stack a
s = [(Stack a -> a
forall a. Stack a -> a
focus Stack a
s, Rectangle -> Ratio Integer -> Rectangle
mainRect Rectangle
r Ratio Integer
f)]
[(a, Rectangle)] -> [(a, Rectangle)] -> [(a, Rectangle)]
forall a. [a] -> [a] -> [a]
++ [a] -> [Rectangle] -> [(a, Rectangle)]
forall a b. [a] -> [b] -> [(a, b)]
zip [a]
winCycle (Rectangle -> Ratio Integer -> [Rectangle]
upRects Rectangle
r Ratio Integer
f)
[(a, Rectangle)] -> [(a, Rectangle)] -> [(a, Rectangle)]
forall a. [a] -> [a] -> [a]
++ [a] -> [Rectangle] -> [(a, Rectangle)]
forall a b. [a] -> [b] -> [(a, b)]
zip ([a] -> [a]
forall a. [a] -> [a]
reverse [a]
winCycle) (Rectangle -> Ratio Integer -> [Rectangle]
downRects Rectangle
r Ratio Integer
f)
where winCycle :: [a]
winCycle = Stack a -> [a]
forall a. Stack a -> [a]
up Stack a
s [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a] -> [a]
forall a. [a] -> [a]
reverse (Stack a -> [a]
forall a. Stack a -> [a]
down Stack a
s)
pureMessage :: Cross a -> SomeMessage -> Maybe (Cross a)
pureMessage (Cross Ratio Integer
f Ratio Integer
d) SomeMessage
m = [Maybe (Cross a)] -> Maybe (Cross a)
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum [(Resize -> Cross a) -> Maybe Resize -> Maybe (Cross a)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Resize -> Cross a
forall {a}. Resize -> Cross a
resize (SomeMessage -> Maybe Resize
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m)]
where resize :: Resize -> Cross a
resize Resize
Shrink = Ratio Integer -> Ratio Integer -> Cross a
forall a. Ratio Integer -> Ratio Integer -> Cross a
Cross (Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Ord a => a -> a -> a
max (Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
100) (Ratio Integer -> Ratio Integer) -> Ratio Integer -> Ratio Integer
forall a b. (a -> b) -> a -> b
$ Ratio Integer
f Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
- Ratio Integer
d) Ratio Integer
d
resize Resize
Expand = Ratio Integer -> Ratio Integer -> Cross a
forall a. Ratio Integer -> Ratio Integer -> Cross a
Cross (Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Ord a => a -> a -> a
min Ratio Integer
1 (Ratio Integer -> Ratio Integer) -> Ratio Integer -> Ratio Integer
forall a b. (a -> b) -> a -> b
$ Ratio Integer
f Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
+ Ratio Integer
d) Ratio Integer
d
description :: Cross a -> String
description Cross a
_ = String
"Cross"
mainRect :: Rectangle -> Rational -> Rectangle
mainRect :: Rectangle -> Ratio Integer -> Rectangle
mainRect (Rectangle Int32
rx Int32
ry Dimension
rw Dimension
rh) Ratio Integer
f = Int32 -> Int32 -> Dimension -> Dimension -> Rectangle
Rectangle
(Int32
rx Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Dimension -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
rw Dimension -> Ratio Integer -> Dimension
<%> Ratio Integer
invf))
(Int32
ry Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Dimension -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
rh Dimension -> Ratio Integer -> Dimension
<%> Ratio Integer
invf))
(Dimension
rw Dimension -> Ratio Integer -> Dimension
<%> Ratio Integer
f) (Dimension
rh Dimension -> Ratio Integer -> Dimension
<%> Ratio Integer
f)
where invf :: Ratio Integer
invf = (Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2) Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* (Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
-Ratio Integer
f)
upRects :: Rectangle -> Rational -> [Rectangle]
upRects :: Rectangle -> Ratio Integer -> [Rectangle]
upRects Rectangle
r Ratio Integer
f = [Rectangle -> Ratio Integer -> Rectangle
topRectangle Rectangle
r Ratio Integer
nf, Rectangle -> Ratio Integer -> Rectangle
rightRectangle Rectangle
r Ratio Integer
nf]
where nf :: Ratio Integer
nf = Ratio Integer
f Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* (Ratio Integer
8Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
10)
downRects :: Rectangle -> Rational -> [Rectangle]
downRects :: Rectangle -> Ratio Integer -> [Rectangle]
downRects Rectangle
r Ratio Integer
f = [Rectangle -> Ratio Integer -> Rectangle
bottomRectangle Rectangle
r Ratio Integer
nf, Rectangle -> Ratio Integer -> Rectangle
leftRectangle Rectangle
r Ratio Integer
nf]
where nf :: Ratio Integer
nf = Ratio Integer
f Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
* (Ratio Integer
8Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
10)
topRectangle :: Rectangle -> Rational -> Rectangle
topRectangle :: Rectangle -> Ratio Integer -> Rectangle
topRectangle (Rectangle Int32
rx Int32
ry Dimension
rw Dimension
rh) Ratio Integer
f = Int32 -> Int32 -> Dimension -> Dimension -> Rectangle
Rectangle
(Int32
rx Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Dimension -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
rw Dimension -> Ratio Integer -> Dimension
<%> ((Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
-Ratio Integer
f)Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
*(Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2))))
Int32
ry
(Dimension
rw Dimension -> Ratio Integer -> Dimension
<%> Ratio Integer
f) (Dimension
rh Dimension -> Ratio Integer -> Dimension
<%> ((Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
-Ratio Integer
f)Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
*(Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2)))
rightRectangle :: Rectangle -> Rational -> Rectangle
rightRectangle :: Rectangle -> Ratio Integer -> Rectangle
rightRectangle (Rectangle Int32
rx Int32
ry Dimension
rw Dimension
rh) Ratio Integer
f = Int32 -> Int32 -> Dimension -> Dimension -> Rectangle
Rectangle
(Int32
rx Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Dimension -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
rw Dimension -> Dimension -> Dimension
forall a. Num a => a -> a -> a
- (Dimension
rw Dimension -> Ratio Integer -> Dimension
<%> (Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2))))
(Int32
ry Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Dimension -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
rh Dimension -> Ratio Integer -> Dimension
<%> ((Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
-Ratio Integer
f)Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
*(Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2))))
(Dimension
rw Dimension -> Ratio Integer -> Dimension
<%> (Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2)) (Dimension
rh Dimension -> Ratio Integer -> Dimension
<%> Ratio Integer
f)
bottomRectangle :: Rectangle -> Rational -> Rectangle
bottomRectangle :: Rectangle -> Ratio Integer -> Rectangle
bottomRectangle (Rectangle Int32
rx Int32
ry Dimension
rw Dimension
rh) Ratio Integer
f = Int32 -> Int32 -> Dimension -> Dimension -> Rectangle
Rectangle
(Int32
rx Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Dimension -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
rw Dimension -> Ratio Integer -> Dimension
<%> ((Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
-Ratio Integer
f)Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
*(Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2))))
(Int32
ry Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Dimension -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
rh Dimension -> Dimension -> Dimension
forall a. Num a => a -> a -> a
- (Dimension
rh Dimension -> Ratio Integer -> Dimension
<%> ((Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
-Ratio Integer
f)Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
*(Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2)))))
(Dimension
rw Dimension -> Ratio Integer -> Dimension
<%> Ratio Integer
f) (Dimension
rh Dimension -> Ratio Integer -> Dimension
<%> ((Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
-Ratio Integer
f)Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
*(Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2)))
leftRectangle :: Rectangle -> Rational -> Rectangle
leftRectangle :: Rectangle -> Ratio Integer -> Rectangle
leftRectangle (Rectangle Int32
rx Int32
ry Dimension
rw Dimension
rh) Ratio Integer
f = Int32 -> Int32 -> Dimension -> Dimension -> Rectangle
Rectangle
Int32
rx
(Int32
ry Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Dimension -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
rh Dimension -> Ratio Integer -> Dimension
<%> ((Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
-Ratio Integer
f)Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Num a => a -> a -> a
*(Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2))))
(Dimension
rw Dimension -> Ratio Integer -> Dimension
<%> (Ratio Integer
1Ratio Integer -> Ratio Integer -> Ratio Integer
forall a. Fractional a => a -> a -> a
/Ratio Integer
2)) (Dimension
rh Dimension -> Ratio Integer -> Dimension
<%> Ratio Integer
f)