summaryrefslogtreecommitdiff
path: root/bar
diff options
context:
space:
mode:
authorhhvn <dev@hhvn.uk>2023-10-31 11:36:24 +0000
committerhhvn <dev@hhvn.uk>2023-10-31 11:36:24 +0000
commit76dc78859b31cd15c8327e64b7684fbc2063a0b4 (patch)
tree3bfb42ba66e00a053facb263e5936f842eab42e6 /bar
parentc20f2aa6185c8ac1f7f309c469ea43acd8e8719c (diff)
Successfully destroys and recreates windows upon bspwm reload
Diffstat (limited to 'bar')
-rw-r--r--bar/bar.go39
1 files changed, 28 insertions, 11 deletions
diff --git a/bar/bar.go b/bar/bar.go
index 3c5dfad..402ab55 100644
--- a/bar/bar.go
+++ b/bar/bar.go
@@ -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
}