diff options
author | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-07-09 01:23:38 +0200 |
---|---|---|
committer | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-07-09 01:23:38 +0200 |
commit | 20c1f8de69ad714becc2b5e8adcfc0aab3cc50f7 (patch) | |
tree | 202675ac1c60f629411b48700dce04ac527a1372 /XMobar.hs | |
parent | b70f7796a04a92c581d81c426c4c3d236b76ee03 (diff) | |
download | xmobar-20c1f8de69ad714becc2b5e8adcfc0aab3cc50f7.tar.gz xmobar-20c1f8de69ad714becc2b5e8adcfc0aab3cc50f7.tar.bz2 |
added a short-hand for fromintegral (much used here)
darcs-hash:20070708232338-d6583-3341a03f0095304183638d4a7bdc038063952231.gz
Diffstat (limited to 'XMobar.hs')
-rw-r--r-- | XMobar.hs | 34 |
1 files changed, 19 insertions, 15 deletions
@@ -90,10 +90,10 @@ createWin config = let dflt = defaultScreen dpy rootw <- rootWindow dpy dflt win <- mkUnmanagedWindow dpy (defaultScreenOfDisplay dpy) rootw - (fromIntegral $ xPos config) - (fromIntegral $ yPos config) - (fromIntegral $ width config) - (fromIntegral $ height config) + (fi $ xPos config) + (fi $ yPos config) + (fi $ width config) + (fi $ height config) mapWindow dpy win return (dpy,win) @@ -113,22 +113,22 @@ drawInWin str = io $ setFont dpy gc (fontFromFontStruct fontst) -- create a pixmap to write to and fill it with a rectangle: p <- io $ createPixmap dpy win - (fromIntegral (width config)) - (fromIntegral (height config)) + (fi (width config)) + (fi (height config)) (defaultDepthOfScreen (defaultScreenOfDisplay dpy)) io $ setForeground dpy gc bgcolor io $ fillRectangle dpy p gc 0 0 - (fromIntegral $ width config) - (fromIntegral $ height config) + (fi $ width config) + (fi $ height config) -- write to the pixmap the new string: let strWithLenth = map (\(s,c) -> (s,c,textWidth fontst s)) str p' <- printStrings p gc fontst 1 strWithLenth -- copy the pixmap with the new string to the window. io $ copyArea dpy p' win gc - (fromIntegral (xPos config)) - (fromIntegral (yPos config)) - (fromIntegral (width config)) - (fromIntegral (height config)) 0 0 + (fi (xPos config)) + (fi (yPos config)) + (fi (width config)) + (fi (height config)) 0 0 -- free up everything (we do not want to leak memory!) io $ freeFont dpy fontst io $ freeGC dpy gc @@ -149,15 +149,15 @@ printStrings p gc fontst offs sl@((s,c,l):xs) = st <- get let (_,asc,_,_) = textExtents fontst s totSLen = foldr (\(_,_,len) -> (+) len) 0 sl - valign = (fromIntegral (height config) + fromIntegral asc) `div` 2 - remWidth = fromIntegral (width config) - fromIntegral totSLen + valign = (fi (height config) + fi asc) `div` 2 + remWidth = fi (width config) - fi totSLen offset = case (align config) of "center" -> (remWidth + offs) `div` 2 "right" -> remWidth - 1 "left" -> offs _ -> offs fgcolor <- io $ initColor (display st) c - bgcolor <- io $ initColor (display st) (bgColor config) + bgcolor <- io $ initColor (display st) (bgColor config) io $ setForeground (display st) gc fgcolor io $ setBackground (display st) gc bgcolor io $ drawImageString (display st) p gc offset valign s @@ -259,3 +259,7 @@ tenthSeconds s | s >= x = do threadDelay y | otherwise = threadDelay (s * 100000) where y = (maxBound :: Int) x = y `div` 100000 + +-- | Short-hand for 'fromIntegral' +fi :: (Integral a, Num b) => a -> b +fi = fromIntegral |