{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RecordWildCards #-}
module XMonad.Layout.CircleEx (
CircleEx (..), circle, circleEx,
CircleExMsg (..)
)
where
import Data.Ratio
import XMonad
import XMonad.StackSet (Stack)
import XMonad.Prelude
import qualified XMonad.StackSet as W
data CircleEx a = CircleEx
{ forall a. CircleEx a -> Int
cNMaster :: !Int
, forall a. CircleEx a -> Rational
cMasterRatio :: !Rational
, forall a. CircleEx a -> Rational
cStackRatio :: !Rational
, forall a. CircleEx a -> Rational
cMultiplier :: !Rational
, forall a. CircleEx a -> Double
cDelta :: !Double
} deriving (CircleEx a -> CircleEx a -> Bool
forall a. CircleEx a -> CircleEx a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CircleEx a -> CircleEx a -> Bool
$c/= :: forall a. CircleEx a -> CircleEx a -> Bool
== :: CircleEx a -> CircleEx a -> Bool
$c== :: forall a. CircleEx a -> CircleEx a -> Bool
Eq, Int -> CircleEx a -> ShowS
forall a. Int -> CircleEx a -> ShowS
forall a. [CircleEx a] -> ShowS
forall a. CircleEx a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CircleEx a] -> ShowS
$cshowList :: forall a. [CircleEx a] -> ShowS
show :: CircleEx a -> String
$cshow :: forall a. CircleEx a -> String
showsPrec :: Int -> CircleEx a -> ShowS
$cshowsPrec :: forall a. Int -> CircleEx a -> ShowS
Show, ReadPrec [CircleEx a]
ReadPrec (CircleEx a)
ReadS [CircleEx a]
forall a. ReadPrec [CircleEx a]
forall a. ReadPrec (CircleEx a)
forall a. Int -> ReadS (CircleEx a)
forall a. ReadS [CircleEx a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CircleEx a]
$creadListPrec :: forall a. ReadPrec [CircleEx a]
readPrec :: ReadPrec (CircleEx a)
$creadPrec :: forall a. ReadPrec (CircleEx a)
readList :: ReadS [CircleEx a]
$creadList :: forall a. ReadS [CircleEx a]
readsPrec :: Int -> ReadS (CircleEx a)
$creadsPrec :: forall a. Int -> ReadS (CircleEx a)
Read)
circle :: CircleEx a
circle :: forall a. CircleEx a
circle = forall a.
Int -> Rational -> Rational -> Rational -> Double -> CircleEx a
CircleEx Int
1 (Integer
70forall a. Integral a => a -> a -> Ratio a
%Integer
99) (Integer
2forall a. Integral a => a -> a -> Ratio a
%Integer
5) Rational
1 Double
0
circleEx :: CircleEx a
circleEx :: forall a. CircleEx a
circleEx = forall a.
Int -> Rational -> Rational -> Rational -> Double -> CircleEx a
CircleEx Int
1 (Integer
4forall a. Integral a => a -> a -> Ratio a
%Integer
5) (Integer
3forall a. Integral a => a -> a -> Ratio a
%Integer
5) (Integer
5forall a. Integral a => a -> a -> Ratio a
%Integer
6) Double
0
data CircleExMsg
= Rotate !Double
| IncStackRatio !Rational
| IncMultiplier !Rational
deriving (CircleExMsg -> CircleExMsg -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CircleExMsg -> CircleExMsg -> Bool
$c/= :: CircleExMsg -> CircleExMsg -> Bool
== :: CircleExMsg -> CircleExMsg -> Bool
$c== :: CircleExMsg -> CircleExMsg -> Bool
Eq, Int -> CircleExMsg -> ShowS
[CircleExMsg] -> ShowS
CircleExMsg -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CircleExMsg] -> ShowS
$cshowList :: [CircleExMsg] -> ShowS
show :: CircleExMsg -> String
$cshow :: CircleExMsg -> String
showsPrec :: Int -> CircleExMsg -> ShowS
$cshowsPrec :: Int -> CircleExMsg -> ShowS
Show, Typeable)
instance Message CircleExMsg
instance LayoutClass CircleEx Window where
doLayout :: CircleEx Window -> Rectangle -> Stack Window -> X ([(Window, Rectangle)], Maybe (CircleEx Window))
doLayout :: CircleEx Window
-> Rectangle
-> Stack Window
-> X ([(Window, Rectangle)], Maybe (CircleEx Window))
doLayout CircleEx Window
layout Rectangle
rect Stack Window
stack = do
[(Window, Rectangle)]
result <- [(Window, Rectangle)] -> X [(Window, Rectangle)]
raiseFocus forall a b. (a -> b) -> a -> b
$ forall a. CircleEx a -> Rectangle -> [a] -> [(a, Rectangle)]
circleLayout CircleEx Window
layout Rectangle
rect forall a b. (a -> b) -> a -> b
$ forall a. Stack a -> [a]
W.integrate Stack Window
stack
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Window, Rectangle)]
result, forall a. Maybe a
Nothing)
pureMessage :: CircleEx Window -> SomeMessage -> Maybe (CircleEx Window)
pureMessage :: CircleEx Window -> SomeMessage -> Maybe (CircleEx Window)
pureMessage CircleEx Window
layout SomeMessage
m =
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum [forall a. IncMasterN -> CircleEx a
changeMasterN forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m,
forall a. Resize -> CircleEx a
resize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m,
forall a. CircleExMsg -> CircleEx a
specific forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m]
where
deltaSize :: Rational
deltaSize = Integer
11 forall a. Integral a => a -> a -> Ratio a
% Integer
10
resize :: Resize -> CircleEx a
resize :: forall a. Resize -> CircleEx a
resize Resize
Shrink = CircleEx Window
layout {cMasterRatio :: Rational
cMasterRatio = forall a. Ord a => a -> a -> a
max Rational
0.1 forall a b. (a -> b) -> a -> b
$ forall a. Ord a => a -> a -> a
min Rational
1.0 forall a b. (a -> b) -> a -> b
$ forall a. CircleEx a -> Rational
cMasterRatio CircleEx Window
layout forall a. Fractional a => a -> a -> a
/ Rational
deltaSize}
resize Resize
Expand = CircleEx Window
layout {cMasterRatio :: Rational
cMasterRatio = forall a. Ord a => a -> a -> a
max Rational
0.1 forall a b. (a -> b) -> a -> b
$ forall a. Ord a => a -> a -> a
min Rational
1.0 forall a b. (a -> b) -> a -> b
$ forall a. CircleEx a -> Rational
cMasterRatio CircleEx Window
layout forall a. Num a => a -> a -> a
* Rational
deltaSize}
changeMasterN :: IncMasterN -> CircleEx a
changeMasterN :: forall a. IncMasterN -> CircleEx a
changeMasterN (IncMasterN Int
d) = CircleEx Window
layout {cNMaster :: Int
cNMaster = forall a. Ord a => a -> a -> a
max Int
0 (forall a. CircleEx a -> Int
cNMaster CircleEx Window
layout forall a. Num a => a -> a -> a
+ Int
d)}
specific :: CircleExMsg -> CircleEx a
specific :: forall a. CircleExMsg -> CircleEx a
specific (Rotate Double
delta) = CircleEx Window
layout {cDelta :: Double
cDelta = Double
delta forall a. Num a => a -> a -> a
+ forall a. CircleEx a -> Double
cDelta CircleEx Window
layout}
specific (IncStackRatio Rational
delta) = CircleEx Window
layout {cStackRatio :: Rational
cStackRatio = forall a. Ord a => a -> a -> a
max Rational
0.1 forall a b. (a -> b) -> a -> b
$ forall a. Ord a => a -> a -> a
min Rational
2.0 forall a b. (a -> b) -> a -> b
$ Rational
delta forall a. Num a => a -> a -> a
+ forall a. CircleEx a -> Rational
cStackRatio CircleEx Window
layout}
specific (IncMultiplier Rational
delta) = CircleEx Window
layout {cMultiplier :: Rational
cMultiplier = forall a. Ord a => a -> a -> a
max Rational
0.1 forall a b. (a -> b) -> a -> b
$ forall a. Ord a => a -> a -> a
min Rational
2.0 forall a b. (a -> b) -> a -> b
$ Rational
delta forall a. Num a => a -> a -> a
+ forall a. CircleEx a -> Rational
cMultiplier CircleEx Window
layout}
circleLayout :: CircleEx a -> Rectangle -> [a] -> [(a, Rectangle)]
circleLayout :: forall a. CircleEx a -> Rectangle -> [a] -> [(a, Rectangle)]
circleLayout CircleEx a
_ Rectangle
_ [] = []
circleLayout (CircleEx {Double
Int
Rational
cDelta :: Double
cMultiplier :: Rational
cStackRatio :: Rational
cMasterRatio :: Rational
cNMaster :: Int
cDelta :: forall a. CircleEx a -> Double
cMultiplier :: forall a. CircleEx a -> Rational
cStackRatio :: forall a. CircleEx a -> Rational
cMasterRatio :: forall a. CircleEx a -> Rational
cNMaster :: forall a. CircleEx a -> Int
..}) Rectangle
rectangle [a]
wins =
forall a. [a] -> [(a, Rectangle)]
master (forall a. Int -> [a] -> [a]
take Int
cNMaster [a]
wins) forall a. [a] -> [a] -> [a]
++ forall a. [a] -> [(a, Rectangle)]
rest (forall a. Int -> [a] -> [a]
drop Int
cNMaster [a]
wins)
where
master :: [a] -> [(a, Rectangle)]
master :: forall a. [a] -> [(a, Rectangle)]
master [a]
ws = forall a b. [a] -> [b] -> [(a, b)]
zip [a]
ws forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (Rational -> Rational -> Rectangle -> Int -> Rectangle
placeCenter Rational
cMasterRatio Rational
cMultiplier Rectangle
rectangle)
[Int
cNMasterforall a. Num a => a -> a -> a
-Int
1, Int
cNMasterforall a. Num a => a -> a -> a
-Int
2 .. Int
0]
rest :: [a] -> [(a, Rectangle)]
rest :: forall a. [a] -> [(a, Rectangle)]
rest [a]
ws = forall a b. [a] -> [b] -> [(a, b)]
zip [a]
ws forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (Rational -> Rational -> Rectangle -> Double -> Int -> Rectangle
placeSatellite Rational
cStackRatio Rational
cMultiplier Rectangle
rectangle)
(forall a b. (a -> b) -> [a] -> [b]
map (forall a. Num a => a -> a -> a
+ Double
cDelta) [Double
0, forall a. Floating a => a
piforall a. Num a => a -> a -> a
*Double
2 forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral (forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
ws) ..])
[Int
0 ..]
raiseFocus :: [(Window, Rectangle)] -> X [(Window, Rectangle)]
raiseFocus :: [(Window, Rectangle)] -> X [(Window, Rectangle)]
raiseFocus [(Window, Rectangle)]
wrs = do
Maybe Window
focused <- forall a. (WindowSet -> X a) -> X a
withWindowSet (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((forall a. Eq a => a -> a -> Bool
== Maybe Window
focused) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) [(Window, Rectangle)]
wrs of
Just (Window, Rectangle)
x -> (Window, Rectangle)
x forall a. a -> [a] -> [a]
: forall a. Eq a => a -> [a] -> [a]
delete (Window, Rectangle)
x [(Window, Rectangle)]
wrs
Maybe (Window, Rectangle)
Nothing -> [(Window, Rectangle)]
wrs
placeCenter :: Rational -> Rational -> Rectangle -> Int -> Rectangle
placeCenter :: Rational -> Rational -> Rectangle -> Int -> Rectangle
placeCenter Rational
ratio Rational
multiplier (Rectangle Position
x Position
y Dimension
width Dimension
height) Int
n = Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x' Position
y' Dimension
width' Dimension
height'
where
m :: Rational
m = Rational
ratio forall a. Num a => a -> a -> a
* Rational
multiplier forall a b. (Num a, Integral b) => a -> b -> a
^ Int
n
width' :: Dimension
width' = forall a b. (RealFrac a, Integral b) => a -> b
round (Rational
m forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
width)
height' :: Dimension
height' = forall a b. (RealFrac a, Integral b) => a -> b
round (Rational
m forall a. Num a => a -> a -> a
* forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
height)
x' :: Position
x' = Position
x forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
width forall a. Num a => a -> a -> a
- Dimension
width') forall a. Integral a => a -> a -> a
`div` Position
2
y' :: Position
y' = Position
y forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
height forall a. Num a => a -> a -> a
- Dimension
height') forall a. Integral a => a -> a -> a
`div` Position
2
placeSatellite :: Rational -> Rational -> Rectangle -> Double -> Int -> Rectangle
placeSatellite :: Rational -> Rational -> Rectangle -> Double -> Int -> Rectangle
placeSatellite Rational
ratio Rational
multiplier (Rectangle Position
x Position
y Dimension
width Dimension
height) Double
alpha Int
n =
Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x' Position
y' Dimension
width' Dimension
height'
where
m :: Rational
m = Rational
ratio forall a. Num a => a -> a -> a
* Rational
multiplier forall a b. (Num a, Integral b) => a -> b -> a
^ Int
n
x' :: Position
x' = Position
x forall a. Num a => a -> a -> a
+ forall a b. (RealFrac a, Integral b) => a -> b
round (Double
rx forall a. Num a => a -> a -> a
+ Double
rx forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
cos Double
alpha)
y' :: Position
y' = Position
y forall a. Num a => a -> a -> a
+ forall a b. (RealFrac a, Integral b) => a -> b
round (Double
ry forall a. Num a => a -> a -> a
+ Double
ry forall a. Num a => a -> a -> a
* forall a. Floating a => a -> a
sin Double
alpha)
rx :: Double
rx = forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
width forall a. Num a => a -> a -> a
- Dimension
width') forall a. Fractional a => a -> a -> a
/ Double
2
ry :: Double
ry = forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
height forall a. Num a => a -> a -> a
- Dimension
height') forall a. Fractional a => a -> a -> a
/ Double
2
width' :: Dimension
width' = forall a b. (RealFrac a, Integral b) => a -> b
round (forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
width forall a. Num a => a -> a -> a
* Rational
m)
height' :: Dimension
height' = forall a b. (RealFrac a, Integral b) => a -> b
round (forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
height forall a. Num a => a -> a -> a
* Rational
m)