From e019e80eac1b03a5c177ef5d358b720bdbc774ac Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 5 Dec 2021 16:56:41 +0100 Subject: gkleen@sif: taffybar --- accounts/gkleen@sif/taffybar/src/taffybar.hs | 83 ++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 accounts/gkleen@sif/taffybar/src/taffybar.hs (limited to 'accounts/gkleen@sif/taffybar/src/taffybar.hs') diff --git a/accounts/gkleen@sif/taffybar/src/taffybar.hs b/accounts/gkleen@sif/taffybar/src/taffybar.hs new file mode 100644 index 00000000..dd713ea7 --- /dev/null +++ b/accounts/gkleen@sif/taffybar/src/taffybar.hs @@ -0,0 +1,83 @@ +{-# 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 + + +main :: IO () +main = do + myCssPath <- getDataFileName "taffybar.css" + startTaffybar exampleTaffybarConfig{ cssPath = Just myCssPath } + + +exampleTaffybarConfig :: TaffybarConfig +exampleTaffybarConfig = + 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) + } + 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 [date, weekdate, time] + } + layout = layoutNew defaultLayoutConfig + windowsW = windowsNew defaultWindowsConfig + { getMenuLabel = truncatedGetMenuLabel 80 + , getActiveLabel = truncatedGetActiveLabel 80 + } + worktime = commandRunnerNew 150 "worktime" [] "worktime" + worktimeToday = commandRunnerNew 150 "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 -- cgit v1.2.3