Browse Source

~/.config/taffybar: Add memory usage widget.

Surprisingly, only calling pollingLabelNew doesn't do the job, we have
to call Graphics.UI.Gtk.widgetShowAll, too.
Lucas Stadler 12 years ago
parent
commit
1df48980ff
1 changed files with 14 additions and 2 deletions
  1. 14 2
      .config/taffybar/taffybar.hs

+ 14 - 2
.config/taffybar/taffybar.hs

4
import System.Taffybar.XMonadLog
4
import System.Taffybar.XMonadLog
5
import System.Taffybar.SimpleClock
5
import System.Taffybar.SimpleClock
6
import System.Taffybar.Widgets.PollingGraph
6
import System.Taffybar.Widgets.PollingGraph
7
import System.Taffybar.Widgets.PollingLabel
7
import System.Information.CPU
8
import System.Information.CPU
9
import System.Information.Memory (parseMeminfo, memoryUsedRatio)
10
import Graphics.UI.Gtk (widgetShowAll)
8
11
9
cpuCallback = do
12
cpuCallback = do
10
    (_, systemLoad, totalLoad) <- cpuLoad
13
    (_, systemLoad, totalLoad) <- cpuLoad
11
    return [ totalLoad, systemLoad ]
14
    return [ totalLoad, systemLoad ]
12
15
16
formatMeminfo m = "Mem: " ++ memPercentage ++ "%"
17
    where memPercentage = show . truncate . ((*) 100) $ memoryUsedRatio m
18
19
textMemoryNew intervalSeconds = do
20
    memLabel <- pollingLabelNew "" intervalSeconds (parseMeminfo >>= return . formatMeminfo)
21
    widgetShowAll memLabel
22
    return memLabel
23
13
main = do
24
main = do
14
    let cpuCfg = defaultGraphConfig {
25
    let cpuCfg = defaultGraphConfig {
15
            graphDataColors = [(0, 1, 0, 1), (1, 0, 1, 0.5)]
26
            graphDataColors = [(0, 1, 0, 1), (1, 0, 1, 0.5)]
18
        log = xmonadLogNew
29
        log = xmonadLogNew
19
        tray = systrayNew
30
        tray = systrayNew
20
        cpu = pollingGraphNew cpuCfg 3 cpuCallback
31
        cpu = pollingGraphNew cpuCfg 3 cpuCallback
21
        battery = textBatteryNew "%d%%" 30
32
        battery = textBatteryNew "Bat: %d%%" 30
33
        memory = textMemoryNew 3
22
    defaultTaffybar defaultTaffybarConfig {
34
    defaultTaffybar defaultTaffybarConfig {
23
        barHeight = 15,
35
        barHeight = 15,
24
        startWidgets = [log],
36
        startWidgets = [log],
25
        endWidgets = [tray, clock, battery, cpu]
37
        endWidgets = [tray, clock, memory, battery, cpu]
26
    }
38
    }