diff options
-rw-r--r-- | src/Xmobar/Config/Parse.hs | 19 | ||||
-rw-r--r-- | src/Xmobar/Config/Types.hs | 23 | ||||
-rw-r--r-- | src/Xmobar/Run/Parsers.hs | 2 | ||||
-rw-r--r-- | src/Xmobar/X11/Boxes.hs | 5 | ||||
-rw-r--r-- | src/Xmobar/X11/CairoDraw.hs | 4 |
5 files changed, 30 insertions, 23 deletions
diff --git a/src/Xmobar/Config/Parse.hs b/src/Xmobar/Config/Parse.hs index 41088e9..16af3db 100644 --- a/src/Xmobar/Config/Parse.hs +++ b/src/Xmobar/Config/Parse.hs @@ -16,7 +16,10 @@ ------------------------------------------------------------------------------ -module Xmobar.Config.Parse(readConfig, parseConfig) where +module Xmobar.Config.Parse(readConfig + , parseConfig + , indexedFont + , indexedOffset) where import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec.Number (int) @@ -174,3 +177,17 @@ commandsErr = "commands: this usually means that a command could not" ++ readConfig :: Config -> FilePath -> IO (Either ParseError (Config,[String])) readConfig defaultConfig f = liftIO (S.readFile f) <&> parseConfig defaultConfig + +-- | Extracts from a configuration the additional font at the corresponding index. +-- Returns the default font if not present. +indexedFont :: Config -> FontIndex -> String +indexedFont config idx = + if idx < 1 || idx > length (additionalFonts config) + then font config else additionalFonts config !! (idx - 1) + +-- | Extracts from a configuration the offset at the corresponding index. +-- Returns the default offset if not present. +indexedOffset :: Config -> FontIndex -> Int +indexedOffset config idx = + if idx < 1 || idx > length (textOffsets config) + then textOffset config else textOffsets config !! (idx - 1) diff --git a/src/Xmobar/Config/Types.hs b/src/Xmobar/Config/Types.hs index 3f2297f..a448d5d 100644 --- a/src/Xmobar/Config/Types.hs +++ b/src/Xmobar/Config/Types.hs @@ -1,6 +1,6 @@ ----------------------------------------------------------------------------- -- | --- Module : Xmobar.Config +-- Module : Xmobar.Config.Types -- Copyright : (c) Andrea Rossato -- License : BSD-style (see LICENSE) -- @@ -13,12 +13,9 @@ ----------------------------------------------------------------------------- module Xmobar.Config.Types - ( -- * Configuration - -- $config - Config (..) + ( Config (..) , XPosition (..), Align (..), Border (..), TextOutputFormat (..) - , SignalChan (..) - , indexedFont, indexedOffset + , FontIndex, SignalChan (..) ) where import qualified Control.Concurrent.STM as STM @@ -71,19 +68,9 @@ data Config = -- right text alignment , template :: String -- ^ The output template , verbose :: Bool -- ^ Emit additional debug messages - , signal :: SignalChan -- ^ The signal channel used to send signals to xmobar + , signal :: SignalChan -- ^ The signal channel to send signals to xmobar } deriving (Read, Show) -indexedFont :: Config -> Int -> String -indexedFont config idx = - if idx < 1 || idx > length (additionalFonts config) - then font config else additionalFonts config !! (idx - 1) - -indexedOffset :: Config -> Int -> Int -indexedOffset config idx = - if idx < 1 || idx > length (textOffsets config) - then textOffset config else textOffsets config !! (idx - 1) - data XPosition = Top | TopH Int | TopW Align Int @@ -111,6 +98,8 @@ data Border = NoBorder data TextOutputFormat = Plain | Ansi | Pango | Swaybar deriving (Read, Show, Eq) +type FontIndex = Int + newtype SignalChan = SignalChan { unSignalChan :: Maybe (STM.TMVar SignalType) } instance Read SignalChan where diff --git a/src/Xmobar/Run/Parsers.hs b/src/Xmobar/Run/Parsers.hs index c0f3104..9b36786 100644 --- a/src/Xmobar/Run/Parsers.hs +++ b/src/Xmobar/Run/Parsers.hs @@ -64,8 +64,6 @@ data TextRenderInfo = TextRenderInfo { tColorsString :: String , tBoxes :: [Box] } deriving Show -type FontIndex = Int - type Segment = (Widget, TextRenderInfo, FontIndex, Maybe [Action]) -- | Runs the string parser diff --git a/src/Xmobar/X11/Boxes.hs b/src/Xmobar/X11/Boxes.hs index c0eeeed..87a081f 100644 --- a/src/Xmobar/X11/Boxes.hs +++ b/src/Xmobar/X11/Boxes.hs @@ -18,6 +18,10 @@ module Xmobar.X11.Boxes (boxLines, borderRect) where import Xmobar.Run.Parsers import Xmobar.Config.Types +-- | Computes the coordinates of a list of lines representing a Box. +-- The Box is to be positioned between x0 and x1, with height ht, and drawn +-- with line width lw. The returned lists are coordinates of the beginning +-- and end of each line. boxLines :: Box -> Double -> Double -> Double -> [(Double, Double, Double, Double)] boxLines (Box bd offset lw _ margins) ht x0 x1 = case bd of @@ -39,6 +43,7 @@ boxLines (Box bd offset lw _ margins) ht x0 x1 = rleft = (xmin, ymin + p0, xmin, ymax + p1) rright = (xmax, ymin + p0, xmax, ymax + p1) +-- | Computes the rectangle (x, y, width, height) for the given Border. borderRect :: Border -> Double -> Double -> (Double, Double, Double, Double) borderRect bdr w h = case bdr of diff --git a/src/Xmobar/X11/CairoDraw.hs b/src/Xmobar/X11/CairoDraw.hs index b90b2f8..b7ecd34 100644 --- a/src/Xmobar/X11/CairoDraw.hs +++ b/src/Xmobar/X11/CairoDraw.hs @@ -35,12 +35,10 @@ import qualified Graphics.Rendering.Pango as P import Xmobar.Run.Parsers (Segment , Widget(..) , Box (..) - , BoxMargins (..) - , BoxBorder (..) - , BoxOffset (..) , TextRenderInfo (..) , colorComponents) import Xmobar.Config.Types +import Xmobar.Config.Parse (indexedFont, indexedOffset) import Xmobar.Text.Pango (fixXft) import Xmobar.X11.Types import Xmobar.X11.Boxes (boxLines, borderRect) |