summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Config/Types.hs
blob: 785b55b40f593fd5e28c22d6b00428678980f65e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
-----------------------------------------------------------------------------
-- |
-- 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 { font :: String         -- ^ Font
           , additionalFonts :: [String] -- ^ List of alternative fonts
           , wmClass :: String      -- ^ X11 WM_CLASS property value
           , wmName :: String       -- ^ X11 WM_NAME property value
           , bgColor :: String      -- ^ Backgroud color
           , fgColor :: String      -- ^ Default font color
           , position :: XPosition  -- ^ Top Bottom or Static
           , textOutput :: Bool     -- ^ Write data to stdout instead of X
           , textOutputFormat :: TextOutputFormat
                -- ^ Which color format to use for stdout: Ansi or Pango
           , textOffset :: Int      -- ^ Offset from top of window for text
           , textOffsets :: [Int]   -- ^ List of offsets for additionalFonts
           , iconOffset :: Int      -- ^ Offset from top of window for icons
           , border :: Border       -- ^ NoBorder TopB BottomB or FullB
           , borderColor :: String  -- ^ Border color
           , borderWidth :: Int     -- ^ Border width
           , alpha :: Int           -- ^ Transparency from 0 (transparent)
                                    --   to 255 (opaque)
           , hideOnStart :: Bool    -- ^ Hide (Unmap) the window on
                                    --   initialization
           , allDesktops :: Bool    -- ^ Tell the WM to map to all desktops
           , overrideRedirect :: Bool -- ^ Needed for dock behaviour in some
                                      --   non-tiling WMs
           , pickBroadest :: Bool   -- ^ Use the broadest display
                                    --   instead of the first one by
                                    --   default
           , lowerOnStart :: Bool   -- ^ lower to the bottom of the
                                    --   window stack on initialization
           , persistent :: Bool     -- ^ Whether automatic hiding should
                                    --   be enabled or disabled
           , iconRoot :: FilePath   -- ^ Root folder for icons
           , commands :: [R.Runnable] -- ^ For setting the command,
                                      --   the command arguments
                                    --   and refresh rate for the programs
                                    --   to run (optional)
           , sepChar :: String      -- ^ The character to be used for indicating
                                    --   commands in the output template
                                    --   (default '%')
           , alignSep :: String     -- ^ Separators for left, center and
                                    --   right text alignment
           , template :: String     -- ^ The output template
           , verbose :: Bool        -- ^ Emit additional debug messages
           , signal :: SignalChan   -- ^ Channel to send signals to xmobar
           , dpi :: Double          -- ^ DPI scaling factor for fonts
           } deriving (Read, 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 { xpos :: Int   -- ^ Position X (in pixels)
                        , ypos :: Int   -- ^ Position Y (in pixels)
                        , width :: Int  -- ^ Width (in pixels)
                        , 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 ( Read, Show, Eq )

data Align = L | R | C deriving ( Read, Show, Eq )

data Border = NoBorder
            | TopB
            | BottomB
            | FullB
            | TopBM Int
            | BottomBM Int
            | FullBM Int
              deriving ( Read, Show, Eq )

data TextOutputFormat = Plain | Ansi | Pango | Swaybar deriving (Read, Show, Eq)

type FontIndex = Int

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

instance Read SignalChan where
  readsPrec _ _ = fail "SignalChan is not readable from a String"

instance Show SignalChan where
  show (SignalChan (Just _)) = "SignalChan (Just <tmvar>)"
  show (SignalChan Nothing) = "SignalChan Nothing"

data Widget = Icon String | Text String | Hspace Int32 deriving Show

data BoxOffset = BoxOffset Align Int32 deriving (Eq, Show)

-- margins: Top, Right, Bottom, Left
data BoxMargins = BoxMargins Int32 Int32 Int32 Int32 deriving (Eq, Show)

data BoxBorder = BBTop
               | BBBottom
               | BBVBoth
               | BBLeft
               | BBRight
               | BBHBoth
               | BBFull
                 deriving (Read, Eq, Show)

data Box = Box { bBorder :: BoxBorder
               , bOffset :: BoxOffset
               , bWidth :: CInt
               , bColor :: String
               , bMargins :: BoxMargins
               } deriving (Eq, Show)

data TextRenderInfo = TextRenderInfo { tColorsString   :: String
                                     , tBgTopOffset    :: Int32
                                     , tBgBottomOffset :: Int32
                                     , tBoxes          :: [Box]
                                     } deriving Show

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