summaryrefslogtreecommitdiffhomepage
path: root/Xmobar.hs
diff options
context:
space:
mode:
authornzeh <nzeh@cs.dal.ca>2009-03-24 01:11:23 +0100
committernzeh <nzeh@cs.dal.ca>2009-03-24 01:11:23 +0100
commit530371201a18e497e5ad328c14b93d78bc2017cc (patch)
treead7f3553dd8a03d1756e82502fc3a28afc2e03a2 /Xmobar.hs
parent062b6e457f7e90389a18aef234c3b49373b7eb76 (diff)
downloadxmobar-530371201a18e497e5ad328c14b93d78bc2017cc.tar.gz
xmobar-530371201a18e497e5ad328c14b93d78bc2017cc.tar.bz2
Fix colour allocation leak
darcs-hash:20090324001123-c6b6b-8d31153a5794e56f7abd251bcafa8aa2676193c2.gz
Diffstat (limited to 'Xmobar.hs')
-rw-r--r--Xmobar.hs38
1 files changed, 19 insertions, 19 deletions
diff --git a/Xmobar.hs b/Xmobar.hs
index 823abc4..d3c252d 100644
--- a/Xmobar.hs
+++ b/Xmobar.hs
@@ -233,25 +233,25 @@ drawInWin (Rectangle _ _ wid ht) ~[left,center,right] = do
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))
- bgcolor <- io $ initColor d $ bgColor c
- gc <- io $ createGC d w
- -- create a pixmap to write to and fill it with a rectangle
- p <- io $ createPixmap d w wid ht
- (defaultDepthOfScreen (defaultScreenOfDisplay d))
- -- the fgcolor of the rectangle will be the bgcolor of the window
- io $ setForeground d gc bgcolor
- io $ fillRectangle d p gc 0 0 wid ht
- -- write to the pixmap the new string
- printStrings p gc fs 1 L =<< strLn left
- printStrings p gc fs 1 R =<< strLn right
- printStrings p gc fs 1 C =<< strLn center
- -- copy the pixmap with the new string to the window
- io $ copyArea d p w gc 0 0 wid ht 0 0
- -- free up everything (we do not want to leak memory!)
- io $ freeGC d gc
- io $ freePixmap d p
- -- resync
- io $ sync d True
+ withColors d [bgColor c] $ \[bgcolor] -> do
+ gc <- io $ createGC d w
+ -- create a pixmap to write to and fill it with a rectangle
+ p <- io $ createPixmap d w wid ht
+ (defaultDepthOfScreen (defaultScreenOfDisplay d))
+ -- the fgcolor of the rectangle will be the bgcolor of the window
+ io $ setForeground d gc bgcolor
+ io $ fillRectangle d p gc 0 0 wid ht
+ -- write to the pixmap the new string
+ printStrings p gc fs 1 L =<< strLn left
+ printStrings p gc fs 1 R =<< strLn right
+ printStrings p gc fs 1 C =<< strLn center
+ -- copy the pixmap with the new string to the window
+ io $ copyArea d p w gc 0 0 wid ht 0 0
+ -- free up everything (we do not want to leak memory!)
+ io $ freeGC d gc
+ io $ freePixmap d p
+ -- resync
+ io $ sync d True
-- | An easy way to print the stuff we need to print
printStrings :: Drawable -> GC -> XFont -> Position