{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module XMonad.Layout.Circle (
Circle (..)
) where
import XMonad.Prelude
import XMonad
import XMonad.StackSet (integrate, peek)
data Circle a = Circle deriving ( ReadPrec [Circle a]
ReadPrec (Circle a)
ReadS [Circle a]
forall a. ReadPrec [Circle a]
forall a. ReadPrec (Circle a)
forall a. Int -> ReadS (Circle a)
forall a. ReadS [Circle a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Circle a]
$creadListPrec :: forall a. ReadPrec [Circle a]
readPrec :: ReadPrec (Circle a)
$creadPrec :: forall a. ReadPrec (Circle a)
readList :: ReadS [Circle a]
$creadList :: forall a. ReadS [Circle a]
readsPrec :: Int -> ReadS (Circle a)
$creadsPrec :: forall a. Int -> ReadS (Circle a)
Read, Int -> Circle a -> ShowS
forall a. Int -> Circle a -> ShowS
forall a. [Circle a] -> ShowS
forall a. Circle a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Circle a] -> ShowS
$cshowList :: forall a. [Circle a] -> ShowS
show :: Circle a -> String
$cshow :: forall a. Circle a -> String
showsPrec :: Int -> Circle a -> ShowS
$cshowsPrec :: forall a. Int -> Circle a -> ShowS
Show )
instance LayoutClass Circle Window where
doLayout :: Circle Window
-> Rectangle
-> Stack Window
-> X ([(Window, Rectangle)], Maybe (Circle Window))
doLayout Circle Window
Circle Rectangle
r Stack Window
s = do [(Window, Rectangle)]
layout <- [(Window, Rectangle)] -> X [(Window, Rectangle)]
raiseFocus forall a b. (a -> b) -> a -> b
$ forall a. Rectangle -> [a] -> [(a, Rectangle)]
circleLayout Rectangle
r forall a b. (a -> b) -> a -> b
$ forall a. Stack a -> [a]
integrate Stack Window
s
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Window, Rectangle)]
layout, forall a. Maybe a
Nothing)
circleLayout :: Rectangle -> [a] -> [(a, Rectangle)]
circleLayout :: forall a. Rectangle -> [a] -> [(a, Rectangle)]
circleLayout Rectangle
_ [] = []
circleLayout Rectangle
r (a
w:[a]
ws) = (a, Rectangle)
master forall a. a -> [a] -> [a]
: [(a, Rectangle)]
rest
where master :: (a, Rectangle)
master = (a
w, Rectangle -> Rectangle
center Rectangle
r)
rest :: [(a, Rectangle)]
rest = 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 (Rectangle -> Double -> Rectangle
satellite Rectangle
r) [Double
0, forall a. Floating a => a
pi forall 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) ..]
raiseFocus :: [(Window, Rectangle)] -> X [(Window, Rectangle)]
raiseFocus :: [(Window, Rectangle)] -> X [(Window, Rectangle)]
raiseFocus [(Window, Rectangle)]
xs = 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
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)]
xs 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)]
xs
Maybe (Window, Rectangle)
Nothing -> [(Window, Rectangle)]
xs
center :: Rectangle -> Rectangle
center :: Rectangle -> Rectangle
center (Rectangle Position
sx Position
sy Window
sw Window
sh) = Position -> Position -> Window -> Window -> Rectangle
Rectangle Position
x Position
y Window
w Window
h
where s :: Double
s = forall a. Floating a => a -> a
sqrt Double
2 :: Double
w :: Window
w = forall a b. (RealFrac a, Integral b) => a -> b
round (forall a b. (Integral a, Num b) => a -> b
fromIntegral Window
sw forall a. Fractional a => a -> a -> a
/ Double
s)
h :: Window
h = forall a b. (RealFrac a, Integral b) => a -> b
round (forall a b. (Integral a, Num b) => a -> b
fromIntegral Window
sh forall a. Fractional a => a -> a -> a
/ Double
s)
x :: Position
x = Position
sx forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral (Window
sw forall a. Num a => a -> a -> a
- Window
w) forall a. Integral a => a -> a -> a
`div` Position
2
y :: Position
y = Position
sy forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral (Window
sh forall a. Num a => a -> a -> a
- Window
h) forall a. Integral a => a -> a -> a
`div` Position
2
satellite :: Rectangle -> Double -> Rectangle
satellite :: Rectangle -> Double -> Rectangle
satellite (Rectangle Position
sx Position
sy Window
sw Window
sh) Double
a = Position -> Position -> Window -> Window -> Rectangle
Rectangle (Position
sx 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
a))
(Position
sy 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
a))
Window
w Window
h
where rx :: Double
rx = forall a b. (Integral a, Num b) => a -> b
fromIntegral (Window
sw forall a. Num a => a -> a -> a
- Window
w) forall a. Fractional a => a -> a -> a
/ Double
2
ry :: Double
ry = forall a b. (Integral a, Num b) => a -> b
fromIntegral (Window
sh forall a. Num a => a -> a -> a
- Window
h) forall a. Fractional a => a -> a -> a
/ Double
2
w :: Window
w = Window
sw forall a. Num a => a -> a -> a
* Window
10 forall a. Integral a => a -> a -> a
`div` Window
25
h :: Window
h = Window
sh forall a. Num a => a -> a -> a
* Window
10 forall a. Integral a => a -> a -> a
`div` Window
25