summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Xmobar/App/EventLoop.hs1
-rw-r--r--src/Xmobar/X11/Actions.hs2
-rw-r--r--src/Xmobar/X11/Draw.hs3
-rw-r--r--src/Xmobar/X11/Parsers.hs21
4 files changed, 20 insertions, 7 deletions
diff --git a/src/Xmobar/App/EventLoop.hs b/src/Xmobar/App/EventLoop.hs
index 4a0db46..474ff4f 100644
--- a/src/Xmobar/App/EventLoop.hs
+++ b/src/Xmobar/App/EventLoop.hs
@@ -265,6 +265,7 @@ updateActions conf (Rectangle _ _ wid _) ~[left,center,right] = do
iconW i = maybe 0 Bitmap.width (lookup i $ iconS conf)
getCoords (Text s,_,i,a) = textWidth d (safeIndex fs i) s >>= \tw -> return (a, 0, fi tw)
getCoords (Icon s,_,_,a) = return (a, 0, fi $ iconW s)
+ getCoords (Hspace w,_,_,a) = return (a, 0, fi w)
partCoord off xs = map (\(a, x, x') -> (fromJust a, x, x')) $
filter (\(a, _,_) -> isJust a) $
scanl (\(_,_,x') (a,_,w') -> (a, x', x' + w'))
diff --git a/src/Xmobar/X11/Actions.hs b/src/Xmobar/X11/Actions.hs
index 03e58ad..87c03ed 100644
--- a/src/Xmobar/X11/Actions.hs
+++ b/src/Xmobar/X11/Actions.hs
@@ -18,7 +18,7 @@ import Text.Regex (Regex, subRegex, mkRegex, matchRegex)
import Graphics.X11.Types (Button)
data Action = Spawn [Button] String
- deriving (Eq)
+ deriving (Eq, Show)
runAction :: Action -> IO ()
runAction (Spawn _ s) = void $ system (s ++ "&")
diff --git a/src/Xmobar/X11/Draw.hs b/src/Xmobar/X11/Draw.hs
index 6044eff..1b3d4ee 100644
--- a/src/Xmobar/X11/Draw.hs
+++ b/src/Xmobar/X11/Draw.hs
@@ -60,6 +60,7 @@ drawInWin wr@(Rectangle _ _ wid ht) ~[left,center,right] = do
getWidth (Text s,cl,i,_) =
textWidth d (safeIndex fs i) s >>= \tw -> return (Text s,cl,i,fi tw)
getWidth (Icon s,cl,i,_) = return (Icon s,cl,i,fi $ iconW s)
+ getWidth (Hspace p,cl,i,_) = return (Hspace p,cl,i,fi p)
p <- liftIO $ createPixmap d w wid ht
(defaultDepthOfScreen (defaultScreenOfDisplay d))
@@ -102,6 +103,7 @@ verticalOffset ht (Text t) fontst voffs _
verticalOffset ht (Icon _) _ _ conf
| iconOffset conf > -1 = return $ fi (iconOffset conf)
| otherwise = return $ fi (ht `div` 2) - 1
+verticalOffset _ (Hspace _) _ voffs _ = return $ fi voffs
printString :: Display -> Drawable -> XFont -> GC -> String -> String
-> Position -> Position -> Position -> Position -> String -> Int -> IO ()
@@ -160,6 +162,7 @@ printStrings dr gc fontlist voffs offs a boxes sl@((s,c,i,l):xs) = do
(Icon p) -> liftIO $ maybe (return ())
(B.drawBitmap d dr gc fc bc offset valign)
(lookup p (iconS r))
+ (Hspace _) -> liftIO $ return ()
let triBoxes = tBoxes c
dropBoxes = filter (\(_,b) -> b `notElem` triBoxes) boxes
boxes' = map (\((x1,_),b) -> ((x1, offset + l), b)) (filter (\(_,b) -> b `elem` triBoxes) boxes)
diff --git a/src/Xmobar/X11/Parsers.hs b/src/Xmobar/X11/Parsers.hs
index d35cfa0..513f63b 100644
--- a/src/Xmobar/X11/Parsers.hs
+++ b/src/Xmobar/X11/Parsers.hs
@@ -28,11 +28,11 @@ import Text.Read (readMaybe)
import Graphics.X11.Types (Button)
import Foreign.C.Types (CInt)
-data Widget = Icon String | Text String
+data Widget = Icon String | Text String | Hspace Int32 deriving Show
-data BoxOffset = BoxOffset Align Int32 deriving Eq
+data BoxOffset = BoxOffset Align Int32 deriving (Eq, Show)
-- margins: Top, Right, Bottom, Left
-data BoxMargins = BoxMargins Int32 Int32 Int32 Int32 deriving Eq
+data BoxMargins = BoxMargins Int32 Int32 Int32 Int32 deriving (Eq, Show)
data BoxBorder = BBTop
| BBBottom
| BBVBoth
@@ -40,14 +40,14 @@ data BoxBorder = BBTop
| BBRight
| BBHBoth
| BBFull
- deriving ( Read, Eq )
-data Box = Box BoxBorder BoxOffset CInt String BoxMargins deriving Eq
+ deriving ( Read, Eq, Show )
+data Box = Box BoxBorder BoxOffset CInt String BoxMargins deriving (Eq, Show)
data TextRenderInfo =
TextRenderInfo { tColorsString :: String
, tBgTopOffset :: Int32
, tBgBottomOffset :: Int32
, tBoxes :: [Box]
- }
+ } deriving Show
type FontIndex = Int
-- | Runs the string parser
@@ -68,6 +68,7 @@ allParsers :: TextRenderInfo
-> Parser [(Widget, TextRenderInfo, FontIndex, Maybe [Action])]
allParsers c f a = textParser c f a
<|> try (iconParser c f a)
+ <|> try (hspaceParser c f a)
<|> try (rawParser c f a)
<|> try (actionParser c f a)
<|> try (fontParser c a)
@@ -91,6 +92,7 @@ textParser c f a = do s <- many1 $
try (string "action=") <|>
try (string "/action>") <|>
try (string "icon=") <|>
+ try (string "hspace=") <|>
try (string "raw=") <|>
try (string "/fn>") <|>
try (string "/box>") <|>
@@ -133,6 +135,13 @@ iconParser c f a = do
i <- manyTill (noneOf ">") (try (string "/>"))
return [(Icon i, c, f, a)]
+hspaceParser :: TextRenderInfo -> FontIndex -> Maybe [Action]
+ -> Parser [(Widget, TextRenderInfo, FontIndex, Maybe [Action])]
+hspaceParser c f a = do
+ string "<hspace="
+ pVal <- manyTill digit (try (string "/>"))
+ return [(Hspace (fromMaybe 0 $ readMaybe pVal), c, f, a)]
+
actionParser :: TextRenderInfo -> FontIndex -> Maybe [Action]
-> Parser [(Widget, TextRenderInfo, FontIndex, Maybe [Action])]
actionParser c f act = do