diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Config.hs | 4 | ||||
-rw-r--r-- | src/Parsers.hs | 4 | ||||
-rw-r--r-- | src/Xmobar.hs | 42 |
3 files changed, 34 insertions, 16 deletions
diff --git a/src/Config.hs b/src/Config.hs index 3514e50..7e43e92 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -52,6 +52,8 @@ data Config = , bgColor :: String -- ^ Backgroud color , fgColor :: String -- ^ Default font color , position :: XPosition -- ^ Top Bottom or Static + , textOffset :: Int -- ^ Offset from top of window for text + , iconOffset :: Int -- ^ Offset from top of window for icons , border :: Border -- ^ NoBorder TopB BottomB or FullB , borderColor :: String -- ^ Border color , borderWidth :: Int -- ^ Border width @@ -113,6 +115,8 @@ defaultConfig = , border = NoBorder , borderColor = "#BFBFBF" , borderWidth = 1 + , textOffset = -1 + , iconOffset = -1 , hideOnStart = False , lowerOnStart = True , persistent = False diff --git a/src/Parsers.hs b/src/Parsers.hs index dceb4b7..cdc180d 100644 --- a/src/Parsers.hs +++ b/src/Parsers.hs @@ -199,6 +199,7 @@ parseConfig = runParser parseConf fields "Config" . stripComments perms = permute $ Config <$?> pFont <|?> pBgColor <|?> pFgColor <|?> pPosition + <|?> pTextOffset <|?> pIconOffset <|?> pBorder <|?> pBdColor <|?> pBdWidth <|?> pHideOnStart <|?> pAllDesktops <|?> pOverrideRedirect <|?> pPickBroadest <|?> pLowerOnStart <|?> pPersistent <|?> pIconRoot @@ -207,6 +208,7 @@ parseConfig = runParser parseConf fields "Config" . stripComments fields = [ "font", "bgColor", "fgColor", "sepChar", "alignSep" , "border", "borderColor" ,"template", "position" + , "textOffset", "iconOffset" , "allDesktops", "overrideRedirect", "pickBroadest" , "hideOnStart", "lowerOnStart", "persistent", "iconRoot" , "commands" @@ -220,6 +222,8 @@ parseConfig = runParser parseConf fields "Config" . stripComments pAlignSep = strField alignSep "alignSep" pTemplate = strField template "template" + pTextOffset = readField textOffset "textOffset" + pIconOffset = readField iconOffset "iconOffset" pPosition = readField position "position" pHideOnStart = readField hideOnStart "hideOnStart" pLowerOnStart = readField lowerOnStart "lowerOnStart" diff --git a/src/Xmobar.hs b/src/Xmobar.hs index 766b2fe..459d6ef 100644 --- a/src/Xmobar.hs +++ b/src/Xmobar.hs @@ -305,29 +305,39 @@ drawInWin (Rectangle _ _ wid ht) ~[left,center,right] = do -- resync io $ sync d True +verticalOffset :: (Integral b, Integral a, MonadIO m) => + a -> Widget -> XFont -> Config -> m b +verticalOffset ht (Text t) fontst conf + | textOffset conf > -1 = return $ fi (textOffset conf) + | otherwise = do + (as,ds) <- io $ textExtents fontst t + let bwidth = borderOffset (border conf) (borderWidth conf) + verticalMargin = (fi ht) - fi (as + ds) - 2 * fi (abs bwidth) + return $ (fi ht) - (fi ds) - (verticalMargin `div` 2) + bwidth + 1 +verticalOffset _ (Icon _) _ conf + | iconOffset conf > -1 = return $ fi (iconOffset conf) + | otherwise = do + let bwidth = borderOffset (border conf) (borderWidth conf) + return $ bwidth + 1 + -- | An easy way to print the stuff we need to print printStrings :: Drawable -> GC -> XFont -> Position -> Align -> [(Widget, String, Position)] -> X () printStrings _ _ _ _ _ [] = return () printStrings dr gc fontst offs a sl@((s,c,l):xs) = do r <- ask - (as,ds) <- case s of - Text t -> io $ textExtents fontst t - Icon _ -> return (0, 0) - let (conf,d) = (config &&& display) r - boffs = borderOffset (border conf) (borderWidth conf) + let (conf,d) = (config &&& display) r Rectangle _ _ wid ht = rect r - totSLen = foldr (\(_,_,len) -> (+) len) 0 sl - verticalMargin = (fi ht) - fi (as + ds) + boffs - valign = (fi ht) - (fi ds) - (verticalMargin `div` 2) - remWidth = fi wid - fi totSLen - offset = case a of - C -> (remWidth + offs) `div` 2 - R -> remWidth - L -> offs - (fc,bc) = case break (==',') c of - (f,',':b) -> (f, b ) - (f, _) -> (f, bgColor conf) + totSLen = foldr (\(_,_,len) -> (+) len) 0 sl + remWidth = fi wid - fi totSLen + offset = case a of + C -> (remWidth + offs) `div` 2 + R -> remWidth + L -> offs + (fc,bc) = case break (==',') c of + (f,',':b) -> (f, b ) + (f, _) -> (f, bgColor conf) + valign <- verticalOffset ht s fontst conf case s of (Text t) -> io $ printString d dr fontst gc fc bc offset valign t (Icon p) -> io $ maybe (return ()) (drawBitmap d dr gc fc bc offset valign) (lookup p (iconS r)) |