summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-07-12 14:41:25 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-07-12 14:41:25 +0200
commit6de4eb5792d88a70eaf9cc19784371a9a0eaba43 (patch)
tree9ab92e2c3e29b16131a237be932a5338b292d97e
parentc918dde366a02ed4de26ea0c5e07a153d8f902bb (diff)
downloadphi-6de4eb5792d88a70eaf9cc19784371a9a0eaba43.tar
phi-6de4eb5792d88a70eaf9cc19784371a9a0eaba43.zip
Simplify struts generation
-rw-r--r--lib/Phi/Panel.hs5
-rw-r--r--lib/Phi/X11.hs55
-rw-r--r--src/Phi.hs2
3 files changed, 26 insertions, 36 deletions
diff --git a/lib/Phi/Panel.hs b/lib/Phi/Panel.hs
index 23b022f..42f4f98 100644
--- a/lib/Phi/Panel.hs
+++ b/lib/Phi/Panel.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE ExistentialQuantification #-}
-module Phi.Panel ( Panel(..)
+module Phi.Panel ( Position(..)
+ , Panel(..)
, PanelClass(..)
, (<~>)
, separator
@@ -8,6 +9,8 @@ module Phi.Panel ( Panel(..)
import Data.Function
+data Position = Top | Bottom
+
class PanelClass a where
minSize :: a -> Int
diff --git a/lib/Phi/X11.hs b/lib/Phi/X11.hs
index 06bebfa..129e00e 100644
--- a/lib/Phi/X11.hs
+++ b/lib/Phi/X11.hs
@@ -1,7 +1,6 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-module Phi.X11 ( PanelPosition(..)
- , PhiXConfig(..)
+module Phi.X11 ( PhiXConfig(..)
, phiDefaultXConfig
, initPhi
) where
@@ -17,10 +16,10 @@ import Data.Bits
import Control.Monad.State
import Control.Monad.Trans
-data PanelPosition = PanelPositionTop | PanelPositionBottom
+import qualified Phi.Panel as Panel
data PhiXConfig = PhiXConfig { phiXScreenInfo :: Display -> IO [Rectangle]
- , phiPanelPosition :: PanelPosition
+ , phiPanelPosition :: Panel.Position
, phiPanelSize :: Int
}
@@ -44,7 +43,7 @@ runPhi st (Phi a) = runStateT a st
phiDefaultXConfig = PhiXConfig { phiXScreenInfo = getScreenInfo
- , phiPanelPosition = PanelPositionTop
+ , phiPanelPosition = Panel.Top
, phiPanelSize = 24
}
@@ -184,33 +183,21 @@ setStruts panel = do
area = panelArea panel
(_, _, _, _, rootHeight, _, _) <- liftIO $ getGeometry disp rootwin
- let struts = case position of
- PanelPositionTop -> [ 0
- , 0
- , (fromIntegral $ rect_y area) + (fromIntegral $ rect_height area)
- , 0
- , 0
- , 0
- , 0
- , 0
- , (fromIntegral $ rect_x area)
- , (fromIntegral $ rect_x area) + (fromIntegral $ rect_width area) - 1
- , 0
- , 0
- ]
- PanelPositionBottom -> [ 0
- , 0
- , 0
- , (fromIntegral rootHeight) - (fromIntegral $ rect_y area)
- , 0
- , 0
- , 0
- , 0
- , 0
- , 0
- , (fromIntegral $ rect_x area)
- , (fromIntegral $ rect_x area) + (fromIntegral $ rect_width area) - 1
- ]
+ let struts = [makeStruts i | i <- [0..11]]
+ where
+ makeTopStruts 2 = (fromIntegral $ rect_y area) + (fromIntegral $ rect_height area)
+ makeTopStruts 8 = (fromIntegral $ rect_x area)
+ makeTopStruts 9 = (fromIntegral $ rect_x area) + (fromIntegral $ rect_width area) - 1
+ makeTopStruts _ = 0
+
+ makeBottomStruts 3 = (fromIntegral rootHeight) - (fromIntegral $ rect_y area)
+ makeBottomStruts 10 = (fromIntegral $ rect_x area)
+ makeBottomStruts 11 = (fromIntegral $ rect_x area) + (fromIntegral $ rect_width area) - 1
+ makeBottomStruts _ = 0
+
+ makeStruts = case position of
+ Panel.Top -> makeTopStruts
+ Panel.Bottom -> makeBottomStruts
liftIO $ do
atom_NET_WM_STRUT <- internAtom disp "_NET_WM_STRUT" False
@@ -222,8 +209,8 @@ setStruts panel = do
panelBounds :: PhiXConfig -> Rectangle -> Rectangle
panelBounds config screenBounds = case phiPanelPosition config of
- PanelPositionTop -> screenBounds { rect_height = fromIntegral $ phiPanelSize config }
- PanelPositionBottom -> screenBounds { rect_height = fromIntegral $ phiPanelSize config,
+ Panel.Top -> screenBounds { rect_height = fromIntegral $ phiPanelSize config }
+ Panel.Bottom -> screenBounds { rect_height = fromIntegral $ phiPanelSize config,
rect_y = (rect_y screenBounds) + (fromIntegral $ rect_height screenBounds) - (fromIntegral $ phiPanelSize config) }
withRectangle :: Rectangle -> (Position -> Position -> Dimension -> Dimension -> a) -> a
diff --git a/src/Phi.hs b/src/Phi.hs
index 9aa6ad0..a3bc84e 100644
--- a/src/Phi.hs
+++ b/src/Phi.hs
@@ -3,4 +3,4 @@ import Phi.X11
main :: IO ()
main = do
- initPhi phiDefaultXConfig { phiPanelPosition = PanelPositionBottom } \ No newline at end of file
+ initPhi phiDefaultXConfig { phiPanelPosition = Bottom }