From cfd729999901c39f6e0aac1c271d56ae6e704d3e Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Mon, 21 Jan 2013 06:19:26 +1100 Subject: XBM icon support --- src/Xmobar.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/Xmobar.hs') diff --git a/src/Xmobar.hs b/src/Xmobar.hs index 5fc0cd4..7730620 100644 --- a/src/Xmobar.hs +++ b/src/Xmobar.hs @@ -231,12 +231,15 @@ updateWin v = do -- $print -- | Draws in and updates the window -drawInWin :: Rectangle -> [[(String, String)]] -> X () +drawInWin :: Rectangle -> [[(Widget, String)]] -> X () drawInWin (Rectangle _ _ wid ht) ~[left,center,right] = do r <- ask let (c,d ) = (config &&& display) r (w,fs) = (window &&& fontS ) r - strLn = io . mapM (\(s,cl) -> textWidth d fs s >>= \tw -> return (s,cl,fi tw)) + strLn = io . mapM getWidth + getWidth (Text s,cl) = textWidth d fs s >>= \tw -> return (Text s,cl,fi tw) + getWidth (Icon s,cl) = return (Icon s,cl,fi ht) + withColors d [bgColor c, borderColor c] $ \[bgcolor, bdcolor] -> do gc <- io $ createGC d w -- create a pixmap to write to and fill it with a rectangle @@ -261,11 +264,13 @@ drawInWin (Rectangle _ _ wid ht) ~[left,center,right] = do -- | An easy way to print the stuff we need to print printStrings :: Drawable -> GC -> XFont -> Position - -> Align -> [(String, String, Position)] -> X () + -> Align -> [(Widget, String, Position)] -> X () printStrings _ _ _ _ _ [] = return () printStrings dr gc fontst offs a sl@((s,c,l):xs) = do r <- ask - (as,ds) <- io $ textExtents fontst s + let fromWidget (Text t) = t + fromWidget (Icon t) = t + (as,ds) <- io $ textExtents fontst (fromWidget s) let (conf,d) = (config &&& display) r Rectangle _ _ wid ht = rect r totSLen = foldr (\(_,_,len) -> (+) len) 0 sl -- cgit v1.2.3