From 0b3d4426cb585ceade7a27ed28cfe08f1710738d Mon Sep 17 00:00:00 2001 From: hhvn Date: Fri, 2 Feb 2024 20:40:07 +0000 Subject: Pass slice of Blocks via NewBlocks --- bar/bar.go | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'bar/bar.go') diff --git a/bar/bar.go b/bar/bar.go index 2a543d3..e7d66ff 100644 --- a/bar/bar.go +++ b/bar/bar.go @@ -76,10 +76,14 @@ func (b *bar) drawRect(x, y, w, h int, c color.Color, fill bool) { drw.DrawRect(b.i, x, y, w, h, c, fill) } -func (b bar) draw(state *bspc.State, blocks *status.Blocks) { +func (b bar) draw(state *bspc.State, blocks []*status.Block) { var bg color.Color var filled bool + if blocks == nil { + return + } + mon, err := b.getmon(state) if err != nil { return @@ -137,29 +141,24 @@ func (b bar) draw(state *bspc.State, blocks *status.Blocks) { cx += ax + 2 } - cx = int(mon.Rectangle.Width) - 6 - for i := blocks.Len() - 1; i >= 0; i -= 1 { - s, ok := blocks.Get(i) - if ok { + cx = int(mon.Rectangle.Width) + for _, s := range blocks { + if s != nil { cx -= s.W cx -= config.StatusPad } } - cx += config.StatusPad - cx -= 6 b.drawRect(cx, 0, int(mon.Rectangle.Width) - cx, int(config.H), config.Status, true) - cx = int(mon.Rectangle.Width) - 6 - for i := blocks.Len() - 1; i >= 0; i -= 1 { - s, ok := blocks.Get(i) - if ok { - cx -= s.W + cx += config.StatusPad / 2 + for _, s := range blocks { + if s != nil { drw.AddImg(b.i, cx, s.W, s.I) - cx -= config.StatusPad + cx += s.W + config.StatusPad } } @@ -176,8 +175,8 @@ var Err = make(chan error) var finalstate *bspc.State = nil func init() { - var state *bspc.State = nil - var blocks *status.Blocks = nil + var state *bspc.State = nil + var blocks []*status.Block = nil go func() { defer func() { -- cgit v1.2.3