diff options
-rw-r--r-- | readme.md | 8 | ||||
-rw-r--r-- | src/Bitmap.hs | 11 | ||||
-rw-r--r-- | src/Config.hs | 2 | ||||
-rw-r--r-- | src/Parsers.hs | 6 | ||||
-rw-r--r-- | src/Xmobar.hs | 2 |
5 files changed, 22 insertions, 7 deletions
@@ -319,6 +319,11 @@ Other configuration options: `borderWidth` : Border width in pixels. +`iconRoot` +: Root folder where icons are stored. For <icon=path/> + if path start with `"/"`, `"./"` or `"../"` it is interpreted as it is. + Otherwise it will have `iconRoot ++ "/"` prepended to it. Default is `"."`. + `commands` : For setting the options of the programs to run (optional). @@ -495,7 +500,8 @@ form: <icon=/path/to/bitmap.xbm/> which will produce the expected result. Accepted image formats are XBM -and XPM (when `with_xpm` flag is enabled). +and XPM (when `with_xpm` flag is enabled). If path does not start with +`"/"`, `"./"`, `"../"` it will have `iconRoot ++ "/"` prepended to it. It's also possible to use action directives of the form: diff --git a/src/Bitmap.hs b/src/Bitmap.hs index ff79262..63baf6a 100644 --- a/src/Bitmap.hs +++ b/src/Bitmap.hs @@ -23,6 +23,7 @@ import Control.Monad.Trans(MonadIO(..)) import Data.Map hiding (foldr, map, filter) import Graphics.X11.Xlib import System.Directory (doesFileExist) +import System.FilePath ((</>)) import System.Mem.Weak ( addFinalizer ) import ColorCache import Parsers (Widget(..)) @@ -41,15 +42,19 @@ data Bitmap = Bitmap { width :: Dimension , bitmapType :: BitmapType } -updateCache :: Display -> Window -> Map FilePath Bitmap -> +updateCache :: Display -> Window -> Map FilePath Bitmap -> FilePath -> [[(Widget, String, Maybe [Action])]] -> IO (Map FilePath Bitmap) -updateCache dpy win cache ps = do +updateCache dpy win cache iconRoot ps = do let paths = map (\(Icon p, _, _) -> p) . concatMap (filter icons) $ ps icons (Icon _, _, _) = True icons _ = False + expandPath path@('/':_) = path + expandPath path@('.':'/':_) = path + expandPath path@('.':'.':'/':_) = path + expandPath path = iconRoot </> path go m path = if member path m then return m - else do bitmap <- loadBitmap dpy win path + else do bitmap <- loadBitmap dpy win $ expandPath path return $ maybe m (\b -> insert path b m) bitmap foldM go cache paths diff --git a/src/Config.hs b/src/Config.hs index e7c25ad..3514e50 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -67,6 +67,7 @@ data Config = -- window stack on initialization , persistent :: Bool -- ^ Whether automatic hiding should -- be enabled or disabled + , iconRoot :: FilePath -- ^ Root folder for icons , commands :: [Runnable] -- ^ For setting the command, -- the command arguments -- and refresh rate for the programs @@ -118,6 +119,7 @@ defaultConfig = , allDesktops = True , overrideRedirect = True , pickBroadest = False + , iconRoot = "." , commands = [ Run $ Date "%a %b %_d %Y * %H:%M:%S" "theDate" 10 , Run StdinReader] , sepChar = "%" diff --git a/src/Parsers.hs b/src/Parsers.hs index 5e6f4d6..dceb4b7 100644 --- a/src/Parsers.hs +++ b/src/Parsers.hs @@ -201,14 +201,15 @@ parseConfig = runParser parseConf fields "Config" . stripComments <$?> pFont <|?> pBgColor <|?> pFgColor <|?> pPosition <|?> pBorder <|?> pBdColor <|?> pBdWidth <|?> pHideOnStart <|?> pAllDesktops <|?> pOverrideRedirect <|?> pPickBroadest - <|?> pLowerOnStart <|?> pPersistent + <|?> pLowerOnStart <|?> pPersistent <|?> pIconRoot <|?> pCommands <|?> pSepChar <|?> pAlignSep <|?> pTemplate fields = [ "font", "bgColor", "fgColor", "sepChar", "alignSep" , "border", "borderColor" ,"template", "position" , "allDesktops", "overrideRedirect", "pickBroadest" - , "hideOnStart", "lowerOnStart", "persistent", "commands" + , "hideOnStart", "lowerOnStart", "persistent", "iconRoot" + , "commands" ] pFont = strField font "font" @@ -228,6 +229,7 @@ parseConfig = runParser parseConf fields "Config" . stripComments pAllDesktops = readField allDesktops "allDesktops" pOverrideRedirect = readField overrideRedirect "overrideRedirect" pPickBroadest = readField pickBroadest "pickBroadest" + pIconRoot = readField iconRoot "iconRoot" pCommands = field commands "commands" readCommands diff --git a/src/Xmobar.hs b/src/Xmobar.hs index 91245e2..33feeb0 100644 --- a/src/Xmobar.hs +++ b/src/Xmobar.hs @@ -151,7 +151,7 @@ eventLoop tv xc@(XConf d r w fs is cfg) as signal = do case typ of Wakeup -> do str <- updateString cfg tv - xc' <- updateCache d w is str >>= \c -> return xc { iconS = c } + xc' <- updateCache d w is (iconRoot cfg) str >>= \c -> return xc { iconS = c } as' <- updateActions xc r str runX xc' $ drawInWin r str eventLoop tv xc' as' signal |