{-# LANGUAGE OverloadedStrings #-} module Main where import System.Taffybar (startTaffybar) import System.Taffybar.Context (TaffybarConfig(..)) import System.Taffybar.Hooks import System.Taffybar.SimpleConfig hiding (SimpleTaffyConfig(cssPath)) import System.Taffybar.Widget import qualified System.Taffybar.Widget.Clock as MyClock import System.Taffybar.Widget.TooltipBattery import Data.Time.Format import Data.Time.LocalTime import Data.Time.Calendar.WeekDate import qualified Data.Text as T import Control.Exception (SomeException, try) import Control.Monad.Trans.Reader (mapReaderT) import Paths_gkleen_sif_taffybar import System.Log.Logger main :: IO () main = do logger <- getLogger "System.Taffybar" saveGlobalLogger $ setLevel INFO logger myCssPath <- getDataFileName "taffybar.css" startTaffybar taffybarConfig{ cssPaths = pure myCssPath } taffybarConfig :: TaffybarConfig taffybarConfig = let myWorkspacesConfig = defaultWorkspacesConfig { maxIcons = Just 0 , widgetGap = 7 , showWorkspaceFn = \case -- Workspace{ workspaceState = Empty } -> False Workspace{ workspaceName } | workspaceName == "NSP" -> False _other -> True , getWindowIconPixbuf = \i d -> either (\(_ :: SomeException) -> Nothing) id <$> mapReaderT try (defaultGetWindowIconPixbuf i d) , urgentWorkspaceState = True } workspaces = workspacesNew myWorkspacesConfig clock = MyClock.textClockNewWith MyClock.defaultClockConfig { MyClock.clockUpdateStrategy = MyClock.RoundedTargetInterval 1 0.0 , MyClock.clockFormat = \tl zt@ZonedTime{ zonedTimeToLocalTime = LocalTime{ localDay } } -> let date = formatTime tl "%Y-%m-%d" localDay weekdate = "W" <> show2 woy <> "-" <> show dow where (_, woy, dow) = toWeekDate localDay show2 :: Int -> String show2 x = replicate (2 - length s) '0' ++ s where s = show x time = formatTime tl "%H:%M:%S%Ez" zt in T.intercalate " " $ map T.pack [weekdate, date, time] } layout = layoutNew defaultLayoutConfig windowsW = windowsNew defaultWindowsConfig { getMenuLabel = truncatedGetMenuLabel 80 , getActiveLabel = truncatedGetActiveLabel 80 } worktime = commandRunnerNew 15 "worktime" [] "worktime" worktimeToday = commandRunnerNew 15 "worktime" ["today"] "worktime today" -- See https://github.com/taffybar/gtk-sni-tray#statusnotifierwatcher -- for a better way to set up the sni tray -- tray = sniTrayThatStartsWatcherEvenThoughThisIsABadWayToDoIt tray = sniTrayNew myConfig = defaultSimpleTaffyConfig { startWidgets = workspaces : map (>>= buildContentsBox) [ layout, windowsW ] , endWidgets = map (>>= buildContentsBox) $ reverse -- , mpris2New [ worktime, worktimeToday , clock , tray , batteryIconTooltipNew "$status$ $percentage$%$if(time)$$if(rate)$ ($rate$W $time$)$else$ ($time$)$endif$$elseif(rate)$ ($rate$W)$endif$" ] , barPosition = Top , barPadding = 2 , barHeight = 28 , widgetSpacing = 10 } in withBatteryRefresh $ withLogServer $ withToggleServer $ toTaffyConfig myConfig