[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
import Control.Exception.Base
import Data.Char (toLower)
import Data.List
import Data.Maybe
import qualified Graphics.UI.Gtk as Gtk
@ -13,13 +12,14 @@ import System.FilePath.Posix
import System.Information.CPU
import System.Information.Memory
import System.Taffybar
import System.Taffybar.IconImages
import System.Taffybar.LayoutSwitcher
import System.Taffybar.MPRIS2
import System.Taffybar.Pager
import System.Taffybar.SimpleClock
import System.Taffybar.Systray
import System.Taffybar.TaffyPager
import System.Taffybar.Widgets.PollingGraph
import System.Taffybar.WindowSwitcher
import System.Taffybar.WorkspaceHUD
import Text.Printf
import Text.Read
@ -32,13 +32,6 @@ cpuCallback = do
(_, systemLoad, totalLoad) <- cpuLoad
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
w <- buildWidget
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 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
return $ Gtk.toWidget t
myGetIconInfo =
windowTitleClassIconGetter False fallbackIcons
main = do
monEither <-
(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
Left _ -> 0
Right monString -> fromMaybe 0 $ readMaybe monString
let monFilter =
monFilter =
case monEither of
Left _ -> allMonitors
Right monString -> Nothing
let memCfg =
Right _ -> Nothing
memCfg =
defaultGraphConfig
{graphDataColors = [(1, 0, 0, 1)], graphLabel = Just "mem"}
{ graphDataColors = [(0.129, 0.588, 0.953, 1)]
, graphLabel = Just "mem"
}
cpuCfg =
defaultGraphConfig
{ graphDataColors = [(0, 1, 0, 1), (1, 0, 1, 0.5)]
, graphLabel = Just "cpu"
}
let clock = textClockNew Nothing "%a %b %_d %r" 1
pagerConfig = defaultPagerConfig {
useImages = True
}
clock = textClockNew Nothing "%a %b %_d %r" 1
mpris = mpris2New
mem = pollingGraphNew memCfg 1 memCallback
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 =
defaultWorkspaceHUDConfig
{ underlineHeight = 3
, underlinePadding = 1
, underlinePadding = 5
, minWSWidgetSize = Nothing
, minIcons = 3
, getIconInfo = myGetIconInfo
, windowIconSize = 32
, windowIconSize = 25
, widgetGap = 0
-- , widgetBuilder = buildBorderButtonController
, showWorkspaceFn = hideEmpty
@ -101,25 +105,31 @@ main = do
, updateOnWMIconChange = True
, debugMode = False
, redrawIconsOnStateChange = True
, innerPadding = 5
, outerPadding = 5
}
hudPagerConfig = hudFromPagerConfig pagerConfig
hud = taffyPagerHUDNew pagerConfig hudConfig
pagerConfig = defaultPagerConfig {useImages = True}
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
defaultTaffybarConfig
{ startWidgets = [hud]
{ startWidgets = [hud, los, wnd]
, endWidgets =
[ underline tray "yellow"
, underline clock "teal"
, underline mem "red"
, underline cpu "green"
, underline mpris "blue"
[ makeUnderline tray "yellow"
, makeUnderline clock "teal"
, makeUnderline mem "blue"
, makeUnderline cpu "green"
, makeUnderline mpris "red"
]
, monitorNumber = monNumber
, monitorFilter = monFilter
, barPosition = Top
, barHeight = 40
, barHeight = 50
, widgetSpacing = 5
}

View File

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