-----------------------------------------------------------------------------
-- |
-- Module      :  Xmobar.Config.Types
-- Copyright   :  (c) Andrea Rossato
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  Jose A. Ortega Ruiz <jao@gnu.org>
-- Stability   :  unstable
-- Portability :  unportable
--
-- The configuration types
--
-----------------------------------------------------------------------------

module Xmobar.Config.Types
    ( Config (..)
    , XPosition (..), Align (..), Border (..), TextOutputFormat (..)
    , Segment
    , FontIndex
    , Box(..)
    , BoxBorder(..)
    , BoxOffset(..)
    , BoxMargins(..)
    , TextRenderInfo(..)
    , Widget(..)
    , SignalChan (..)
    , Action (..)
    , Button
    ) where

import qualified Control.Concurrent.STM as STM
import qualified Xmobar.Run.Runnable as R
import qualified Xmobar.System.Signal as S

import Data.Int (Int32)
import Foreign.C.Types (CInt)

import Xmobar.Run.Actions (Action (..), Button)

-- $config
-- Configuration data type

-- | The configuration data type
data Config =
    Config { Config -> String
font :: String         -- ^ Font
           , Config -> [String]
additionalFonts :: [String] -- ^ List of alternative fonts
           , Config -> String
wmClass :: String      -- ^ X11 WM_CLASS property value
           , Config -> String
wmName :: String       -- ^ X11 WM_NAME property value
           , Config -> String
bgColor :: String      -- ^ Backgroud color
           , Config -> String
fgColor :: String      -- ^ Default font color
           , Config -> XPosition
position :: XPosition  -- ^ Top Bottom or Static
           , Config -> Bool
textOutput :: Bool     -- ^ Write data to stdout instead of X
           , Config -> TextOutputFormat
textOutputFormat :: TextOutputFormat
                -- ^ Which color format to use for stdout: Ansi or Pango
           , Config -> Int
textOffset :: Int      -- ^ Offset from top of window for text
           , Config -> [Int]
textOffsets :: [Int]   -- ^ List of offsets for additionalFonts
           , Config -> Int
iconOffset :: Int      -- ^ Offset from top of window for icons
           , Config -> Border
border :: Border       -- ^ NoBorder TopB BottomB or FullB
           , Config -> String
borderColor :: String  -- ^ Border color
           , Config -> Int
borderWidth :: Int     -- ^ Border width
           , Config -> Int
alpha :: Int           -- ^ Transparency from 0 (transparent)
                                    --   to 255 (opaque)
           , Config -> Bool
hideOnStart :: Bool    -- ^ Hide (Unmap) the window on
                                    --   initialization
           , Config -> Bool
allDesktops :: Bool    -- ^ Tell the WM to map to all desktops
           , Config -> Bool
overrideRedirect :: Bool -- ^ Needed for dock behaviour in some
                                      --   non-tiling WMs
           , Config -> Bool
pickBroadest :: Bool   -- ^ Use the broadest display
                                    --   instead of the first one by
                                    --   default
           , Config -> Bool
lowerOnStart :: Bool   -- ^ lower to the bottom of the
                                    --   window stack on initialization
           , Config -> Bool
persistent :: Bool     -- ^ Whether automatic hiding should
                                    --   be enabled or disabled
           , Config -> String
iconRoot :: FilePath   -- ^ Root folder for icons
           , Config -> [Runnable]
commands :: [R.Runnable] -- ^ For setting the command,
                                      --   the command arguments
                                    --   and refresh rate for the programs
                                    --   to run (optional)
           , Config -> String
sepChar :: String      -- ^ The character to be used for indicating
                                    --   commands in the output template
                                    --   (default '%')
           , Config -> String
alignSep :: String     -- ^ Separators for left, center and
                                    --   right text alignment
           , Config -> String
template :: String     -- ^ The output template
           , Config -> Bool
verbose :: Bool        -- ^ Emit additional debug messages
           , Config -> SignalChan
signal :: SignalChan   -- ^ Channel to send signals to xmobar
           , Config -> Double
dpi :: Double          -- ^ DPI scaling factor for fonts
           } deriving (ReadPrec [Config]
ReadPrec Config
Int -> ReadS Config
ReadS [Config]
(Int -> ReadS Config)
-> ReadS [Config]
-> ReadPrec Config
-> ReadPrec [Config]
-> Read Config
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Config
readsPrec :: Int -> ReadS Config
$creadList :: ReadS [Config]
readList :: ReadS [Config]
$creadPrec :: ReadPrec Config
readPrec :: ReadPrec Config
$creadListPrec :: ReadPrec [Config]
readListPrec :: ReadPrec [Config]
Read, Int -> Config -> ShowS
[Config] -> ShowS
Config -> String
(Int -> Config -> ShowS)
-> (Config -> String) -> ([Config] -> ShowS) -> Show Config
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Config -> ShowS
showsPrec :: Int -> Config -> ShowS
$cshow :: Config -> String
show :: Config -> String
$cshowList :: [Config] -> ShowS
showList :: [Config] -> ShowS
Show)

-- | The position datatype
data XPosition = Top            -- ^ Top of the screen, full width, auto height

               | TopH           -- ^ Top of the screen, full width with
                                --   specific height
                  Int           -- ^ Height (in pixels)

                 -- | Top of the screen, full width with
                 --   specific height and margins
               | TopHM
                  Int           -- ^ Height (in pixels)
                  Int           -- ^ Left margin (in pixels)
                  Int           -- ^ Right margin (in pixels)
                  Int           -- ^ Top margin (in pixels)
                  Int           -- ^ Bottom margin (in pixels)

                 -- | Top of the screen with specific width
                 --   (as screen percentage) and alignment
               | TopW
                  Align         -- ^ Alignement (L|C|R)
                  Int           -- ^ Width as screen percentage (0-100)

                 -- | Top of the screen with specific width
                 --   (as screen percentage), height and
                 --   alignment
               | TopSize
                  Align         -- ^ Alignement (L|C|R)
                  Int           -- ^ Width as screen percentage (0-100)
                  Int           -- ^ Height (in pixels)

                 -- | Top of the screen with specific left/right
                 --   margins
               | TopP
                  Int           -- ^ Left margin (in pixels)
                  Int           -- ^ Right margin (in pixels)

                 -- | Bottom of the screen, full width, auto height
               | Bottom

               | BottomH        -- ^ Bottom of the screen, full width, with
                                --   specific height
                  Int           -- ^ Height (in pixels)

                 -- | Bottom of the screen with specific height
                 --   and margins
               | BottomHM
                  Int           -- ^ Height (in pixels)
                  Int           -- ^ Left margin (in pixels)
                  Int           -- ^ Right margin (in pixels)
                  Int           -- ^ Top margin (in pixels)
                  Int           -- ^ Bottom margin (in pixels)

                 -- | Bottom of the screen with specific
                 --   left/right margins
               | BottomP
                  Int           -- ^ Left margin (in pixels)
                  Int           -- ^ Bottom margin (in pixels)

                 -- | Bottom of the screen with specific width
                 --   (as screen percentage) and alignment
                 --   and alignment
               | BottomW
                  Align         -- ^ Alignement (L|C|R)
                  Int           -- ^ Width as screen percentage (0-100)

                 -- | Bottom of the screen with specific width
                 --   (as screen percentage), height
                 --   and alignment
               | BottomSize
                  Align         -- ^ Alignement (L|C|R)
                  Int           -- ^ Width as screen percentage (0-100)
                  Int           -- ^ Height (in pixels)

                 -- | Static position and specific size
               | Static { XPosition -> Int
xpos :: Int   -- ^ Position X (in pixels)
                        , XPosition -> Int
ypos :: Int   -- ^ Position Y (in pixels)
                        , XPosition -> Int
width :: Int  -- ^ Width (in pixels)
                        , XPosition -> Int
height :: Int -- ^ Height (in pixels)
                        }

                 -- | Along with the position characteristics
                 --   specify the screen to display the bar
               | OnScreen
                  Int           -- ^ Screen id (primary is 0)
                  XPosition     -- ^ Position
                 deriving ( ReadPrec [XPosition]
ReadPrec XPosition
Int -> ReadS XPosition
ReadS [XPosition]
(Int -> ReadS XPosition)
-> ReadS [XPosition]
-> ReadPrec XPosition
-> ReadPrec [XPosition]
-> Read XPosition
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS XPosition
readsPrec :: Int -> ReadS XPosition
$creadList :: ReadS [XPosition]
readList :: ReadS [XPosition]
$creadPrec :: ReadPrec XPosition
readPrec :: ReadPrec XPosition
$creadListPrec :: ReadPrec [XPosition]
readListPrec :: ReadPrec [XPosition]
Read, Int -> XPosition -> ShowS
[XPosition] -> ShowS
XPosition -> String
(Int -> XPosition -> ShowS)
-> (XPosition -> String)
-> ([XPosition] -> ShowS)
-> Show XPosition
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> XPosition -> ShowS
showsPrec :: Int -> XPosition -> ShowS
$cshow :: XPosition -> String
show :: XPosition -> String
$cshowList :: [XPosition] -> ShowS
showList :: [XPosition] -> ShowS
Show, XPosition -> XPosition -> Bool
(XPosition -> XPosition -> Bool)
-> (XPosition -> XPosition -> Bool) -> Eq XPosition
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: XPosition -> XPosition -> Bool
== :: XPosition -> XPosition -> Bool
$c/= :: XPosition -> XPosition -> Bool
/= :: XPosition -> XPosition -> Bool
Eq )

data Align = L | R | C deriving ( ReadPrec [Align]
ReadPrec Align
Int -> ReadS Align
ReadS [Align]
(Int -> ReadS Align)
-> ReadS [Align]
-> ReadPrec Align
-> ReadPrec [Align]
-> Read Align
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Align
readsPrec :: Int -> ReadS Align
$creadList :: ReadS [Align]
readList :: ReadS [Align]
$creadPrec :: ReadPrec Align
readPrec :: ReadPrec Align
$creadListPrec :: ReadPrec [Align]
readListPrec :: ReadPrec [Align]
Read, Int -> Align -> ShowS
[Align] -> ShowS
Align -> String
(Int -> Align -> ShowS)
-> (Align -> String) -> ([Align] -> ShowS) -> Show Align
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Align -> ShowS
showsPrec :: Int -> Align -> ShowS
$cshow :: Align -> String
show :: Align -> String
$cshowList :: [Align] -> ShowS
showList :: [Align] -> ShowS
Show, Align -> Align -> Bool
(Align -> Align -> Bool) -> (Align -> Align -> Bool) -> Eq Align
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Align -> Align -> Bool
== :: Align -> Align -> Bool
$c/= :: Align -> Align -> Bool
/= :: Align -> Align -> Bool
Eq )

data Border = NoBorder
            | TopB
            | BottomB
            | FullB
            | TopBM Int
            | BottomBM Int
            | FullBM Int
              deriving ( ReadPrec [Border]
ReadPrec Border
Int -> ReadS Border
ReadS [Border]
(Int -> ReadS Border)
-> ReadS [Border]
-> ReadPrec Border
-> ReadPrec [Border]
-> Read Border
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Border
readsPrec :: Int -> ReadS Border
$creadList :: ReadS [Border]
readList :: ReadS [Border]
$creadPrec :: ReadPrec Border
readPrec :: ReadPrec Border
$creadListPrec :: ReadPrec [Border]
readListPrec :: ReadPrec [Border]
Read, Int -> Border -> ShowS
[Border] -> ShowS
Border -> String
(Int -> Border -> ShowS)
-> (Border -> String) -> ([Border] -> ShowS) -> Show Border
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Border -> ShowS
showsPrec :: Int -> Border -> ShowS
$cshow :: Border -> String
show :: Border -> String
$cshowList :: [Border] -> ShowS
showList :: [Border] -> ShowS
Show, Border -> Border -> Bool
(Border -> Border -> Bool)
-> (Border -> Border -> Bool) -> Eq Border
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Border -> Border -> Bool
== :: Border -> Border -> Bool
$c/= :: Border -> Border -> Bool
/= :: Border -> Border -> Bool
Eq )

data TextOutputFormat = Plain | Ansi | Pango | Swaybar deriving (ReadPrec [TextOutputFormat]
ReadPrec TextOutputFormat
Int -> ReadS TextOutputFormat
ReadS [TextOutputFormat]
(Int -> ReadS TextOutputFormat)
-> ReadS [TextOutputFormat]
-> ReadPrec TextOutputFormat
-> ReadPrec [TextOutputFormat]
-> Read TextOutputFormat
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TextOutputFormat
readsPrec :: Int -> ReadS TextOutputFormat
$creadList :: ReadS [TextOutputFormat]
readList :: ReadS [TextOutputFormat]
$creadPrec :: ReadPrec TextOutputFormat
readPrec :: ReadPrec TextOutputFormat
$creadListPrec :: ReadPrec [TextOutputFormat]
readListPrec :: ReadPrec [TextOutputFormat]
Read, Int -> TextOutputFormat -> ShowS
[TextOutputFormat] -> ShowS
TextOutputFormat -> String
(Int -> TextOutputFormat -> ShowS)
-> (TextOutputFormat -> String)
-> ([TextOutputFormat] -> ShowS)
-> Show TextOutputFormat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextOutputFormat -> ShowS
showsPrec :: Int -> TextOutputFormat -> ShowS
$cshow :: TextOutputFormat -> String
show :: TextOutputFormat -> String
$cshowList :: [TextOutputFormat] -> ShowS
showList :: [TextOutputFormat] -> ShowS
Show, TextOutputFormat -> TextOutputFormat -> Bool
(TextOutputFormat -> TextOutputFormat -> Bool)
-> (TextOutputFormat -> TextOutputFormat -> Bool)
-> Eq TextOutputFormat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextOutputFormat -> TextOutputFormat -> Bool
== :: TextOutputFormat -> TextOutputFormat -> Bool
$c/= :: TextOutputFormat -> TextOutputFormat -> Bool
/= :: TextOutputFormat -> TextOutputFormat -> Bool
Eq)

type FontIndex = Int

newtype SignalChan = SignalChan {SignalChan -> Maybe (TMVar SignalType)
unSignalChan :: Maybe (STM.TMVar S.SignalType)}

instance Read SignalChan where
  readsPrec :: Int -> ReadS SignalChan
readsPrec Int
_ String
_ = ReadS SignalChan
forall a. String -> [a]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"SignalChan is not readable from a String"

instance Show SignalChan where
  show :: SignalChan -> String
show (SignalChan (Just TMVar SignalType
_)) = String
"SignalChan (Just <tmvar>)"
  show (SignalChan Maybe (TMVar SignalType)
Nothing) = String
"SignalChan Nothing"

data Widget = Icon String | Text String | Hspace Int32 deriving Int -> Widget -> ShowS
[Widget] -> ShowS
Widget -> String
(Int -> Widget -> ShowS)
-> (Widget -> String) -> ([Widget] -> ShowS) -> Show Widget
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Widget -> ShowS
showsPrec :: Int -> Widget -> ShowS
$cshow :: Widget -> String
show :: Widget -> String
$cshowList :: [Widget] -> ShowS
showList :: [Widget] -> ShowS
Show

data BoxOffset = BoxOffset Align Int32 deriving (BoxOffset -> BoxOffset -> Bool
(BoxOffset -> BoxOffset -> Bool)
-> (BoxOffset -> BoxOffset -> Bool) -> Eq BoxOffset
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BoxOffset -> BoxOffset -> Bool
== :: BoxOffset -> BoxOffset -> Bool
$c/= :: BoxOffset -> BoxOffset -> Bool
/= :: BoxOffset -> BoxOffset -> Bool
Eq, Int -> BoxOffset -> ShowS
[BoxOffset] -> ShowS
BoxOffset -> String
(Int -> BoxOffset -> ShowS)
-> (BoxOffset -> String)
-> ([BoxOffset] -> ShowS)
-> Show BoxOffset
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BoxOffset -> ShowS
showsPrec :: Int -> BoxOffset -> ShowS
$cshow :: BoxOffset -> String
show :: BoxOffset -> String
$cshowList :: [BoxOffset] -> ShowS
showList :: [BoxOffset] -> ShowS
Show)

-- margins: Top, Right, Bottom, Left
data BoxMargins = BoxMargins Int32 Int32 Int32 Int32 deriving (BoxMargins -> BoxMargins -> Bool
(BoxMargins -> BoxMargins -> Bool)
-> (BoxMargins -> BoxMargins -> Bool) -> Eq BoxMargins
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BoxMargins -> BoxMargins -> Bool
== :: BoxMargins -> BoxMargins -> Bool
$c/= :: BoxMargins -> BoxMargins -> Bool
/= :: BoxMargins -> BoxMargins -> Bool
Eq, Int -> BoxMargins -> ShowS
[BoxMargins] -> ShowS
BoxMargins -> String
(Int -> BoxMargins -> ShowS)
-> (BoxMargins -> String)
-> ([BoxMargins] -> ShowS)
-> Show BoxMargins
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BoxMargins -> ShowS
showsPrec :: Int -> BoxMargins -> ShowS
$cshow :: BoxMargins -> String
show :: BoxMargins -> String
$cshowList :: [BoxMargins] -> ShowS
showList :: [BoxMargins] -> ShowS
Show)

data BoxBorder = BBTop
               | BBBottom
               | BBVBoth
               | BBLeft
               | BBRight
               | BBHBoth
               | BBFull
                 deriving (ReadPrec [BoxBorder]
ReadPrec BoxBorder
Int -> ReadS BoxBorder
ReadS [BoxBorder]
(Int -> ReadS BoxBorder)
-> ReadS [BoxBorder]
-> ReadPrec BoxBorder
-> ReadPrec [BoxBorder]
-> Read BoxBorder
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS BoxBorder
readsPrec :: Int -> ReadS BoxBorder
$creadList :: ReadS [BoxBorder]
readList :: ReadS [BoxBorder]
$creadPrec :: ReadPrec BoxBorder
readPrec :: ReadPrec BoxBorder
$creadListPrec :: ReadPrec [BoxBorder]
readListPrec :: ReadPrec [BoxBorder]
Read, BoxBorder -> BoxBorder -> Bool
(BoxBorder -> BoxBorder -> Bool)
-> (BoxBorder -> BoxBorder -> Bool) -> Eq BoxBorder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BoxBorder -> BoxBorder -> Bool
== :: BoxBorder -> BoxBorder -> Bool
$c/= :: BoxBorder -> BoxBorder -> Bool
/= :: BoxBorder -> BoxBorder -> Bool
Eq, Int -> BoxBorder -> ShowS
[BoxBorder] -> ShowS
BoxBorder -> String
(Int -> BoxBorder -> ShowS)
-> (BoxBorder -> String)
-> ([BoxBorder] -> ShowS)
-> Show BoxBorder
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BoxBorder -> ShowS
showsPrec :: Int -> BoxBorder -> ShowS
$cshow :: BoxBorder -> String
show :: BoxBorder -> String
$cshowList :: [BoxBorder] -> ShowS
showList :: [BoxBorder] -> ShowS
Show)

data Box = Box { Box -> BoxBorder
bBorder :: BoxBorder
               , Box -> BoxOffset
bOffset :: BoxOffset
               , Box -> CInt
bWidth :: CInt
               , Box -> String
bColor :: String
               , Box -> BoxMargins
bMargins :: BoxMargins
               } deriving (Box -> Box -> Bool
(Box -> Box -> Bool) -> (Box -> Box -> Bool) -> Eq Box
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Box -> Box -> Bool
== :: Box -> Box -> Bool
$c/= :: Box -> Box -> Bool
/= :: Box -> Box -> Bool
Eq, Int -> Box -> ShowS
[Box] -> ShowS
Box -> String
(Int -> Box -> ShowS)
-> (Box -> String) -> ([Box] -> ShowS) -> Show Box
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Box -> ShowS
showsPrec :: Int -> Box -> ShowS
$cshow :: Box -> String
show :: Box -> String
$cshowList :: [Box] -> ShowS
showList :: [Box] -> ShowS
Show)

data TextRenderInfo = TextRenderInfo { TextRenderInfo -> String
tColorsString   :: String
                                     , TextRenderInfo -> Int32
tBgTopOffset    :: Int32
                                     , TextRenderInfo -> Int32
tBgBottomOffset :: Int32
                                     , TextRenderInfo -> [Box]
tBoxes          :: [Box]
                                     } deriving Int -> TextRenderInfo -> ShowS
[TextRenderInfo] -> ShowS
TextRenderInfo -> String
(Int -> TextRenderInfo -> ShowS)
-> (TextRenderInfo -> String)
-> ([TextRenderInfo] -> ShowS)
-> Show TextRenderInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextRenderInfo -> ShowS
showsPrec :: Int -> TextRenderInfo -> ShowS
$cshow :: TextRenderInfo -> String
show :: TextRenderInfo -> String
$cshowList :: [TextRenderInfo] -> ShowS
showList :: [TextRenderInfo] -> ShowS
Show

type Segment = (Widget, TextRenderInfo, FontIndex, Maybe [Action])