diff options
Diffstat (limited to 'bar/bar.go')
| -rw-r--r-- | bar/bar.go | 39 |
1 files changed, 28 insertions, 11 deletions
@@ -42,8 +42,9 @@ var conf = struct { "/usr/share/fonts/TTF/DejaVuSansMono.ttf", 11.0, 1 } -var bars *list.List -var font *truetype.Font +var bars *list.List +var font *truetype.Font +var stoploop chan bool type bar struct { X *xgb.Conn @@ -162,6 +163,7 @@ func (b *bar) draw() { func (b *bar) destroy() { b.Mon.TopPadding(0) + xproto.DestroyWindow(b.X, b.w) } type eventwrap struct { @@ -198,8 +200,9 @@ func Init(state *bspc.State) (*Handle, error) { h.NewState = make(chan *bspc.State) h.Err = make(chan error) - events := make(chan *eventwrap) - xstop := make(chan bool, 1) + events := make(chan *eventwrap) + stoploop = make(chan bool, 1) + xstop := make(chan bool, 1) go func() { for { ev, err := x.WaitForEvent() @@ -229,15 +232,16 @@ func Init(state *bspc.State) (*Handle, error) { continue } - switch e.Ev.(type) { - case xproto.DestroyNotifyEvent: - h.Err <- fmt.Errorf("Window destroyed") - return - default: - } + // switch e.Ev.(type) { + // case xproto.DestroyNotifyEvent: + // h.Err <- fmt.Errorf("Window destroyed") + // return + // default: + // } case id := <- h.Destroy: destroy(id) case id := <- h.Create: + if getbar(id) != nil { break } if err := create(x, xu, screen, state.GetMon(id)); err != nil { h.Err <- fmt.Errorf("Couldn't create window: %s\n", err) return @@ -248,6 +252,8 @@ func Init(state *bspc.State) (*Handle, error) { v.Mon = state.GetMon(v.Mon.ID) go v.draw() } + case <- stoploop: + return } } }() @@ -255,6 +261,16 @@ func Init(state *bspc.State) (*Handle, error) { return &h, nil } +func getbar(monid int) (*bar) { + for e := bars.Front(); e != nil; e = e.Next() { + v := e.Value.(*bar) + + if v.Mon.ID == monid { return v } + } + + return nil +} + func create(x *xgb.Conn, xu *xgbutil.XUtil, scr *xproto.ScreenInfo, m *bspc.Monitor) (error) { var b bar @@ -284,7 +300,7 @@ func destroy(monid int) (bool) { /* A monid of -1 means that we're doing the bar.Cleanup schermoodle today */ - if monid == -1 || monid > 0 && v.Mon.ID == int(monid) { + if monid == -1 || monid > 0 && v.Mon.ID == monid { v.destroy() bars.Remove(e) if monid != -1 { return true } @@ -297,4 +313,5 @@ func destroy(monid int) (bool) { func Cleanup() { destroy(-1) + stoploop <- true } |