hbspbar

[WIP] bspwm status bar
git clone https://hhvn.uk/hbspbar
git clone git://hhvn.uk/hbspbar
Log | Files | Refs

commit f63b94d614026e21bf6246440b9bda1f85197fbc
parent 77c48c8a8074cfb48f346b77760eb3d58a2716dc
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 27 Jan 2024 16:41:45 +0000

Reorganize bar/bar.go

Diffstat:
Mbar/bar.go | 54+++++++++++++++++++++++++++---------------------------
1 file changed, 27 insertions(+), 27 deletions(-)

diff --git a/bar/bar.go b/bar/bar.go @@ -28,7 +28,25 @@ type bar struct { redraw chan drawinfo } -func (b *bar) init(state *bspc.State) error { +func create(state *bspc.State, id int) (error) { + var b bar + + if err := b.init(id, state); err != nil { + return err + } + + if bars == nil { + bars = make(map[int]*bar) + } + + bars[b.id] = &b + return nil +} + +func (b *bar) init(id int, state *bspc.State) error { + b.id = id + b.i = nil + mon, err := b.getmon(state) if err != nil { return err } @@ -61,6 +79,14 @@ func (b *bar) init(state *bspc.State) error { return nil } +func (b *bar) destroy(state *bspc.State) { + close(b.redraw) + mon, _ := b.getmon(state) + if (mon != nil) { + mon.TopPadding(0) + } +} + func (b bar) getmon(state *bspc.State) (*bspc.Monitor, error) { return state.GetMon(b.id) } @@ -166,14 +192,6 @@ func (b bar) draw(d drawinfo) { b.w.Paint(b.i) } -func (b *bar) destroy(state *bspc.State) { - close(b.redraw) - mon, _ := b.getmon(state) - if (mon != nil) { - mon.TopPadding(0) - } -} - var Create = make(chan int) var Destroy = make(chan int) var NewState = make(chan *bspc.State) @@ -241,24 +259,6 @@ func init() { }() } -func create(state *bspc.State, id int) (error) { - var b bar - - b.id = id - b.i = nil - - if err := b.init(state); err != nil { - return err - } - - if bars == nil { - bars = make(map[int]*bar) - } - - bars[b.id] = &b - return nil -} - func Cleanup() { if finalstate != nil { for _, b := range bars {