Skip to content

Commit

Permalink
Make some imports more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
dylex committed Oct 25, 2017
1 parent 6beb01b commit 27eb179
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
43 changes: 22 additions & 21 deletions lib/Pager.hs
Expand Up @@ -2,18 +2,19 @@ module Pager
( pagerStart
) where

import XMonad as X
import qualified XMonad.StackSet as W
import XMonad.Util.NamedWindows
import Control.Monad
import Data.List
import Control.Monad (mapAndUnzipM)
import Data.List (find, transpose)
import qualified Data.Map as Map
import Data.Maybe
import System.IO
import Util
import Param
import Server
import Dzen
import Data.Maybe (fromJust)
import System.IO (Handle, hPutStrLn, hFlush)
import qualified XMonad as X
import qualified XMonad.StackSet as W
import XMonad.Util.NamedWindows (getName)

import Util
import Param
import Server
import Dzen

fontSize :: Int
fontSize = 8
Expand All @@ -33,13 +34,13 @@ dzenArgs = dzenDefaultArgs ++
data StackPos = Up | Focus | Down deriving (Eq, Ord)

data WinInfo = WinInfo
{ win :: Window
{ win :: X.Window
, winName :: String
, winPos :: !StackPos
, winFloat :: !Bool
}

getWinInfo :: WindowSet -> WindowSpace -> StackPos -> Window -> X WinInfo
getWinInfo :: X.WindowSet -> X.WindowSpace -> StackPos -> X.Window -> X.X WinInfo
getWinInfo set _ws p w = do
n <- show =.< getName w
return WinInfo
Expand All @@ -49,14 +50,14 @@ getWinInfo set _ws p w = do
, winFloat = w `Map.member` W.floating set
}

getWinList :: WindowSet -> WindowSpace -> X [WinInfo]
getWinList :: X.WindowSet -> X.WindowSpace -> X.X [WinInfo]
getWinList _ (W.Workspace{ W.stack = Nothing }) = return []
getWinList set ws@(W.Workspace{ W.stack = Just (W.Stack f u d) }) = mapM (uncurry $ getWinInfo set ws) $ (Focus,f) : map ((,) Up) u ++ map ((,) Down) d

winInfo :: WinInfo -> Int -> String
winInfo w l = dzenClickArea 3 ServerCommandWindowMenu [ii $ win w] $ take l $ winName w

deskInfo :: WindowSet -> Desktop -> WindowSpace -> X (String, [String])
deskInfo :: X.WindowSet -> Desktop -> X.WindowSpace -> X.X (String, [String])
deskInfo set d = wins >=. \(wm:wl) -> (line True wm, map (line False) wl) where
line top w =
(if cur then "pa"^/show (i*pagerDeskWidth) ++ "fg"^/"#404080" ++ "r"^/(show pagerDeskWidth ++ "x" ++ show fontSize) else "")
Expand All @@ -73,12 +74,12 @@ deskInfo set d = wins >=. \(wm:wl) -> (line True wm, map (line False) wl) where
| cur = "#408040"
| otherwise = "#004000"
wins ws@(W.Workspace{ W.stack = Just _ }) = getWinList set ws
wins _ = asks theRoot >.= \r -> [WinInfo r tag Down False]
wins _ = X.asks X.theRoot >.= \r -> [WinInfo r tag Down False]
cur = tag == W.currentTag set
tag = show d
i = fromEnum d

iconInfo :: WindowSet -> WindowSpace -> X String
iconInfo :: X.WindowSet -> X.WindowSpace -> X.X String
iconInfo set ws = unwords . map icon =.< getWinList set ws where
icon w =
"fg"^/(if winPos w == Focus then "#FFFFC0" else "#C0C0F0")
Expand All @@ -87,19 +88,19 @@ iconInfo set ws = unwords . map icon =.< getWinList set ws where
(winInfo w 60)
++ "ib"^/"1"

pagerLog :: Handle -> X ()
pagerLog :: Handle -> X.X ()
pagerLog h = do
s <- gets windowset
s <- X.gets X.windowset
let ws = W.workspaces s
fd i = fromJust $ find ((i ==) . W.tag) ws
(tl,bll) <- mapAndUnzipM (\i -> deskInfo s i $ fd $ show i) desktops
il <- iconInfo s (fd $ show iconDesktop)
io $ do
X.io $ do
hPutStrLn h $ "^cs()\n^tw()"
++ concat tl
++ '\n' : unlines (map concat (transpose bll))
++ "bg"^/"#400000" ++ il
hFlush h

pagerStart :: IO (X ())
pagerStart :: IO (X.X ())
pagerStart = pagerLog =.< runDzen dzenArgs
37 changes: 20 additions & 17 deletions lib/Param.hs
Expand Up @@ -14,18 +14,20 @@ module Param
, isFont
) where

import XMonad as X hiding (terminal)
import Control.Exception (catch, IOException)
import Data.Ix
import Data.Maybe
import Control.Exception (catch, IOException)
import Data.Ix (Ix)
import Data.List (isPrefixOf)
import Data.Maybe (isJust)
import qualified System.Directory
import System.Environment
import System.IO.Unsafe
import System.Posix.Unistd
import Util
import System.Environment (getEnv)
import System.IO.Unsafe (unsafeDupablePerformIO)
import System.Posix.Unistd (SystemID, getSystemID, systemName, nodeName)
import qualified XMonad as X

import Util

systemID :: SystemID
systemID = unsafePerformIO getSystemID
systemID = unsafeDupablePerformIO getSystemID

osName :: String
osName = systemName systemID
Expand All @@ -37,7 +39,7 @@ hostHome :: Bool
hostHome = hostName == "datura"

home :: String
home = unsafePerformIO $ getEnv "HOME"
home = unsafeDupablePerformIO $ getEnv "HOME"

newtype Desktop = Desktop { _unDesktop :: Int } deriving (Eq, Ord, Enum, Ix)

Expand All @@ -63,25 +65,26 @@ instance Read Desktop where
topHeight :: Int
topHeight = 50

wmod :: KeyMask
wmod = mod4Mask -- mod1Mask
wmod :: X.KeyMask
wmod = X.mod4Mask -- mod1Mask

type COLOR = String

colorRootFG :: COLOR
colorRootFG = "#FFFFBB"

pagerDeskWidth :: Int
pagerDeskWidth = 75
pagerDeskWidth | hdpi = 140
| otherwise = 75

pagerWidth :: Int
pagerWidth = pagerDeskWidth*length desktops

isExec :: String -> Bool
isExec = unsafePerformIO . (isJust .=< System.Directory.findExecutable)
isExec = unsafeDupablePerformIO . (isJust .=< System.Directory.findExecutable)

isFont :: String -> X Bool
isFont f = withDisplay $ \dpy -> io $ catch
(loadQueryFont dpy f >>= freeFont dpy >. True)
isFont :: String -> X.X Bool
isFont f = X.withDisplay $ \dpy -> X.io $ catch
(X.loadQueryFont dpy f >>= X.freeFont dpy >. True)
(\(_ :: IOException) -> return False)

29 changes: 15 additions & 14 deletions lib/Program.hs
Expand Up @@ -9,12 +9,13 @@ module Program
, mixerSet
) where

import XMonad as X hiding (terminal)
import Data.Maybe
import System.FilePath
import Util
import Param
import Ops
import Data.Maybe (maybeToList)
import System.FilePath ((</>))
import qualified XMonad as X

import Util
import Param
import Ops

data Term = Term
{ terminal :: String
Expand All @@ -31,27 +32,27 @@ term = Term
, termRun = Nothing
}

runTerm :: MonadIO m => Term -> m ()
runTerm :: X.MonadIO m => Term -> m ()
runTerm t = run $ Run (terminal t) $
maybe [] (\n -> ["-title",n]) (termTitle t)
++ (if termHold t then ["-hold","1"] else [])
++ maybe [] (("-e":) . unRun) (termRun t)

notify :: MonadIO m => String -> m ()
notify = io . runInput (Run "xmessage" ["-file","-"])
notify :: X.MonadIO m => String -> m ()
notify = X.io . runInput (Run "xmessage" ["-file","-"])

identWindow :: Window -> X ()
identWindow w = io $ runOutput (Run "xprop" ["-id",show w]) >>= notify
identWindow :: X.Window -> X.X ()
identWindow w = X.io $ runOutput (Run "xprop" ["-id",show w]) >>= notify

browser :: String
browser
| isExec "uzbl" = "uzbl"
| otherwise = "firefox"

runBrowser :: Maybe String -> X ()
runBrowser :: Maybe String -> X.X ()
runBrowser = run . Run browser . maybeToList

runLogin :: String -> X ()
runLogin :: String -> X.X ()
runLogin h = runTerm $ term{ termTitle = Just h, termRun = Just (RunShell ("ssh " ++ h)) }

startups :: [(String, Run)]
Expand Down Expand Up @@ -98,7 +99,7 @@ programs = startups
| isExec p = [(p, Run p a)]
| otherwise = []

mixerSet :: MonadIO m => Ordering -> Int -> m ()
mixerSet :: X.MonadIO m => Ordering -> Int -> m ()
mixerSet d n
| osName == "Linux" = run $ Run "amixer" ["-q","-D","main","set",if hostHome then "Wave" else "Master","playback",show n ++ dirSign d]
| osName == "FreeBSD" = run $ Run "/usr/sbin/mixer" [if hostName == "druid" then "ogain" else "vol",dirSign d ++ show n]
Expand Down

0 comments on commit 27eb179

Please sign in to comment.