MyHelper.hs 2.87 KB
Newer Older
epsi sayidina's avatar
epsi sayidina committed
1 2 3 4
module MyHelper
( getMonitor
, getGeometry
, getDzen2Parameters
epsi sayidina's avatar
epsi sayidina committed
5 6
, getParamsTop
, getParamsBottom
epsi sayidina's avatar
epsi sayidina committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
) where

import System.Process
import System.IO
import System.Exit

import Control.Monad

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- helpers

getMonitor :: [String] -> Int
getMonitor args
  | length(args) > 0 = read (args !! 0) :: Int
  | otherwise        = 0

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- geometry calculation

getGeometry :: Int -> IO [Int]
getGeometry monitor = do 
    let args = ["monitor_rect", show(monitor)]

    (_, Just pipe_out, _, ph) <- 
        createProcess (proc "herbstclient" args)
        { std_out = CreatePipe } 
        
    raw <- hGetContents pipe_out   
    _ <- waitForProcess ph
    
    when (raw == "") $ do
        putStrLn $ "Invalid monitor " ++ show(monitor)
        exitSuccess

    let geometry = map (read::String->Int) (words raw)
    
    return geometry


-- geometry has the format X Y W H
data XYWH = XYWH String String String String

getTopPanelGeometry :: Int -> [Int] -> XYWH
getTopPanelGeometry 
    height geometry = XYWH 
                      (show (geometry !! 0))
                      (show (geometry !! 1))
                      (show (geometry !! 2))
                      (show height)

getBottomPanelGeometry :: Int -> [Int] -> XYWH
getBottomPanelGeometry 
    height geometry = XYWH 
epsi sayidina's avatar
epsi sayidina committed
60
                      (show ((geometry !! 0) + 0))
epsi sayidina's avatar
epsi sayidina committed
61
                      (show ((geometry !! 3) - height))
epsi sayidina's avatar
epsi sayidina committed
62
                      (show ((geometry !! 2) - 0))
epsi sayidina's avatar
epsi sayidina committed
63 64 65 66 67
                      (show height)

-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
-- dzen Parameters

epsi sayidina's avatar
epsi sayidina committed
68 69
getParamsTop :: Int -> [Int] -> [String]
getParamsTop
epsi sayidina's avatar
epsi sayidina committed
70 71 72 73 74 75
    panelHeight geometry = [
          "-x", xpos,  "-y", ypos,
          "-w", width, "-h", height,
          "-ta", "l",
          "-bg", bgcolor,
          "-fg", fgcolor,
epsi sayidina's avatar
epsi sayidina committed
76 77
          "-title-name", "dzentop",
          "-fn", font
epsi sayidina's avatar
epsi sayidina committed
78 79 80 81 82 83 84
        ]
      where
        XYWH xpos ypos width height = getTopPanelGeometry 
                                      panelHeight geometry        
        bgcolor = "#000000"
        fgcolor = "#ffffff"
        font    = "-*-takaopgothic-medium-*-*-*-12-*-*-*-*-*-*-*"
epsi sayidina's avatar
epsi sayidina committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

getParamsBottom :: Int -> [Int] -> [String]
getParamsBottom
    panelHeight geometry = [
          "-x", xpos,  "-y", ypos,
          "-w", width, "-h", height,
          "-ta", "l",
          "-bg", bgcolor,
          "-fg", fgcolor,
          "-title-name", "dzenbottom",
          "-fn", font
        ]
      where
        XYWH xpos ypos width height = getBottomPanelGeometry 
                                      panelHeight geometry        
        bgcolor = "#000000"
        fgcolor = "#ffffff"
        font    = "-*-fixed-medium-*-*-*-11-*-*-*-*-*-*-*"

getDzen2Parameters :: Int -> [Int] -> [String]
getDzen2Parameters panelHeight geometry = 
    getParamsTop panelHeight geometry