179 lines
6.1 KiB
Haskell
Raw Normal View History

2018-05-29 21:03:19 -07:00
{-# LANGUAGE OverloadedStrings #-}
2017-08-23 12:43:25 -07:00
module Main where
import Control.Exception.Base
import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Control.Monad.Trans.Reader
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.List.Split
import qualified Data.Map as M
import Data.Maybe
import Network.HostName
import StatusNotifier.Tray
import System.Directory
import System.Environment
import System.FilePath.Posix
import System.IO
import System.Log.Handler.Simple
import System.Log.Logger
import System.Process
import System.Taffybar
import System.Taffybar.Auth
import System.Taffybar.Context (appendHook)
import System.Taffybar.DBus
import System.Taffybar.DBus.Toggle
import System.Taffybar.Hooks
import System.Taffybar.Information.CPU
import System.Taffybar.Information.EWMHDesktopInfo
import System.Taffybar.Information.Memory
import System.Taffybar.Information.X11DesktopInfo
import System.Environment.XDG.BaseDir
import System.Taffybar.SimpleConfig
import System.Taffybar.Util
import System.Taffybar.Widget
import System.Taffybar.Widget.Generic.PollingGraph
import System.Taffybar.Widget.Generic.PollingLabel
import System.Taffybar.Widget.Util
import System.Taffybar.Widget.Workspaces
import Text.Printf
import Text.Read hiding (lift)
mkRGBA (r, g, b, a) = (r/256, g/256, b/256, a/256)
blue = mkRGBA (42, 99, 140, 256)
yellow1 = mkRGBA (242, 163, 54, 256)
yellow2 = mkRGBA (254, 204, 83, 256)
yellow3 = mkRGBA (227, 134, 18, 256)
red = mkRGBA (210, 77, 37, 256)
2017-10-26 00:32:31 -07:00
myGraphConfig =
2017-05-24 21:56:34 -07:00
defaultGraphConfig
{ graphPadding = 0
2017-10-26 00:32:31 -07:00
, graphBorderWidth = 0
, graphWidth = 75
2018-05-21 12:44:12 -07:00
, graphBackgroundColor = (0.0, 0.0, 0.0, 0.0)
}
2018-05-16 11:56:22 -07:00
netCfg = myGraphConfig
{ graphDataColors = [yellow1, yellow2]
, graphLabel = Just "net"
2017-10-26 00:32:31 -07:00
}
2018-05-16 11:56:22 -07:00
memCfg = myGraphConfig
2018-04-27 17:36:32 -07:00
{ graphDataColors = [(0.129, 0.588, 0.953, 1)]
, graphLabel = Just "mem"
}
2017-05-24 21:56:34 -07:00
2018-05-16 11:56:22 -07:00
cpuCfg = myGraphConfig
{ graphDataColors = [(0, 1, 0, 1), (1, 0, 1, 0.5)]
, graphLabel = Just "cpu"
}
memCallback :: IO [Double]
memCallback = do
2016-09-16 14:11:52 -07:00
mi <- parseMeminfo
return [memoryUsedRatio mi]
2018-05-16 11:56:22 -07:00
cpuCallback = do
(_, systemLoad, totalLoad) <- cpuLoad
return [totalLoad, systemLoad]
getFullWorkspaceNames :: X11Property [(WorkspaceIdx, String)]
getFullWorkspaceNames = go <$> readAsListOfString Nothing "_NET_DESKTOP_FULL_NAMES"
where go = zip [WSIdx i | i <- [0..]]
2018-03-23 21:24:38 -07:00
workspaceNamesLabelSetter workspace =
fromMaybe "" . lookup (workspaceIdx workspace) <$>
liftX11Def [] getFullWorkspaceNames
enableLogger logger level = do
logger <- getLogger logger
saveGlobalLogger $ setLevel level logger
logDebug = do
2018-05-21 12:44:12 -07:00
logger <- getLogger "System.Taffybar.Widget.Generic.AutoSizeImage"
saveGlobalLogger $ setLevel DEBUG logger
2018-05-21 12:44:12 -07:00
logger2 <- getLogger "StatusNotifier.Tray"
saveGlobalLogger $ setLevel DEBUG logger2
workspacesLogger <- getLogger "System.Taffybar.Widget.Workspaces"
saveGlobalLogger $ setLevel WARNING workspacesLogger
cssFileByHostname =
[ ("uber-loaner", "uber-loaner.css")
, ("imalison-home", "taffybar.css")
]
2016-09-16 14:11:52 -07:00
main = do
hostName <- getHostName
2017-03-05 18:30:55 -08:00
homeDirectory <- getHomeDirectory
let cssFileName = lookup hostName cssFileByHostname
cssFilePath <- traverse (getUserConfigFile "taffybar") cssFileName
2018-05-21 12:44:12 -07:00
-- logDebug
2018-05-29 21:03:19 -07:00
-- logM "What" WARNING "Why"
-- enableLogger "System.Taffybar.Widget.Util" DEBUG
-- enableLogger "System.Taffybar.Information.XDG.DesktopEntry" DEBUG
-- enableLogger "System.Taffybar.WindowIcon" DEBUG
2017-05-30 18:23:13 -07:00
let resourcesDirectory = homeDirectory </> ".lib" </> "resources"
inResourcesDirectory file = resourcesDirectory </> file
2017-10-13 22:09:08 -07:00
highContrastDirectory =
"/" </> "usr" </> "share" </> "icons" </> "HighContrast" </> "256x256"
inHighContrastDirectory file = highContrastDirectory </> file
2018-05-29 21:03:19 -07:00
myIcons = scaledWindowIconPixbufGetter $
getWindowIconPixbufFromChrome <|||>
2018-05-29 21:03:19 -07:00
unscaledDefaultGetWindowIconPixbuf <|||>
(\size _ -> lift $ loadPixbufByName size "application-default-icon")
2016-09-16 14:11:52 -07:00
cpu = pollingGraphNew cpuCfg 0.5 cpuCallback
mem = pollingGraphNew memCfg 1 memCallback
2018-05-16 11:56:22 -07:00
layout = layoutNew defaultLayoutConfig
windows = windowsNew defaultWindowsConfig
notifySystemD = void $ runCommandFromPath ["systemd-notify", "--ready"]
2018-04-24 14:19:52 -07:00
myWorkspacesConfig =
defaultWorkspacesConfig
{ underlineHeight = 3
2017-07-27 19:59:23 -07:00
, underlinePadding = 2
, minIcons = 1
, getWindowIconPixbuf = myIcons
2018-05-21 12:44:12 -07:00
-- , windowIconSize = 31
, widgetGap = 0
, showWorkspaceFn = hideEmpty
, updateRateLimitMicroseconds = 100000
, labelSetter = workspaceNamesLabelSetter
}
2018-05-16 11:56:22 -07:00
workspaces = workspacesNew myWorkspacesConfig
baseConfig =
defaultSimpleTaffyConfig
{ startWidgets =
workspaces : map (>>= buildContentsBox) [layout, windows]
, endWidgets =
map
(>>= buildContentsBox)
[ textBatteryNew "$percentage$%"
, batteryIconNew
, textClockNew Nothing "%a %b %_d %r" 1
, sniTrayNew
, cpu
, mem
, networkGraphNew netCfg Nothing
2019-01-05 18:42:16 -08:00
-- , networkMonitorNew defaultNetFormat Nothing >>= setMinWidth 200
-- , fsMonitorNew 60 ["/dev/sdd2"]
, mpris2New
]
2017-03-12 21:25:59 -07:00
, barPosition = Top
, barPadding = 0
, barHeight = 30
, cssPath = cssFilePath
2017-03-12 21:25:59 -07:00
}
simpleTaffyConfig = baseConfig
2019-01-05 18:42:16 -08:00
{ centerWidgets = map (>>= buildContentsBox) []
-- , endWidgets = map (>>= buildContentsBox) [ sniTrayNew, mpris2New ]
2018-05-21 12:44:12 -07:00
-- , startWidgets = [flip widgetSetClass "Workspaces" =<< workspaces]
2019-01-05 18:42:16 -08:00
}
startTaffybar $
appendHook notifySystemD $
appendHook (void $ getHost False) $
withLogServer $
withToggleServer $
toTaffyConfig simpleTaffyConfig