From 01ef9a6549e6de63384f2e597804c11f0d837455 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 25 Nov 2018 22:46:50 +0000 Subject: Xmobar.App.Defaults and Xmobar.Config.Types --- app/Configuration.hs | 70 +++++++++++----------- app/Main.hs | 3 +- src/Xmobar.hs | 9 ++- src/Xmobar/App/Defaults.hs | 71 ++++++++++++++++++++++ src/Xmobar/App/EventLoop.hs | 2 +- src/Xmobar/App/Main.hs | 2 +- src/Xmobar/Config.hs | 143 -------------------------------------------- src/Xmobar/Config/Types.hs | 90 ++++++++++++++++++++++++++++ src/Xmobar/X11/Draw.hs | 2 +- src/Xmobar/X11/Parsers.hs | 2 +- src/Xmobar/X11/Types.hs | 2 +- src/Xmobar/X11/Window.hs | 2 +- xmobar.cabal | 5 +- 13 files changed, 212 insertions(+), 191 deletions(-) create mode 100644 src/Xmobar/App/Defaults.hs delete mode 100644 src/Xmobar/Config.hs create mode 100644 src/Xmobar/Config/Types.hs diff --git a/app/Configuration.hs b/app/Configuration.hs index 1cf3ebf..6f6a0db 100644 --- a/app/Configuration.hs +++ b/app/Configuration.hs @@ -27,7 +27,7 @@ import Control.Monad.IO.Class (liftIO) import System.Environment import System.Posix.Files (fileExist) -import qualified Xmobar.Config as C +import qualified Xmobar as X #if defined XFT || defined UTF8 import qualified System.IO as S (readFile,hGetLine) @@ -50,7 +50,7 @@ stripComments = -- | Parse the config, logging a list of fields that were missing and replaced -- by the default definition. -parseConfig :: String -> Either ParseError (C.Config,[String]) +parseConfig :: String -> Either ParseError (X.Config,[String]) parseConfig = runParser parseConf fields "Config" . stripComments where parseConf = do @@ -61,7 +61,7 @@ parseConfig = runParser parseConf fields "Config" . stripComments s <- getState return (x,s) - perms = permute $ C.Config + perms = permute $ X.Config <$?> pFont <|?> pFontList <|?> pWmClass <|?> pWmName <|?> pBgColor <|?> pFgColor <|?> pPosition <|?> pTextOffset <|?> pTextOffsets @@ -81,33 +81,33 @@ parseConfig = runParser parseConf fields "Config" . stripComments , "alpha", "commands" ] - pFont = strField C.font "font" - pFontList = strListField C.additionalFonts "additionalFonts" - pWmClass = strField C.wmClass "wmClass" - pWmName = strField C.wmName "wmName" - pBgColor = strField C.bgColor "bgColor" - pFgColor = strField C.fgColor "fgColor" - pBdColor = strField C.borderColor "borderColor" - pSepChar = strField C.sepChar "sepChar" - pAlignSep = strField C.alignSep "alignSep" - pTemplate = strField C.template "template" - - pTextOffset = readField C.textOffset "textOffset" - pTextOffsets = readIntList C.textOffsets "textOffsets" - pIconOffset = readField C.iconOffset "iconOffset" - pPosition = readField C.position "position" - pHideOnStart = readField C.hideOnStart "hideOnStart" - pLowerOnStart = readField C.lowerOnStart "lowerOnStart" - pPersistent = readField C.persistent "persistent" - pBorder = readField C.border "border" - pBdWidth = readField C.borderWidth "borderWidth" - pAllDesktops = readField C.allDesktops "allDesktops" - pOverrideRedirect = readField C.overrideRedirect "overrideRedirect" - pPickBroadest = readField C.pickBroadest "pickBroadest" - pIconRoot = readField C.iconRoot "iconRoot" - pAlpha = readField C.alpha "alpha" - - pCommands = field C.commands "commands" readCommands + pFont = strField X.font "font" + pFontList = strListField X.additionalFonts "additionalFonts" + pWmClass = strField X.wmClass "wmClass" + pWmName = strField X.wmName "wmName" + pBgColor = strField X.bgColor "bgColor" + pFgColor = strField X.fgColor "fgColor" + pBdColor = strField X.borderColor "borderColor" + pSepChar = strField X.sepChar "sepChar" + pAlignSep = strField X.alignSep "alignSep" + pTemplate = strField X.template "template" + + pTextOffset = readField X.textOffset "textOffset" + pTextOffsets = readIntList X.textOffsets "textOffsets" + pIconOffset = readField X.iconOffset "iconOffset" + pPosition = readField X.position "position" + pHideOnStart = readField X.hideOnStart "hideOnStart" + pLowerOnStart = readField X.lowerOnStart "lowerOnStart" + pPersistent = readField X.persistent "persistent" + pBorder = readField X.border "border" + pBdWidth = readField X.borderWidth "borderWidth" + pAllDesktops = readField X.allDesktops "allDesktops" + pOverrideRedirect = readField X.overrideRedirect "overrideRedirect" + pPickBroadest = readField X.pickBroadest "pickBroadest" + pIconRoot = readField X.iconRoot "iconRoot" + pAlpha = readField X.alpha "alpha" + + pCommands = field X.commands "commands" readCommands staticPos = do string "Static" wrapSkip (string "{") @@ -148,7 +148,7 @@ parseConfig = runParser parseConf fields "Config" . stripComments wrapSkip x = many space >> x >>= \r -> many space >> return r sepEndSpc = mapM_ (wrapSkip . try . string) fieldEnd = many $ space <|> oneOf ",}" - field e n c = (,) (e C.defaultConfig) $ + field e n c = (,) (e X.defaultConfig) $ updateState (filter (/= n)) >> sepEndSpc [n,"="] >> wrapSkip c >>= \r -> fieldEnd >> return r readField a n = field a n $ tillFieldEnd >>= read' n @@ -173,7 +173,7 @@ commandsErr = "commands: this usually means that a command could not" ++ "\nwhich follows the offending one." -- | Reads the configuration files or quits with an error -readConfig :: FilePath -> String -> IO (C.Config,[String]) +readConfig :: FilePath -> String -> IO (X.Config,[String]) readConfig f usage = do file <- liftIO $ fileExist f s <- liftIO $ if file then readFileSafe f else error $ @@ -183,9 +183,9 @@ readConfig f usage = do return $ parseConfig s -- | Read default configuration file or load the default config -readDefaultConfig :: String -> IO (C.Config,[String]) +readDefaultConfig :: String -> IO (X.Config,[String]) readDefaultConfig usage = do - xdgConfigFile <- C.getXdgConfigFile + xdgConfigFile <- X.getXdgConfigFile xdgConfigFileExists <- liftIO $ fileExist xdgConfigFile home <- liftIO $ getEnv "HOME" let defaultConfigFile = home ++ "/.xmobarrc" @@ -194,4 +194,4 @@ readDefaultConfig usage = do then readConfig xdgConfigFile usage else if defaultConfigFileExists then readConfig defaultConfigFile usage - else return (C.defaultConfig,[]) + else return (X.defaultConfig,[]) diff --git a/app/Main.hs b/app/Main.hs index 0760d16..c37fb89 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -24,8 +24,7 @@ import System.Environment (getArgs) import Control.Monad (unless) import Text.Read (readMaybe) -import Xmobar (xmobar) -import Xmobar.Config +import Xmobar import Paths_xmobar (version) import Configuration (readConfig, readDefaultConfig) diff --git a/src/Xmobar.hs b/src/Xmobar.hs index 2b15835..dda56db 100644 --- a/src/Xmobar.hs +++ b/src/Xmobar.hs @@ -16,9 +16,11 @@ ----------------------------------------------------------------------------- module Xmobar (xmobar + , defaultConfig + , getXdgConfigFile , Runnable (..) , Exec (..) - , module Xmobar.Config + , module Xmobar.Config.Types , module Xmobar.Plugins.BufferedPipeReader , module Xmobar.Plugins.CommandReader , module Xmobar.Plugins.Date @@ -40,7 +42,7 @@ module Xmobar (xmobar import Xmobar.Run.Runnable import Xmobar.Run.Commands -import Xmobar.Config +import Xmobar.Config.Types import Xmobar.Plugins.BufferedPipeReader import Xmobar.Plugins.CommandReader import Xmobar.Plugins.Date @@ -59,4 +61,5 @@ import Xmobar.Plugins.PipeReader import Xmobar.Plugins.StdinReader import Xmobar.Plugins.XMonadLog -import Xmobar.App.Main (xmobar) +import Xmobar.App.Main(xmobar) +import Xmobar.App.Defaults(defaultConfig, getXdgConfigFile) diff --git a/src/Xmobar/App/Defaults.hs b/src/Xmobar/App/Defaults.hs new file mode 100644 index 0000000..ac3146c --- /dev/null +++ b/src/Xmobar/App/Defaults.hs @@ -0,0 +1,71 @@ +------------------------------------------------------------------------------ +-- | +-- Module: Xmobar.Config.Defaults +-- Copyright: (c) 2018 Jose Antonio Ortega Ruiz +-- License: BSD3-style (see LICENSE) +-- +-- Maintainer: jao@gnu.org +-- Stability: unstable +-- Portability: portable +-- Created: Sun Nov 25, 2018 22:26 +-- +-- +-- Default values for Xmobar configurations +-- +------------------------------------------------------------------------------ + + +module Xmobar.App.Defaults (defaultConfig, getXdgConfigFile) where + +import System.Environment +import System.Directory (getHomeDirectory) +import System.FilePath (()) + +import Xmobar.Plugins.Date +import Xmobar.Plugins.StdinReader +import Xmobar.Config.Types +import Xmobar.Run.Runnable + +-- | The default configuration values +defaultConfig :: Config +defaultConfig = + Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*" + , additionalFonts = [] + , wmClass = "xmobar" + , wmName = "xmobar" + , bgColor = "#000000" + , fgColor = "#BFBFBF" + , alpha = 255 + , position = Top + , border = NoBorder + , borderColor = "#BFBFBF" + , borderWidth = 1 + , textOffset = -1 + , iconOffset = -1 + , textOffsets = [] + , hideOnStart = False + , lowerOnStart = True + , persistent = False + , allDesktops = True + , overrideRedirect = True + , pickBroadest = False + , iconRoot = "." + , commands = [ Run $ Date "%a %b %_d %Y * %H:%M:%S" "theDate" 10 + , Run StdinReader] + , sepChar = "%" + , alignSep = "}{" + , template = "%StdinReader% }{ " ++ + "%uname% * %theDate%" + } + +xdgConfigDir :: IO String +xdgConfigDir = do env <- getEnvironment + case lookup "XDG_CONFIG_HOME" env of + Just val -> return val + Nothing -> fmap ( ".config") getHomeDirectory + +xmobarConfigDir :: IO FilePath +xmobarConfigDir = fmap ( "xmobar") xdgConfigDir + +getXdgConfigFile :: IO FilePath +getXdgConfigFile = fmap ( "xmobarrc") xmobarConfigDir diff --git a/src/Xmobar/App/EventLoop.hs b/src/Xmobar/App/EventLoop.hs index 95ce129..c751511 100644 --- a/src/Xmobar/App/EventLoop.hs +++ b/src/Xmobar/App/EventLoop.hs @@ -36,9 +36,9 @@ import Data.Bits import Data.Map hiding (foldr, map, filter) import Data.Maybe (fromJust, isJust) -import Xmobar.Config import Xmobar.Utils import Xmobar.System.Signal +import Xmobar.Config.Types import Xmobar.X11.Actions import Xmobar.Run.Commands import Xmobar.Run.Runnable diff --git a/src/Xmobar/App/Main.hs b/src/Xmobar/App/Main.hs index 329a4b5..b180e39 100644 --- a/src/Xmobar/App/Main.hs +++ b/src/Xmobar/App/Main.hs @@ -24,7 +24,7 @@ import Graphics.X11.Xlib import Control.Concurrent.Async (Async, cancel) import Control.Exception (bracket) -import Xmobar.Config +import Xmobar.Config.Types import Xmobar.System.Signal (setupSignalHandler, withDeferSignals) import Xmobar.Run.Template import Xmobar.X11.Types diff --git a/src/Xmobar/Config.hs b/src/Xmobar/Config.hs deleted file mode 100644 index a07af9e..0000000 --- a/src/Xmobar/Config.hs +++ /dev/null @@ -1,143 +0,0 @@ ------------------------------------------------------------------------------ --- | --- Module : Xmobar.Config --- Copyright : (c) Andrea Rossato --- License : BSD-style (see LICENSE) --- --- Maintainer : Jose A. Ortega Ruiz --- Stability : unstable --- Portability : unportable --- --- The configuration module of Xmobar, a text based status bar --- ------------------------------------------------------------------------------ - -module Xmobar.Config - ( -- * Configuration - -- $config - Config (..) - , XPosition (..), Align (..), Border(..) - , defaultConfig - , getXdgConfigFile - ) where - -import Xmobar.Plugins.Date -import Xmobar.Plugins.StdinReader - -import System.Environment -import System.Directory (getHomeDirectory) -import System.FilePath (()) - -import Xmobar.Run.Runnable (Runnable(..)) - --- $config --- Configuration data type and default configuration - --- | The configuration data type -data Config = - Config { font :: String -- ^ Font - , additionalFonts :: [String] -- ^ List of alternative fonts - , wmClass :: String -- ^ X11 WM_CLASS property value - , wmName :: String -- ^ X11 WM_NAME property value - , bgColor :: String -- ^ Backgroud color - , fgColor :: String -- ^ Default font color - , position :: XPosition -- ^ Top Bottom or Static - , textOffset :: Int -- ^ Offset from top of window for text - , textOffsets :: [Int] -- ^ List of offsets for additionalFonts - , iconOffset :: Int -- ^ Offset from top of window for icons - , border :: Border -- ^ NoBorder TopB BottomB or FullB - , borderColor :: String -- ^ Border color - , borderWidth :: Int -- ^ Border width - , alpha :: Int -- ^ Transparency from 0 (transparent) - -- to 255 (opaque) - , hideOnStart :: Bool -- ^ Hide (Unmap) the window on - -- initialization - , allDesktops :: Bool -- ^ Tell the WM to map to all desktops - , overrideRedirect :: Bool -- ^ Needed for dock behaviour in some - -- non-tiling WMs - , pickBroadest :: Bool -- ^ Use the broadest display - -- instead of the first one by - -- default - , lowerOnStart :: Bool -- ^ lower to the bottom of the - -- window stack on initialization - , persistent :: Bool -- ^ Whether automatic hiding should - -- be enabled or disabled - , iconRoot :: FilePath -- ^ Root folder for icons - , commands :: [Runnable] -- ^ For setting the command, - -- the command arguments - -- and refresh rate for the programs - -- to run (optional) - , sepChar :: String -- ^ The character to be used for indicating - -- commands in the output template - -- (default '%') - , alignSep :: String -- ^ Separators for left, center and - -- right text alignment - , template :: String -- ^ The output template - } deriving (Read) - -data XPosition = Top - | TopW Align Int - | TopSize Align Int Int - | TopP Int Int - | Bottom - | BottomP Int Int - | BottomW Align Int - | BottomSize Align Int Int - | Static {xpos, ypos, width, height :: Int} - | OnScreen Int XPosition - deriving ( Read, Eq ) - -data Align = L | R | C deriving ( Read, Eq ) - -data Border = NoBorder - | TopB - | BottomB - | FullB - | TopBM Int - | BottomBM Int - | FullBM Int - deriving ( Read, Eq ) - --- | The default configuration values -defaultConfig :: Config -defaultConfig = - Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*" - , additionalFonts = [] - , wmClass = "xmobar" - , wmName = "xmobar" - , bgColor = "#000000" - , fgColor = "#BFBFBF" - , alpha = 255 - , position = Top - , border = NoBorder - , borderColor = "#BFBFBF" - , borderWidth = 1 - , textOffset = -1 - , iconOffset = -1 - , textOffsets = [] - , hideOnStart = False - , lowerOnStart = True - , persistent = False - , allDesktops = True - , overrideRedirect = True - , pickBroadest = False - , iconRoot = "." - , commands = [ Run $ Date "%a %b %_d %Y * %H:%M:%S" "theDate" 10 - , Run StdinReader] - , sepChar = "%" - , alignSep = "}{" - , template = "%StdinReader% }{ " ++ - "%uname% * %theDate%" - } - -xdgConfigDir :: IO String -xdgConfigDir = do env <- getEnvironment - case lookup "XDG_CONFIG_HOME" env of - Just val -> return val - Nothing -> fmap ( ".config") getHomeDirectory - -xmobarConfigDir :: IO FilePath -xmobarConfigDir = fmap ( "xmobar") xdgConfigDir - -getXdgConfigFile :: IO FilePath -getXdgConfigFile = fmap ( "xmobarrc") xmobarConfigDir diff --git a/src/Xmobar/Config/Types.hs b/src/Xmobar/Config/Types.hs new file mode 100644 index 0000000..ab85d5b --- /dev/null +++ b/src/Xmobar/Config/Types.hs @@ -0,0 +1,90 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Xmobar.Config +-- Copyright : (c) Andrea Rossato +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Jose A. Ortega Ruiz +-- Stability : unstable +-- Portability : unportable +-- +-- The configuration types +-- +----------------------------------------------------------------------------- + +module Xmobar.Config.Types + ( -- * Configuration + -- $config + Config (..) + , XPosition (..), Align (..), Border(..) + ) where + +import Xmobar.Run.Runnable (Runnable(..)) + +-- $config +-- Configuration data type + +-- | The configuration data type +data Config = + Config { font :: String -- ^ Font + , additionalFonts :: [String] -- ^ List of alternative fonts + , wmClass :: String -- ^ X11 WM_CLASS property value + , wmName :: String -- ^ X11 WM_NAME property value + , bgColor :: String -- ^ Backgroud color + , fgColor :: String -- ^ Default font color + , position :: XPosition -- ^ Top Bottom or Static + , textOffset :: Int -- ^ Offset from top of window for text + , textOffsets :: [Int] -- ^ List of offsets for additionalFonts + , iconOffset :: Int -- ^ Offset from top of window for icons + , border :: Border -- ^ NoBorder TopB BottomB or FullB + , borderColor :: String -- ^ Border color + , borderWidth :: Int -- ^ Border width + , alpha :: Int -- ^ Transparency from 0 (transparent) + -- to 255 (opaque) + , hideOnStart :: Bool -- ^ Hide (Unmap) the window on + -- initialization + , allDesktops :: Bool -- ^ Tell the WM to map to all desktops + , overrideRedirect :: Bool -- ^ Needed for dock behaviour in some + -- non-tiling WMs + , pickBroadest :: Bool -- ^ Use the broadest display + -- instead of the first one by + -- default + , lowerOnStart :: Bool -- ^ lower to the bottom of the + -- window stack on initialization + , persistent :: Bool -- ^ Whether automatic hiding should + -- be enabled or disabled + , iconRoot :: FilePath -- ^ Root folder for icons + , commands :: [Runnable] -- ^ For setting the command, + -- the command arguments + -- and refresh rate for the programs + -- to run (optional) + , sepChar :: String -- ^ The character to be used for indicating + -- commands in the output template + -- (default '%') + , alignSep :: String -- ^ Separators for left, center and + -- right text alignment + , template :: String -- ^ The output template + } deriving (Read) + +data XPosition = Top + | TopW Align Int + | TopSize Align Int Int + | TopP Int Int + | Bottom + | BottomP Int Int + | BottomW Align Int + | BottomSize Align Int Int + | Static {xpos, ypos, width, height :: Int} + | OnScreen Int XPosition + deriving ( Read, Eq ) + +data Align = L | R | C deriving ( Read, Eq ) + +data Border = NoBorder + | TopB + | BottomB + | FullB + | TopBM Int + | BottomBM Int + | FullBM Int + deriving ( Read, Eq ) diff --git a/src/Xmobar/X11/Draw.hs b/src/Xmobar/X11/Draw.hs index 781ced8..246eb84 100644 --- a/src/Xmobar/X11/Draw.hs +++ b/src/Xmobar/X11/Draw.hs @@ -29,11 +29,11 @@ import Data.Map hiding (foldr, map, filter) import Graphics.X11.Xlib hiding (textExtents, textWidth) import Graphics.X11.Xlib.Extras +import Xmobar.Config.Types import qualified Xmobar.X11.Bitmap as B import Xmobar.X11.Actions (Action(..)) import Xmobar.X11.Types import Xmobar.X11.XUtil -import Xmobar.Config import Xmobar.X11.ColorCache import Xmobar.X11.Window (drawBorder) import Xmobar.X11.Parsers (Widget(..)) diff --git a/src/Xmobar/X11/Parsers.hs b/src/Xmobar/X11/Parsers.hs index c76110d..258964a 100644 --- a/src/Xmobar/X11/Parsers.hs +++ b/src/Xmobar/X11/Parsers.hs @@ -16,7 +16,7 @@ module Xmobar.X11.Parsers (parseString, Widget(..)) where -import Xmobar.Config +import Xmobar.Config.Types import Xmobar.X11.Actions import Control.Monad (guard, mzero) diff --git a/src/Xmobar/X11/Types.hs b/src/Xmobar/X11/Types.hs index c5c7ade..f551c2a 100644 --- a/src/Xmobar/X11/Types.hs +++ b/src/Xmobar/X11/Types.hs @@ -23,7 +23,7 @@ import Data.Map import Xmobar.X11.Bitmap import Xmobar.X11.XUtil -import Xmobar.Config +import Xmobar.Config.Types -- | The X type is a ReaderT type X = ReaderT XConf IO diff --git a/src/Xmobar/X11/Window.hs b/src/Xmobar/X11/Window.hs index 78f4b26..23568ab 100644 --- a/src/Xmobar/X11/Window.hs +++ b/src/Xmobar/X11/Window.hs @@ -28,7 +28,7 @@ import Data.List (maximumBy) import Data.Maybe (fromMaybe) import System.Posix.Process (getProcessID) -import Xmobar.Config +import Xmobar.Config.Types import Xmobar.X11.XUtil -- $window diff --git a/xmobar.cabal b/xmobar.cabal index 69f8f4d..ea1bcdd 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -94,16 +94,17 @@ flag with_conduit library hs-source-dirs: src - exposed-modules: Xmobar, - Xmobar.Config + exposed-modules: Xmobar other-modules: Xmobar.Utils, + Xmobar.Config.Types, Xmobar.Run.Types, Xmobar.Run.Template, Xmobar.Run.Commands, Xmobar.Run.Runnable Xmobar.App.EventLoop, Xmobar.App.Main, + Xmobar.App.Defaults, Xmobar.System.StatFS, Xmobar.System.Environment, Xmobar.System.Localize, -- cgit v1.2.3