2017-10-29 19:04:57 -07:00
|
|
|
{-# LANGUAGE PackageImports #-}
|
2017-08-23 12:43:25 -07:00
|
|
|
module Main where
|
|
|
|
|
2017-11-16 20:00:33 -08:00
|
|
|
import Control.Exception.Base
|
|
|
|
import Control.Monad
|
2018-05-16 23:06:22 -07:00
|
|
|
import Control.Monad.IO.Class
|
|
|
|
import Control.Monad.Trans.Class
|
|
|
|
import Control.Monad.Trans.Reader
|
2018-04-27 17:36:32 -07:00
|
|
|
import qualified Data.ByteString.Char8 as BS
|
2017-11-16 20:00:33 -08:00
|
|
|
import Data.List
|
|
|
|
import Data.List.Split
|
|
|
|
import qualified Data.Map as M
|
|
|
|
import Data.Maybe
|
2018-04-27 17:36:32 -07:00
|
|
|
import qualified GitHub.Auth as Auth
|
2018-03-23 21:24:38 -07:00
|
|
|
import StatusNotifier.Tray
|
2017-11-16 20:00:33 -08:00
|
|
|
import System.Directory
|
|
|
|
import System.Environment
|
|
|
|
import System.FilePath.Posix
|
2018-03-23 21:24:38 -07:00
|
|
|
import System.Glib.GObject
|
2018-04-18 00:46:41 -07:00
|
|
|
import System.IO
|
|
|
|
import System.Log.Handler.Simple
|
|
|
|
import System.Log.Logger
|
2017-11-16 20:00:33 -08:00
|
|
|
import System.Process
|
|
|
|
import System.Taffybar
|
2018-04-27 17:36:32 -07:00
|
|
|
import System.Taffybar.Auth
|
2018-05-03 22:42:39 -07:00
|
|
|
import System.Taffybar.Compat.GtkLibs
|
2018-05-03 10:39:27 -07:00
|
|
|
import System.Taffybar.DBus
|
2018-04-25 20:10:44 -07:00
|
|
|
import System.Taffybar.DBus.Toggle
|
2018-05-03 22:42:39 -07:00
|
|
|
import System.Taffybar.Hooks
|
2018-04-25 20:10:44 -07:00
|
|
|
import System.Taffybar.Information.CPU
|
|
|
|
import System.Taffybar.Information.EWMHDesktopInfo
|
|
|
|
import System.Taffybar.Information.Memory
|
|
|
|
import System.Taffybar.Information.X11DesktopInfo
|
2018-04-18 00:46:41 -07:00
|
|
|
import System.Taffybar.SimpleConfig
|
2018-04-25 20:17:43 -07:00
|
|
|
import System.Taffybar.Widget
|
|
|
|
import System.Taffybar.Widget.Generic.PollingGraph
|
2018-05-10 16:05:50 -07:00
|
|
|
import System.Taffybar.Widget.Generic.PollingLabel
|
2018-05-12 10:02:30 -07:00
|
|
|
import System.Taffybar.Widget.Util
|
2018-04-25 20:17:43 -07:00
|
|
|
import System.Taffybar.Widget.Workspaces
|
2017-11-16 20:00:33 -08:00
|
|
|
import Text.Printf
|
2018-03-23 21:24:38 -07:00
|
|
|
import Text.Read hiding (lift)
|
2018-05-03 22:42:39 -07:00
|
|
|
|
|
|
|
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
|
2017-10-26 17:59:57 -07:00
|
|
|
{ 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-03 22:42:39 -07:00
|
|
|
}
|
|
|
|
|
2018-05-16 11:56:22 -07:00
|
|
|
netCfg = myGraphConfig
|
2018-05-03 22:42:39 -07:00
|
|
|
{ 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"
|
|
|
|
}
|
|
|
|
|
2017-10-26 17:59:57 -07:00
|
|
|
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]
|
|
|
|
|
2017-09-10 13:16:58 -07:00
|
|
|
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
|
2017-09-10 13:16:58 -07:00
|
|
|
|
2018-04-18 00:46:41 -07:00
|
|
|
logDebug = do
|
2018-05-21 12:44:12 -07:00
|
|
|
logger <- getLogger "System.Taffybar.Widget.Generic.AutoSizeImage"
|
2018-04-18 00:46:41 -07:00
|
|
|
saveGlobalLogger $ setLevel DEBUG logger
|
2018-05-21 12:44:12 -07:00
|
|
|
logger2 <- getLogger "StatusNotifier.Tray"
|
|
|
|
saveGlobalLogger $ setLevel DEBUG logger2
|
2018-05-15 18:04:47 -07:00
|
|
|
workspacesLogger <- getLogger "System.Taffybar.Widget.Workspaces"
|
|
|
|
saveGlobalLogger $ setLevel WARNING workspacesLogger
|
2018-04-18 00:46:41 -07:00
|
|
|
|
2018-05-21 12:44:12 -07:00
|
|
|
-- github = do
|
|
|
|
-- Right (token, _) <- passGet "github-token"
|
|
|
|
-- githubNotificationsNew $ defaultGithubConfig $ Auth.OAuth $ BS.pack token
|
2018-04-27 17:36:32 -07:00
|
|
|
|
2016-09-16 14:11:52 -07:00
|
|
|
main = do
|
2017-03-05 18:30:55 -08:00
|
|
|
homeDirectory <- getHomeDirectory
|
2018-05-21 12:44:12 -07:00
|
|
|
-- logDebug
|
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
|
2017-09-10 18:20:04 -07:00
|
|
|
makeIcon = return . IIFilePath . inResourcesDirectory
|
|
|
|
myGetIconInfo w@WindowData {windowTitle = title, windowClass = klass}
|
2017-05-30 18:23:13 -07:00
|
|
|
| "URxvt" `isInfixOf` klass = makeIcon "urxvt.png"
|
2017-09-10 18:20:04 -07:00
|
|
|
| "Termite" `isInfixOf` klass = makeIcon "urxvt.png"
|
2017-05-30 18:23:13 -07:00
|
|
|
| "Kodi" `isInfixOf` klass = makeIcon "kodi.png"
|
|
|
|
| "@gmail.com" `isInfixOf` title &&
|
2017-09-10 18:20:04 -07:00
|
|
|
"chrome" `isInfixOf` klass && "Gmail" `isInfixOf` title =
|
|
|
|
makeIcon "gmail.png"
|
|
|
|
| otherwise = do
|
|
|
|
res <- defaultGetIconInfo w
|
|
|
|
return $
|
|
|
|
case res of
|
|
|
|
IINone -> IIFilePath $ inResourcesDirectory "exe-icon.png"
|
|
|
|
_ -> res
|
2016-09-16 14:11:52 -07:00
|
|
|
cpu = pollingGraphNew cpuCfg 0.5 cpuCallback
|
2017-10-26 17:59:57 -07:00
|
|
|
mem = pollingGraphNew memCfg 1 memCallback
|
2018-05-16 11:56:22 -07:00
|
|
|
layout = layoutNew defaultLayoutConfig
|
|
|
|
windows = windowsNew defaultWindowsConfig
|
2018-04-24 14:19:52 -07:00
|
|
|
myWorkspacesConfig =
|
|
|
|
defaultWorkspacesConfig
|
2017-03-01 19:21:58 -08:00
|
|
|
{ underlineHeight = 3
|
2017-07-27 19:59:23 -07:00
|
|
|
, underlinePadding = 2
|
2017-03-01 19:21:58 -08:00
|
|
|
, minWSWidgetSize = Nothing
|
2017-10-24 11:38:37 -07:00
|
|
|
, minIcons = 1
|
2017-03-01 19:21:58 -08:00
|
|
|
, getIconInfo = myGetIconInfo
|
2018-05-21 12:44:12 -07:00
|
|
|
-- , windowIconSize = 31
|
2017-03-01 19:21:58 -08:00
|
|
|
, widgetGap = 0
|
|
|
|
, showWorkspaceFn = hideEmpty
|
|
|
|
, updateRateLimitMicroseconds = 100000
|
2017-09-10 13:16:58 -07:00
|
|
|
, labelSetter = workspaceNamesLabelSetter
|
2017-03-01 19:21:58 -08:00
|
|
|
}
|
2018-05-16 11:56:22 -07:00
|
|
|
workspaces = workspacesNew myWorkspacesConfig
|
2018-04-25 20:10:44 -07:00
|
|
|
baseConfig = defaultSimpleTaffyConfig
|
|
|
|
{ startWidgets =
|
2018-05-18 01:20:15 -07:00
|
|
|
workspaces : map (>>= buildContentsBox) [ layout, windows ]
|
|
|
|
, endWidgets = map (>>= buildContentsBox)
|
2018-05-17 15:06:58 -07:00
|
|
|
[ textClockNew Nothing "%a %b %_d %r" 1
|
2018-05-16 22:40:12 -07:00
|
|
|
, textBatteryNew "$percentage$% ($time$)"
|
|
|
|
, batteryIconNew
|
2018-05-03 22:42:39 -07:00
|
|
|
, sniTrayNew
|
2018-05-21 12:44:12 -07:00
|
|
|
-- , github
|
2018-05-03 22:42:39 -07:00
|
|
|
, cpu
|
|
|
|
, mem
|
2018-05-15 17:59:53 -07:00
|
|
|
, networkGraphNew netCfg Nothing
|
2018-05-10 16:05:50 -07:00
|
|
|
-- , networkMonitorNew defaultNetFormat Nothing >>= setMinWidth 200
|
2018-05-21 12:44:12 -07:00
|
|
|
-- , fsMonitorNew 60 ["/dev/sdd2"]
|
2018-05-16 11:56:22 -07:00
|
|
|
, mpris2New
|
2018-04-25 20:10:44 -07:00
|
|
|
]
|
2017-03-12 21:25:59 -07:00
|
|
|
, barPosition = Top
|
2018-05-21 12:44:12 -07:00
|
|
|
, barPadding = 5
|
|
|
|
, barHeight = 50
|
2017-10-26 17:59:57 -07:00
|
|
|
, widgetSpacing = 0
|
2017-03-12 21:25:59 -07:00
|
|
|
}
|
2018-04-25 20:10:44 -07:00
|
|
|
simpleTaffyConfig =
|
|
|
|
baseConfig
|
2018-05-21 12:44:12 -07:00
|
|
|
-- { endWidgets = []
|
|
|
|
-- , startWidgets = [flip widgetSetClass "Workspaces" =<< workspaces]
|
|
|
|
-- }
|
|
|
|
startTaffybar $ withBatteryRefresh $ withLogServer $ withToggleServer $
|
|
|
|
toTaffyConfig simpleTaffyConfig
|
2016-09-16 14:11:52 -07:00
|
|
|
|
|
|
|
-- Local Variables:
|
|
|
|
-- flycheck-ghc-args: ("-Wno-missing-signatures")
|
|
|
|
-- End:
|