[taffybar] Add custom padding values

This commit is contained in:
Ivan Malison 2017-03-05 18:30:55 -08:00
parent 0a3239264f
commit f3fd491196
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8
2 changed files with 56 additions and 44 deletions

View File

@ -1,7 +1,6 @@
module Main where module Main where
import Control.Exception.Base import Control.Exception.Base
import Data.Char (toLower)
import Data.List import Data.List
import Data.Maybe import Data.Maybe
import qualified Graphics.UI.Gtk as Gtk import qualified Graphics.UI.Gtk as Gtk
@ -13,13 +12,14 @@ import System.FilePath.Posix
import System.Information.CPU import System.Information.CPU
import System.Information.Memory import System.Information.Memory
import System.Taffybar import System.Taffybar
import System.Taffybar.IconImages import System.Taffybar.LayoutSwitcher
import System.Taffybar.MPRIS2 import System.Taffybar.MPRIS2
import System.Taffybar.Pager import System.Taffybar.Pager
import System.Taffybar.SimpleClock import System.Taffybar.SimpleClock
import System.Taffybar.Systray import System.Taffybar.Systray
import System.Taffybar.TaffyPager import System.Taffybar.TaffyPager
import System.Taffybar.Widgets.PollingGraph import System.Taffybar.Widgets.PollingGraph
import System.Taffybar.WindowSwitcher
import System.Taffybar.WorkspaceHUD import System.Taffybar.WorkspaceHUD
import Text.Printf import Text.Printf
import Text.Read import Text.Read
@ -32,13 +32,6 @@ cpuCallback = do
(_, systemLoad, totalLoad) <- cpuLoad (_, systemLoad, totalLoad) <- cpuLoad
return [totalLoad, systemLoad] return [totalLoad, systemLoad]
resourcesDirectory file = ("/home" </> "imalison" </> ".lib" </> "resources" </> file)
fallbackIcons _ klass
| isInfixOf "URxvt" klass = IIFilePath $ resourcesDirectory "urxvt.png"
| isInfixOf "Kodi" klass = IIFilePath $ resourcesDirectory "kodi.png"
| otherwise = IIColor $ (0xFF, 0xFF, 0, 0xFF)
underlineWidget cfg buildWidget name = do underlineWidget cfg buildWidget name = do
w <- buildWidget w <- buildWidget
t <- T.tableNew 2 1 False t <- T.tableNew 2 1 False
@ -49,50 +42,61 @@ underlineWidget cfg buildWidget name = do
T.tableAttach t w 0 1 0 1 [T.Expand] [T.Expand] 0 0 T.tableAttach t w 0 1 0 1 [T.Expand] [T.Expand] 0 0
T.tableAttach t u 0 1 1 2 [T.Fill] [T.Shrink] 0 0 T.tableAttach t u 0 1 1 2 [T.Fill] [T.Shrink] 0 0
Gtk.widgetSetName u $ (printf "%s-underline" name :: String) Gtk.widgetSetName u (printf "%s-underline" name :: String)
Gtk.widgetShowAll t Gtk.widgetShowAll t
return $ Gtk.toWidget t return $ Gtk.toWidget t
myGetIconInfo =
windowTitleClassIconGetter False fallbackIcons
main = do main = do
monEither <- monEither <-
(try $ getEnv "TAFFYBAR_MONITOR") :: IO (Either SomeException String) (try $ getEnv "TAFFYBAR_MONITOR") :: IO (Either SomeException String)
let monNumber = homeDirectory <- getHomeDirectory
let resourcesDirectory file =
(homeDirectory </> ".lib" </> "resources" </> file)
fallbackIcons _ klass
| "URxvt" `isInfixOf` klass =
IIFilePath $ resourcesDirectory "urxvt.png"
| "Kodi" `isInfixOf` klass = IIFilePath $ resourcesDirectory "kodi.png"
| otherwise = IIColor (0xFF, 0xFF, 0, 0xFF)
myGetIconInfo = windowTitleClassIconGetter False fallbackIcons
monNumber =
case monEither of case monEither of
Left _ -> 0 Left _ -> 0
Right monString -> fromMaybe 0 $ readMaybe monString Right monString -> fromMaybe 0 $ readMaybe monString
let monFilter = monFilter =
case monEither of case monEither of
Left _ -> allMonitors Left _ -> allMonitors
Right monString -> Nothing Right _ -> Nothing
let memCfg = memCfg =
defaultGraphConfig defaultGraphConfig
{graphDataColors = [(1, 0, 0, 1)], graphLabel = Just "mem"} { graphDataColors = [(0.129, 0.588, 0.953, 1)]
, graphLabel = Just "mem"
}
cpuCfg = cpuCfg =
defaultGraphConfig defaultGraphConfig
{ graphDataColors = [(0, 1, 0, 1), (1, 0, 1, 0.5)] { graphDataColors = [(0, 1, 0, 1), (1, 0, 1, 0.5)]
, graphLabel = Just "cpu" , graphLabel = Just "cpu"
} }
let clock = textClockNew Nothing "%a %b %_d %r" 1 clock = textClockNew Nothing "%a %b %_d %r" 1
pagerConfig = defaultPagerConfig {
useImages = True
}
mpris = mpris2New mpris = mpris2New
mem = pollingGraphNew memCfg 1 memCallback mem = pollingGraphNew memCfg 1 memCallback
cpu = pollingGraphNew cpuCfg 0.5 cpuCallback cpu = pollingGraphNew cpuCfg 0.5 cpuCallback
tray = systrayNew tray = do
tray <- systrayNew
container <- Gtk.eventBoxNew
Gtk.containerAdd container tray
Gtk.widgetSetName container "Taffytray"
Gtk.widgetSetName tray "Taffytray"
return $ Gtk.toWidget container
hudConfig = hudConfig =
defaultWorkspaceHUDConfig defaultWorkspaceHUDConfig
{ underlineHeight = 3 { underlineHeight = 3
, underlinePadding = 1 , underlinePadding = 5
, minWSWidgetSize = Nothing , minWSWidgetSize = Nothing
, minIcons = 3 , minIcons = 3
, getIconInfo = myGetIconInfo , getIconInfo = myGetIconInfo
, windowIconSize = 32 , windowIconSize = 25
, widgetGap = 0 , widgetGap = 0
-- , widgetBuilder = buildBorderButtonController -- , widgetBuilder = buildBorderButtonController
, showWorkspaceFn = hideEmpty , showWorkspaceFn = hideEmpty
@ -101,25 +105,31 @@ main = do
, updateOnWMIconChange = True , updateOnWMIconChange = True
, debugMode = False , debugMode = False
, redrawIconsOnStateChange = True , redrawIconsOnStateChange = True
, innerPadding = 5
, outerPadding = 5
} }
hudPagerConfig = hudFromPagerConfig pagerConfig pagerConfig = defaultPagerConfig {useImages = True}
hud = taffyPagerHUDNew pagerConfig hudConfig
pager = taffyPagerNew pagerConfig pager = taffyPagerNew pagerConfig
let underline = underlineWidget hudConfig makeUnderline = underlineWidget hudConfig
pgr <- pagerNew pagerConfig
let hud = buildWorkspaceHUD hudConfig pgr
los = makeUnderline (layoutSwitcherNew pgr) "red"
wnd = makeUnderline (windowSwitcherNew pgr) "teal"
defaultTaffybar defaultTaffybar
defaultTaffybarConfig defaultTaffybarConfig
{ startWidgets = [hud] { startWidgets = [hud, los, wnd]
, endWidgets = , endWidgets =
[ underline tray "yellow" [ makeUnderline tray "yellow"
, underline clock "teal" , makeUnderline clock "teal"
, underline mem "red" , makeUnderline mem "blue"
, underline cpu "green" , makeUnderline cpu "green"
, underline mpris "blue" , makeUnderline mpris "red"
] ]
, monitorNumber = monNumber , monitorNumber = monNumber
, monitorFilter = monFilter , monitorFilter = monFilter
, barPosition = Top , barPosition = Top
, barHeight = 40 , barHeight = 50
, widgetSpacing = 5 , widgetSpacing = 5
} }

View File

@ -6,7 +6,7 @@ style "taffybar-default" {
color["yellow"] = "#ffeb3b" color["yellow"] = "#ffeb3b"
color["orange"] = "#f4511e" color["orange"] = "#f4511e"
color["blue"] = "#2196f3" color["blue"] = "#2196f3"
color["red"] = "#E57373" color["red"] = "#F44336"
color["dgrey"] = "#212121" color["dgrey"] = "#212121"
color["ldgrey"] = "#424242" color["ldgrey"] = "#424242"
color["lgrey"] = "#bdbdbd" color["lgrey"] = "#bdbdbd"
@ -18,18 +18,13 @@ style "taffybar-default" {
bg[NORMAL] = @dgrey bg[NORMAL] = @dgrey
fg[NORMAL] = @white fg[NORMAL] = @white
text[NORMAL] = @white text[NORMAL] = @black
fg[PRELIGHT] = @green fg[PRELIGHT] = @green
bg[PRELIGHT] = @teal bg[PRELIGHT] = @teal
} }
style "taffybar-active-window" = "taffybar-default" { style "taffybar-active-window" = "taffybar-default" {
bg[NORMAL] = @black
bg[PRELIGHT] = @black
bg[SELECTED] = @black
bg[ACTIVE] = @black
fg[NORMAL] = @yellow fg[NORMAL] = @yellow
text[NORMAL] = @red
} }
style "taffybar-notification-button" = "taffybar-default" { style "taffybar-notification-button" = "taffybar-default" {
@ -41,7 +36,7 @@ style "taffybar-workspace-border-active" = "taffybar-default" {
bg[NORMAL] = @yellow bg[NORMAL] = @yellow
} }
style "taffybar-workspace-border-visible" = "taffybar-default" { style "taffybar-workspace-border-visible" = "taffybar-default" {
bg[NORMAL] = @red bg[NORMAL] = @green
} }
style "taffybar-workspace-border-empty" = "taffybar-default" { style "taffybar-workspace-border-empty" = "taffybar-default" {
bg[NORMAL] = @blue bg[NORMAL] = @blue
@ -83,9 +78,14 @@ style "green" = "taffybar-default" {
style "teal" = "taffybar-default" { style "teal" = "taffybar-default" {
bg[NORMAL]= @teal bg[NORMAL]= @teal
} }
style "bgrey" = "taffybar-default" {
bg[NORMAL]= @bgrey
}
widget "Taffybar*" style "taffybar-default" widget "Taffybar*" style "taffybar-default"
widget "Taffybar*WindowSwitcher*" style "taffybar-active-window" widget "*menu*" style "taffybar-default"
widget "*WindowSwitcher*" style "taffybar-default"
widget "*Taffybar*WindowSwitcher*" style "taffybar-active-window"
widget "*NotificationCloseButton" style "taffybar-notification-button" widget "*NotificationCloseButton" style "taffybar-notification-button"
widget "*Workspace-underline*-active*" style "taffybar-workspace-border-active" widget "*Workspace-underline*-active*" style "taffybar-workspace-border-active"
@ -113,3 +113,5 @@ widget "*yellow-underline*" style "yellow"
widget "*orange-underline*" style "orange" widget "*orange-underline*" style "orange"
widget "*green-underline*" style "green" widget "*green-underline*" style "green"
widget "*teal-underline*" style "teal" widget "*teal-underline*" style "teal"
widget "*bgrey-underline*" style "bgrey"
widget "*Taffytray*" style "taffybar-default"