{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module XMonad.Layout.TabBarDecoration
(
simpleTabBar, tabBar
, def, defaultTheme, shrinkText
, TabBarDecoration (..), XPPosition (..)
, module XMonad.Layout.ResizeScreen
) where
import Data.List
import XMonad
import qualified XMonad.StackSet as S
import XMonad.Layout.Decoration
import XMonad.Layout.ResizeScreen
import XMonad.Prompt ( XPPosition (..) )
simpleTabBar :: Eq a => l a -> ModifiedLayout (Decoration TabBarDecoration DefaultShrinker)
(ModifiedLayout ResizeScreen l) a
simpleTabBar :: l a
-> ModifiedLayout
(Decoration TabBarDecoration DefaultShrinker)
(ModifiedLayout ResizeScreen l)
a
simpleTabBar = DefaultShrinker
-> Theme
-> TabBarDecoration a
-> ModifiedLayout ResizeScreen l a
-> ModifiedLayout
(Decoration TabBarDecoration DefaultShrinker)
(ModifiedLayout ResizeScreen l)
a
forall (ds :: * -> *) a s (l :: * -> *).
(DecorationStyle ds a, Shrinker s) =>
s -> Theme -> ds a -> l a -> ModifiedLayout (Decoration ds s) l a
decoration DefaultShrinker
shrinkText Theme
forall a. Default a => a
def (XPPosition -> TabBarDecoration a
forall a. XPPosition -> TabBarDecoration a
TabBar XPPosition
Top) (ModifiedLayout ResizeScreen l a
-> ModifiedLayout
(Decoration TabBarDecoration DefaultShrinker)
(ModifiedLayout ResizeScreen l)
a)
-> (l a -> ModifiedLayout ResizeScreen l a)
-> l a
-> ModifiedLayout
(Decoration TabBarDecoration DefaultShrinker)
(ModifiedLayout ResizeScreen l)
a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> l a -> ModifiedLayout ResizeScreen l a
forall (l :: * -> *) a.
Int -> l a -> ModifiedLayout ResizeScreen l a
resizeVertical 20
tabBar :: (Eq a, Shrinker s) => s -> Theme -> XPPosition -> l a -> ModifiedLayout (Decoration TabBarDecoration s) l a
tabBar :: s
-> Theme
-> XPPosition
-> l a
-> ModifiedLayout (Decoration TabBarDecoration s) l a
tabBar s :: s
s t :: Theme
t p :: XPPosition
p = s
-> Theme
-> TabBarDecoration a
-> l a
-> ModifiedLayout (Decoration TabBarDecoration s) l a
forall (ds :: * -> *) a s (l :: * -> *).
(DecorationStyle ds a, Shrinker s) =>
s -> Theme -> ds a -> l a -> ModifiedLayout (Decoration ds s) l a
decoration s
s Theme
t (XPPosition -> TabBarDecoration a
forall a. XPPosition -> TabBarDecoration a
TabBar XPPosition
p)
data TabBarDecoration a = TabBar XPPosition deriving (ReadPrec [TabBarDecoration a]
ReadPrec (TabBarDecoration a)
Int -> ReadS (TabBarDecoration a)
ReadS [TabBarDecoration a]
(Int -> ReadS (TabBarDecoration a))
-> ReadS [TabBarDecoration a]
-> ReadPrec (TabBarDecoration a)
-> ReadPrec [TabBarDecoration a]
-> Read (TabBarDecoration a)
forall a. ReadPrec [TabBarDecoration a]
forall a. ReadPrec (TabBarDecoration a)
forall a. Int -> ReadS (TabBarDecoration a)
forall a. ReadS [TabBarDecoration a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TabBarDecoration a]
$creadListPrec :: forall a. ReadPrec [TabBarDecoration a]
readPrec :: ReadPrec (TabBarDecoration a)
$creadPrec :: forall a. ReadPrec (TabBarDecoration a)
readList :: ReadS [TabBarDecoration a]
$creadList :: forall a. ReadS [TabBarDecoration a]
readsPrec :: Int -> ReadS (TabBarDecoration a)
$creadsPrec :: forall a. Int -> ReadS (TabBarDecoration a)
Read, Int -> TabBarDecoration a -> ShowS
[TabBarDecoration a] -> ShowS
TabBarDecoration a -> String
(Int -> TabBarDecoration a -> ShowS)
-> (TabBarDecoration a -> String)
-> ([TabBarDecoration a] -> ShowS)
-> Show (TabBarDecoration a)
forall a. Int -> TabBarDecoration a -> ShowS
forall a. [TabBarDecoration a] -> ShowS
forall a. TabBarDecoration a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TabBarDecoration a] -> ShowS
$cshowList :: forall a. [TabBarDecoration a] -> ShowS
show :: TabBarDecoration a -> String
$cshow :: forall a. TabBarDecoration a -> String
showsPrec :: Int -> TabBarDecoration a -> ShowS
$cshowsPrec :: forall a. Int -> TabBarDecoration a -> ShowS
Show)
instance Eq a => DecorationStyle TabBarDecoration a where
describeDeco :: TabBarDecoration a -> String
describeDeco _ = "TabBar"
shrink :: TabBarDecoration a -> Rectangle -> Rectangle -> Rectangle
shrink _ _ r :: Rectangle
r = Rectangle
r
decorationCatchClicksHook :: TabBarDecoration a -> Window -> Int -> Int -> X Bool
decorationCatchClicksHook _ mainw :: Window
mainw _ _ = Window -> X ()
focus Window
mainw X () -> X Bool -> X Bool
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> X Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
pureDecoration :: TabBarDecoration a
-> Window
-> Window
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
-> (a, Rectangle)
-> Maybe Rectangle
pureDecoration (TabBar p :: XPPosition
p) _ dht :: Window
dht (Rectangle x :: Position
x y :: Position
y wh :: Window
wh ht :: Window
ht) s :: Stack a
s _ (w :: a
w,_) =
if Stack a -> a -> Bool
forall a. Eq a => Stack a -> a -> Bool
isInStack Stack a
s a
w then Rectangle -> Maybe Rectangle
forall a. a -> Maybe a
Just (Rectangle -> Maybe Rectangle) -> Rectangle -> Maybe Rectangle
forall a b. (a -> b) -> a -> b
$ Position -> Position -> Window -> Window -> Rectangle
Rectangle Position
nx Position
ny Window
wid (Window -> Window
forall a b. (Integral a, Num b) => a -> b
fi Window
dht) else Maybe Rectangle
forall a. Maybe a
Nothing
where wrs :: [a]
wrs = Stack a -> [a]
forall a. Stack a -> [a]
S.integrate Stack a
s
loc :: a -> Window
loc i :: a
i = (Window
wh Window -> Window -> Window
forall a. Num a => a -> a -> a
* a -> Window
forall a b. (Integral a, Num b) => a -> b
fi a
i) Window -> Window -> Window
forall a. Integral a => a -> a -> a
`div` Window -> Window -> Window
forall a. Ord a => a -> a -> a
max 1 (Int -> Window
forall a b. (Integral a, Num b) => a -> b
fi (Int -> Window) -> Int -> Window
forall a b. (a -> b) -> a -> b
$ [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
wrs)
wid :: Window
wid = Window -> (Int -> Window) -> Maybe Int -> Window
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Position -> Window
forall a b. (Integral a, Num b) => a -> b
fi Position
x) (\i :: Int
i -> Int -> Window
forall a. Integral a => a -> Window
loc (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) Window -> Window -> Window
forall a. Num a => a -> a -> a
- Int -> Window
forall a. Integral a => a -> Window
loc Int
i) (Maybe Int -> Window) -> Maybe Int -> Window
forall a b. (a -> b) -> a -> b
$ a
w a -> [a] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
`elemIndex` [a]
wrs
ny :: Position
ny = case XPPosition
p of
Top -> Position
y
Bottom -> Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Window -> Position
forall a b. (Integral a, Num b) => a -> b
fi Window
ht Position -> Position -> Position
forall a. Num a => a -> a -> a
- Window -> Position
forall a b. (Integral a, Num b) => a -> b
fi Window
dht
nx :: Position
nx = (Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
+) (Position -> Position) -> Position -> Position
forall a b. (a -> b) -> a -> b
$ Position -> (Int -> Position) -> Maybe Int -> Position
forall b a. b -> (a -> b) -> Maybe a -> b
maybe 0 (Window -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Window -> Position) -> (Int -> Window) -> Int -> Position
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Window
forall a. Integral a => a -> Window
loc) (Maybe Int -> Position) -> Maybe Int -> Position
forall a b. (a -> b) -> a -> b
$ a
w a -> [a] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
`elemIndex` [a]
wrs