summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@ing.unitn.it>2007-07-24 14:51:20 +0200
committerAndrea Rossato <andrea.rossato@ing.unitn.it>2007-07-24 14:51:20 +0200
commit8f449586fcfc8f70603cf7017cf38d3d03e58d31 (patch)
tree69dd2a91b6f0488cd7e82d16192c395e6425e300
parentd15ff11f7021777e30a9d41cac0850b794a3d7e9 (diff)
downloadxmobar-8f449586fcfc8f70603cf7017cf38d3d03e58d31.tar.gz
xmobar-8f449586fcfc8f70603cf7017cf38d3d03e58d31.tar.bz2
if an invalid color name or value is given the black pixel will used instead
darcs-hash:20070724125120-d6583-c56837a2e85eb505ce2cc7d9462d5f4471afa302.gz
-rw-r--r--Xmobar.hs9
1 files changed, 7 insertions, 2 deletions
diff --git a/Xmobar.hs b/Xmobar.hs
index 853017d..7142a8d 100644
--- a/Xmobar.hs
+++ b/Xmobar.hs
@@ -255,9 +255,14 @@ mkUnmanagedWindow dpy scr rw x y w h = do
Utilities, aka stollen without givin' credit stuff.
-}
--- | Get the Pixel value for a named color
+-- | Get the Pixel value for a named color: if an invalid name is
+-- given the black pixel will be returned.
initColor :: Display -> String -> IO Pixel
-initColor dpy c = (color_pixel . fst) `liftM` allocNamedColor dpy colormap c
+initColor dpy c =
+ catch (initColor' dpy c) (const $ return $ blackPixel dpy (defaultScreen dpy))
+
+initColor' :: Display -> String -> IO Pixel
+initColor' dpy c = (color_pixel . fst) `liftM` allocNamedColor dpy colormap c
where colormap = defaultColormap dpy (defaultScreen dpy)
-- | Short-hand for lifting in the IO monad