[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

@ -1,44 +1,45 @@
{-# LANGUAGE PackageImports #-} {-# LANGUAGE PackageImports #-}
module Main where module Main where
import Control.Exception.Base import Control.Exception.Base
import Control.Monad import Control.Monad
import Control.Monad.IO.Class import Control.Monad.IO.Class
import Control.Monad.Trans.Class import Control.Monad.Trans.Class
import Control.Monad.Trans.Reader import Control.Monad.Trans.Reader
import qualified Data.ByteString.Char8 as BS import qualified Data.ByteString.Char8 as BS
import Data.List import Data.List
import Data.List.Split import Data.List.Split
import qualified Data.Map as M import qualified Data.Map as M
import Data.Maybe import Data.Maybe
import qualified GitHub.Auth as Auth import qualified GitHub.Auth as Auth
import StatusNotifier.Tray import StatusNotifier.Tray
import System.Directory import System.Directory
import System.Environment import System.Environment
import System.FilePath.Posix import System.FilePath.Posix
import System.Glib.GObject import System.Glib.GObject
import System.IO import System.IO
import System.Log.Handler.Simple import System.Log.Handler.Simple
import System.Log.Logger import System.Log.Logger
import System.Process import System.Process
import System.Taffybar import System.Taffybar
import System.Taffybar.Auth import System.Taffybar.Auth
import System.Taffybar.Compat.GtkLibs import System.Taffybar.Compat.GtkLibs
import System.Taffybar.DBus import System.Taffybar.DBus
import System.Taffybar.DBus.Toggle import System.Taffybar.DBus.Toggle
import System.Taffybar.Hooks import System.Taffybar.Hooks
import System.Taffybar.Information.CPU import System.Taffybar.Information.CPU
import System.Taffybar.Information.EWMHDesktopInfo 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.Widget import System.Taffybar.Util
import System.Taffybar.Widget.Generic.PollingGraph import System.Taffybar.Widget
import System.Taffybar.Widget.Generic.PollingLabel import System.Taffybar.Widget.Generic.PollingGraph
import System.Taffybar.Widget.Util import System.Taffybar.Widget.Generic.PollingLabel
import System.Taffybar.Widget.Workspaces import System.Taffybar.Widget.Util
import Text.Printf import System.Taffybar.Widget.Workspaces
import Text.Read hiding (lift) import Text.Printf
import Text.Read hiding (lift)
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)
@ -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,43 +137,45 @@ 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)
, batteryIconNew [ textBatteryNew "$percentage$%"
, sniTrayNew , batteryIconNew
, textClockNew Nothing "%a %b %_d %r" 1
, sniTrayNew
-- , github -- , github
, cpu , cpu
, mem , mem
, networkGraphNew netCfg Nothing , networkGraphNew netCfg Nothing
-- , networkMonitorNew defaultNetFormat Nothing >>= setMinWidth 200 -- , networkMonitorNew defaultNetFormat Nothing >>= setMinWidth 200
-- , fsMonitorNew 60 ["/dev/sdd2"] -- , fsMonitorNew 60 ["/dev/sdd2"]
, 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")