[taffybar] Add crypto icons to crypto prices

This commit is contained in:
Ivan Malison 2021-08-06 23:38:44 -06:00
parent 6d7070b24d
commit 7168064982
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8
4 changed files with 80 additions and 96 deletions

View File

@ -14,7 +14,6 @@ executable taffybar
hs-source-dirs: . hs-source-dirs: .
main-is: taffybar.hs main-is: taffybar.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N ghc-options: -threaded -rtsopts -with-rtsopts=-N
-- ghc-options: -threaded -g -rtsopts
ghc-prof-options: -fprof-auto ghc-prof-options: -fprof-auto
build-depends: base build-depends: base
, X11 , X11

@ -1 +1 @@
Subproject commit 0b30a778689902c54577306cd73ebb7ba79f8c6e Subproject commit 00d8e0f88de31aed0f7a3baf2dc308e51763bcc6

View File

@ -4,12 +4,14 @@
@define-color taffy-blue #0c7cd5; @define-color taffy-blue #0c7cd5;
@define-color taffy-navy rgb(25, 30, 55); @define-color taffy-navy rgb(25, 30, 55);
@define-color taffy-red rgba(255, 65, 81, 1.0); @define-color taffy-red rgba(255, 65, 81, 1.0);
@define-color taffy-teal #00695C;
@define-color active-window-color @white; @define-color active-window-color @white;
@define-color urgent-window-color @taffy-blue; @define-color urgent-window-color @taffy-blue;
@define-color font-color @white; @define-color font-color @white;
@define-color menu-background-color @white; @define-color menu-background-color @white;
@define-color menu-font-color @black; @define-color menu-font-color @black;
@define-color bar-background @taffy-navy;
/* Top level styling */ /* Top level styling */
@ -18,32 +20,36 @@
font-size: 10pt; font-size: 10pt;
font-weight: bold; font-weight: bold;
color: @font-color; color: @font-color;
border-radius: 4px;
text-shadow: 2px 2px @black; text-shadow: 2px 2px @black;
} }
.taffy-box { .taffy-box {
border-color: @white; border-color: @white;
border-style: solid; border-style: solid;
background-color: @taffy-navy; background-color: @bar-background;
padding: 3px; padding: 3px;
margin: 4px; margin: 4px;
} border-radius: 4px;
.inner-pad {
padding: 0px;
} }
.contents { .contents {
padding: 2px; padding: 2px;
transition: background-color .5s; transition: background-color .5s;
border-color: @white;
opacity: 1; opacity: 1;
/* border-radius: 6px; */
} }
/* Workspaces styling */ /* Workspaces styling */
.workspaces .inner-pad {
box-shadow: none;
border-width: 0;
}
.workspaces .contents {
box-shadow: none;
border-radius: 4px;
}
.workspace-label { .workspace-label {
padding-right: 4px; padding-right: 4px;
padding-left: 2px; padding-left: 2px;
@ -56,9 +62,8 @@
text-shadow: 2px 2px @black; text-shadow: 2px 2px @black;
} }
.contents .window-icon { .contents .window-icon {
opacity: .5; border-width: 1px;
} }
.active .contents .window-icon { .active .contents .window-icon {
@ -107,10 +112,6 @@
.window-icon-container.urgent { .window-icon-container.urgent {
} }
.window-icon-container.inactive .window-icon {
padding: 0px;
}
.window-icon-container.minimized .window-icon { .window-icon-container.minimized .window-icon {
opacity: .3; opacity: .3;
} }

View File

@ -1,11 +1,8 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
module Main where module Main where
import qualified CoinbasePro.Environment as CB
import qualified CoinbasePro.Headers as CB
import qualified CoinbasePro.Request as CB
import qualified CoinbasePro.Types as CB
import qualified CoinbasePro.Unauthenticated.API as CB
import Control.Exception.Base import Control.Exception.Base
import Control.Monad import Control.Monad
import Control.Monad.IO.Class import Control.Monad.IO.Class
@ -17,9 +14,9 @@ import Data.List.Split
import qualified Data.Map as M import qualified Data.Map as M
import Data.Maybe import Data.Maybe
import qualified Data.Text import qualified Data.Text
import Data.Time
import qualified GI.Gtk as Gtk import qualified GI.Gtk as Gtk
import qualified GI.Gtk.Objects.Overlay as Gtk import qualified GI.Gtk.Objects.Overlay as Gtk
import Data.Time
import Network.HostName import Network.HostName
import StatusNotifier.Tray import StatusNotifier.Tray
import System.Directory import System.Directory
@ -43,6 +40,7 @@ import System.Taffybar.Information.X11DesktopInfo
import System.Taffybar.SimpleConfig import System.Taffybar.SimpleConfig
import System.Taffybar.Util import System.Taffybar.Util
import System.Taffybar.Widget import System.Taffybar.Widget
import System.Taffybar.Widget.Crypto
import System.Taffybar.Widget.Generic.Icon import System.Taffybar.Widget.Generic.Icon
import System.Taffybar.Widget.Generic.PollingGraph import System.Taffybar.Widget.Generic.PollingGraph
import System.Taffybar.Widget.Generic.PollingLabel import System.Taffybar.Widget.Generic.PollingLabel
@ -51,16 +49,11 @@ import System.Taffybar.Widget.Workspaces
import Text.Printf import Text.Printf
import Text.Read hiding (lift) import Text.Read hiding (lift)
getDaysCandles productString = do setClassAndBoundingBoxes :: MonadIO m => Data.Text.Text -> Gtk.Widget -> m Gtk.Widget
oneDayAgo <- addUTCTime(-60*60*24) <$> getCurrentTime setClassAndBoundingBoxes klass = buildContentsBox >=> flip widgetSetClassGI klass
let candles = CB.candles (CB.ProductId productString) (Just oneDayAgo) Nothing CB.Minute
CB.run CB.Production (candles CB.userAgent)
coinbaseProductLabel productString =
pollingLabelNew 60.0 $ Data.Text.pack . show . CB.unPrice . CB.close . head <$>
getDaysCandles (Data.Text.pack productString)
deocrateWithSetClassAndBoxes :: MonadIO m => Data.Text.Text -> m Gtk.Widget -> m Gtk.Widget
deocrateWithSetClassAndBoxes klass builder = builder >>= setClassAndBoundingBoxes klass
mkRGBA (r, g, b, a) = (r/256, g/256, b/256, a/256) mkRGBA (r, g, b, a) = (r/256, g/256, b/256, a/256)
blue = mkRGBA (42, 99, 140, 256) blue = mkRGBA (42, 99, 140, 256)
@ -143,80 +136,71 @@ main = do
homeDirectory <- getHomeDirectory homeDirectory <- getHomeDirectory
cssFilePath <- cssFilePath <-
traverse (getUserConfigFile "taffybar") $ lookup hostName cssFileByHostname traverse (getUserConfigFile "taffybar") $ lookup hostName cssFileByHostname
let cpuGraph = pollingGraphNew cpuCfg 5 cpuCallback
memoryGraph = pollingGraphNew memCfg 5 memCallback
myIcons = scaledWindowIconPixbufGetter $
getWindowIconPixbufFromChrome <|||>
unscaledDefaultGetWindowIconPixbuf <|||>
(\size _ -> lift $ loadPixbufByName size "application-default-icon")
layout = layoutNew defaultLayoutConfig
windows = windowsNew defaultWindowsConfig
myWorkspacesConfig = let myCPU = deocrateWithSetClassAndBoxes "cpu" $ pollingGraphNew cpuCfg 5 cpuCallback
defaultWorkspacesConfig myMem = deocrateWithSetClassAndBoxes "mem" $ pollingGraphNew memCfg 5 memCallback
{ underlineHeight = 3 myNet = deocrateWithSetClassAndBoxes "net" $ networkGraphNew netCfg Nothing
, underlinePadding = 2 myLayout = deocrateWithSetClassAndBoxes "layout" $ layoutNew defaultLayoutConfig
, minIcons = 1 myWindows = deocrateWithSetClassAndBoxes "windows" $ windowsNew defaultWindowsConfig
, getWindowIconPixbuf = myIcons myWorkspaces =
, widgetGap = 0 flip widgetSetClassGI "workspaces" =<<
, showWorkspaceFn = hideEmpty workspacesNew defaultWorkspacesConfig
, updateRateLimitMicroseconds = 100000 { minIcons = 1
, labelSetter = workspaceNamesLabelSetter , getWindowIconPixbuf =
, widgetBuilder = buildLabelOverlayController scaledWindowIconPixbufGetter $
} getWindowIconPixbufFromChrome <|||>
workspaces = workspacesNew myWorkspacesConfig unscaledDefaultGetWindowIconPixbuf <|||>
myClock = (\size _ -> lift $ loadPixbufByName size "application-default-icon")
textClockNewWith , widgetGap = 0
defaultClockConfig , showWorkspaceFn = hideEmpty
{ clockUpdateStrategy = RoundedTargetInterval 60 0.0 , updateRateLimitMicroseconds = 100000
, clockFormatString = "%a %b %_d %I:%M %p" , labelSetter = workspaceNamesLabelSetter
} , widgetBuilder = buildLabelOverlayController
}
myClock = deocrateWithSetClassAndBoxes "clock" $
textClockNewWith
defaultClockConfig
{ clockUpdateStrategy = RoundedTargetInterval 60 0.0
, clockFormatString = "%a %b %_d, %I:%M %p"
}
myICP = deocrateWithSetClassAndBoxes "icp" $ cryptoPriceLabelWithIcon @"ICP-USD"
myBTC = deocrateWithSetClassAndBoxes "btc" $ cryptoPriceLabelWithIcon @"BTC-USD"
myETH = deocrateWithSetClassAndBoxes "eth" $ cryptoPriceLabelWithIcon @"ETH-USD"
myTray = deocrateWithSetClassAndBoxes "tray" $
sniTrayNewFromParams defaultTrayParams { trayLeftClickAction = PopupMenu
, trayRightClickAction = Activate
}
myMpris = deocrateWithSetClassAndBoxes "mpris" mpris2New
myBatteryIcon = deocrateWithSetClassAndBoxes "battery-icon" batteryIconNew
myBatteryText =
deocrateWithSetClassAndBoxes "battery-text" $ textBatteryNew "$percentage$%"
fullEndWidgets = fullEndWidgets =
map (>>= buildContentsBox) [ myTray
[ myClock , myICP
, sniTrayNewFromParams defaultTrayParams { trayLeftClickAction = PopupMenu , myBTC
, trayRightClickAction = Activate , myETH
} , myCPU
, coinbaseProductLabel "ICP-USD" , myMem
, coinbaseProductLabel "ICP-BTC" , myNet
, coinbaseProductLabel "BTC-USD" , myMpris
, coinbaseProductLabel "ETH-USD" ]
, cpuGraph
, memoryGraph
, networkGraphNew netCfg Nothing
-- , networkMonitorNew defaultNetFormat Nothing >>= setMinWidth 200
-- , fsMonitorNew 60 ["/dev/sdd2"]
, mpris2New
]
shortLaptopEndWidgets = shortLaptopEndWidgets =
map (>>= buildContentsBox) [ myBatteryIcon
[ batteryIconNew , myBatteryText
, textBatteryNew "$percentage$%" , myClock
, myClock , myTray
, sniTrayNew , myICP
, coinbaseProductLabel "ICP-USD" , myMpris
, mpris2New ]
]
longLaptopEndWidgets =
map (>>= buildContentsBox)
[ batteryIconNew
, textBatteryNew "$percentage$%"
, textClockNewWith defaultClockConfig
, sniTrayNew
, cpuGraph
, memoryGraph
, networkGraphNew netCfg Nothing
, mpris2New
]
baseConfig = baseConfig =
defaultSimpleTaffyConfig defaultSimpleTaffyConfig
{ startWidgets = { startWidgets = [myWorkspaces, myLayout, myWindows]
workspaces : map (>>= buildContentsBox) [layout, windows]
, endWidgets = fullEndWidgets , endWidgets = fullEndWidgets
, barPosition = Top , barPosition = Top
, barPadding = 0 , barPadding = 0
, barHeight = 50 , barHeight = 50
, cssPath = cssFilePath , cssPath = cssFilePath
, startupHook = void $ setCMCAPIKey "f9e66366-9d42-4c6e-8d40-4194a0aaa329"
} }
selectedConfig = selectedConfig =
fromMaybe baseConfig $ lookup hostName fromMaybe baseConfig $ lookup hostName
@ -234,7 +218,7 @@ main = do
) )
] ]
simpleTaffyConfig = selectedConfig simpleTaffyConfig = selectedConfig
{ centerWidgets = [] { centerWidgets = [ myClock ]
-- , endWidgets = [] -- , endWidgets = []
-- , startWidgets = [] -- , startWidgets = []
} }