[taffybar] Use new system for specifying custom icons in workspaces

This commit is contained in:
Ivan Malison 2018-05-27 23:43:28 -07:00
parent 251adbd740
commit 433118298d
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8
2 changed files with 82 additions and 73 deletions

@ -1 +1 @@
Subproject commit e6f0bf2e08300e6dc5405131549fc21a6e9af7f0 Subproject commit b20fd99f934fbfdb5cfc021d01a0c4c4c189af29

View File

@ -32,6 +32,7 @@ import System.Taffybar.Information.EWMHDesktopInfo
import System.Taffybar.Information.Memory import System.Taffybar.Information.Memory
import System.Taffybar.Information.X11DesktopInfo import System.Taffybar.Information.X11DesktopInfo
import System.Taffybar.SimpleConfig import System.Taffybar.SimpleConfig
import System.Taffybar.Util
import System.Taffybar.Widget import System.Taffybar.Widget
import System.Taffybar.Widget.Generic.PollingGraph import System.Taffybar.Widget.Generic.PollingGraph
import System.Taffybar.Widget.Generic.PollingLabel import System.Taffybar.Widget.Generic.PollingLabel
@ -87,6 +88,10 @@ workspaceNamesLabelSetter workspace =
fromMaybe "" . lookup (workspaceIdx workspace) <$> fromMaybe "" . lookup (workspaceIdx workspace) <$>
liftX11Def [] getFullWorkspaceNames liftX11Def [] getFullWorkspaceNames
enableLogger logger level = do
logger <- getLogger logger
saveGlobalLogger $ setLevel level logger
logDebug = do logDebug = do
logger <- getLogger "System.Taffybar.Widget.Generic.AutoSizeImage" logger <- getLogger "System.Taffybar.Widget.Generic.AutoSizeImage"
saveGlobalLogger $ setLevel DEBUG logger saveGlobalLogger $ setLevel DEBUG logger
@ -102,25 +107,27 @@ logDebug = do
main = do main = do
homeDirectory <- getHomeDirectory homeDirectory <- getHomeDirectory
-- logDebug -- logDebug
-- enableLogger "System.Taffybar.Widget.Util" DEBUG
-- enableLogger "System.Taffybar.Information.XDG.DesktopEntry" DEBUG
-- enableLogger "System.Taffybar.WindowIcon" DEBUG
let resourcesDirectory = homeDirectory </> ".lib" </> "resources" let resourcesDirectory = homeDirectory </> ".lib" </> "resources"
inResourcesDirectory file = resourcesDirectory </> file inResourcesDirectory file = resourcesDirectory </> file
highContrastDirectory = highContrastDirectory =
"/" </> "usr" </> "share" </> "icons" </> "HighContrast" </> "256x256" "/" </> "usr" </> "share" </> "icons" </> "HighContrast" </> "256x256"
inHighContrastDirectory file = highContrastDirectory </> file inHighContrastDirectory file = highContrastDirectory </> file
makeIcon = return . IIFilePath . inResourcesDirectory getIconFileName w@WindowData {windowTitle = title, windowClass = klass}
myGetIconInfo w@WindowData {windowTitle = title, windowClass = klass} -- | "URxvt" `isInfixOf` klass = Just "urxvt.png"
| "URxvt" `isInfixOf` klass = makeIcon "urxvt.png" -- | "Termite" `isInfixOf` klass = Just "urxvt.png"
| "Termite" `isInfixOf` klass = makeIcon "urxvt.png" -- | "Kodi" `isInfixOf` klass = Just "kodi.png"r
| "Kodi" `isInfixOf` klass = makeIcon "kodi.png"
| "@gmail.com" `isInfixOf` title && | "@gmail.com" `isInfixOf` title &&
"chrome" `isInfixOf` klass && "Gmail" `isInfixOf` title = "chrome" `isInfixOf` klass && "Gmail" `isInfixOf` title =
makeIcon "gmail.png" Just "gmail.png"
| otherwise = do | otherwise = Nothing
res <- defaultGetIconInfo w myIcons =
return $ addCustomIconsAndFallback
case res of (fmap inResourcesDirectory . getIconFileName)
IINone -> IIFilePath $ inResourcesDirectory "exe-icon.png" (inResourcesDirectory "exe-icon.png")
_ -> res (getWindowIconPixbufFromClass <|||> getWindowIconPixbufFromEWMH)
cpu = pollingGraphNew cpuCfg 0.5 cpuCallback cpu = pollingGraphNew cpuCfg 0.5 cpuCallback
mem = pollingGraphNew memCfg 1 memCallback mem = pollingGraphNew memCfg 1 memCallback
layout = layoutNew defaultLayoutConfig layout = layoutNew defaultLayoutConfig
@ -130,22 +137,25 @@ main = do
{ underlineHeight = 3 { underlineHeight = 3
, underlinePadding = 2 , underlinePadding = 2
, minWSWidgetSize = Nothing , minWSWidgetSize = Nothing
, minIcons = 1 , minIcons = 3
, getIconInfo = myGetIconInfo , getWindowIconPixbuf = myIcons
-- , windowIconSize = 31 -- , windowIconSize = 31
, widgetGap = 0 , widgetGap = 0
, showWorkspaceFn = hideEmpty , showWorkspaceFn = const True
, updateRateLimitMicroseconds = 100000 , updateRateLimitMicroseconds = 100000
, labelSetter = workspaceNamesLabelSetter , labelSetter = workspaceNamesLabelSetter
} }
workspaces = workspacesNew myWorkspacesConfig workspaces = workspacesNew myWorkspacesConfig
baseConfig = defaultSimpleTaffyConfig baseConfig =
defaultSimpleTaffyConfig
{ startWidgets = { startWidgets =
workspaces : map (>>= buildContentsBox) [ layout, windows ] workspaces : map (>>= buildContentsBox) [layout, windows]
, endWidgets = map (>>= buildContentsBox) , endWidgets =
[ textClockNew Nothing "%a %b %_d %r" 1 map
, textBatteryNew "$percentage$% ($time$)" (>>= buildContentsBox)
[ textBatteryNew "$percentage$%"
, batteryIconNew , batteryIconNew
, textClockNew Nothing "%a %b %_d %r" 1
, sniTrayNew , sniTrayNew
-- , github -- , github
, cpu , cpu
@ -156,17 +166,16 @@ main = do
, mpris2New , mpris2New
] ]
, barPosition = Top , barPosition = Top
, barPadding = 5 , barPadding = 10
, barHeight = 50 , barHeight = 53
, widgetSpacing = 0
} }
simpleTaffyConfig = simpleTaffyConfig = baseConfig
baseConfig
-- { endWidgets = [] -- { endWidgets = []
-- , startWidgets = [flip widgetSetClass "Workspaces" =<< workspaces] -- , startWidgets = [flip widgetSetClass "Workspaces" =<< workspaces]
-- } -- }
startTaffybar $ withBatteryRefresh $ withLogServer $ withToggleServer $ startTaffybar $
toTaffyConfig simpleTaffyConfig withBatteryRefresh $
withLogServer $ withToggleServer $ toTaffyConfig simpleTaffyConfig
-- Local Variables: -- Local Variables:
-- flycheck-ghc-args: ("-Wno-missing-signatures") -- flycheck-ghc-args: ("-Wno-missing-signatures")