From 31a5a5821b8a313823e47001d473a711bccb0914 Mon Sep 17 00:00:00 2001 From: Andrea Rossato Date: Sun, 4 Nov 2007 18:45:51 +0100 Subject: A new implementation of the position configuration option WARNING: this patch breaks previous configuration files. A new implementation of the position configuration option: - Top and Bottom have non arguments - TopW and BottomW have now 2 arguments: Align (L, C or R) and Int - setting a width % greater than 100 means a 100% width darcs-hash:20071104174551-d6583-adff505bf3929926554595180b8da1c7a0f9d0a5.gz --- Config.hs | 7 ++++--- Plugins/helloworld.config | 2 +- Xmobar.hs | 28 +++++++++++++--------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Config.hs b/Config.hs index aff4db6..4a566c6 100644 --- a/Config.hs +++ b/Config.hs @@ -15,7 +15,7 @@ module Config ( -- * Configuration -- $config Config (..) - , XPosition (..), Width (..) + , XPosition (..), Align (..) , defaultConfig , runnableTypes ) where @@ -44,8 +44,9 @@ data Config = , template :: String -- ^ The output template } deriving (Read) -data XPosition = Top | TopW Width | Bottom | BottomW Width | Static {xpos, ypos, width, height :: Int} deriving ( Read, Eq ) -data Width = L Int | R Int | C Int deriving ( Read, Eq ) +data XPosition = Top | TopW Align Int | Bottom | BottomW Align Int | Static {xpos, ypos, width, height :: Int} deriving ( Read, Eq ) + +data Align = L | R | C deriving ( Read, Eq ) -- | The default configuration values defaultConfig :: Config diff --git a/Plugins/helloworld.config b/Plugins/helloworld.config index 84fff35..3818bfa 100644 --- a/Plugins/helloworld.config +++ b/Plugins/helloworld.config @@ -1,7 +1,7 @@ Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*" , bgColor = "#000000" , fgColor = "#BFBFBF" - , position = TopW (C 50) + , position = TopW C 90 , commands = [ Run Cpu [] 10 , Run Weather "LIPB" [] 36000 , Run HelloWorld diff --git a/Xmobar.hs b/Xmobar.hs index 4545dcd..0b541f8 100644 --- a/Xmobar.hs +++ b/Xmobar.hs @@ -145,20 +145,20 @@ setPosition :: XPosition -> Rectangle -> Dimension -> (Position,Position,Dimensi setPosition p (Rectangle rx ry rw rh) ht = case p of Top -> (rx , ry , rw , h , True) - TopW (L i) -> (rx , ry , nw i , h , True) - TopW (R i) -> (right i, ry , nw i , h , True) - TopW (C i) -> (center i, ry , nw i , h , True) + TopW L i -> (rx , ry , nw i , h , True) + TopW R i -> (right i, ry , nw i , h , True) + TopW C i -> (center i, ry , nw i , h , True) Bottom -> (rx , ny , rw , h , True) - BottomW (L i) -> (rx , ny , nw i , h , True) - BottomW (R i) -> (right i, ny , nw i , h , True) - BottomW (C i) -> (center i, ny , nw i , h , True) + BottomW L i -> (rx , ny , nw i , h , True) + BottomW R i -> (right i, ny , nw i , h , True) + BottomW C i -> (center i, ny , nw i , h , True) Static cx cy cw ch -> (fi cx , fi cy , fi cw, fi ch, True) where ny = ry + fi (rh - ht) center i = rx + (fi $ div (remwid i) 2) right i = rx + (fi $ remwid i) remwid i = rw - pw (fi i) - pw i = rw * i `div` 100 + pw i = rw * (min 100 i) `div` 100 nw = fi . pw . fi h = fi ht @@ -198,8 +198,6 @@ updateWin v = do -- $print -data Align = Ce | Le | Ri - -- | Draws in and updates the window drawInWin :: Rectangle -> [[(String, String)]] -> X () drawInWin (Rectangle _ _ wid ht) ~[left,center,right] = do @@ -218,9 +216,9 @@ drawInWin (Rectangle _ _ wid ht) ~[left,center,right] = do io $ fillRectangle d p gc 0 0 wid ht -- write to the pixmap the new string let strWithLenth = map (\(s,cl) -> (s,cl,textWidth fs s)) - printStrings p gc fs 1 Le $ strWithLenth left - printStrings p gc fs 1 Ri $ strWithLenth right - printStrings p gc fs 1 Ce $ strWithLenth center + printStrings p gc fs 1 L $ strWithLenth left + printStrings p gc fs 1 R $ strWithLenth right + printStrings p gc fs 1 C $ strWithLenth 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!) @@ -242,9 +240,9 @@ printStrings dr gc fontst offs a sl@((s,c,l):xs) = do valign = (fi ht + fi as - fi ds) `div` 2 remWidth = fi wid - fi totSLen offset = case a of - Ce -> (remWidth + offs) `div` 2 - Ri -> remWidth - 1 - Le -> offs + C -> (remWidth + offs) `div` 2 + R -> remWidth - 1 + L -> offs (fc,bc) <- case (break (==',') c) of (f,',':b) -> do fgc <- io $ initColor d f -- cgit v1.2.3