commit 0a5f0070526a2c32e7b7f65a50ecd993babfedfa
parent 764d1c63768b1bef017bb6c8c31b3dc8540a37fb
Author: hhvn <dev@hhvn.uk>
Date: Sat, 27 Jan 2024 15:26:47 +0000
Remove handle structure from bar/
Diffstat:
2 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/bar/bar.go b/bar/bar.go
@@ -174,15 +174,10 @@ func (b *bar) destroy(state *bspc.State) {
}
}
-// External interface
-type handle struct {
- Create chan int
- Destroy chan int
- NewState chan *bspc.State
- Err chan error
-}
-
-var Handle handle
+var Create = make(chan int)
+var Destroy = make(chan int)
+var NewState = make(chan *bspc.State)
+var Err = make(chan error)
// Store the state for when bar.Cleanup() is called
// This is a bit hacky but I don't really see any alternative
@@ -192,24 +187,19 @@ func init() {
var state *bspc.State = nil
var blocks *status.Blocks = nil
- Handle.Create = make(chan int)
- Handle.Destroy = make(chan int)
- Handle.NewState = make(chan *bspc.State)
- Handle.Err = make(chan error)
-
go func() {
defer func() {
- close(Handle.Create)
- close(Handle.Destroy)
- close(Handle.NewState)
- close(Handle.Err)
+ close(Create)
+ close(Destroy)
+ close(NewState)
+ close(Err)
}()
for {
select {
case e := <- drw.Events:
if e.Ev == nil && e.Err == nil {
- Handle.Err <- fmt.Errorf("X connection clossed")
+ Err <- fmt.Errorf("X connection clossed")
return
}
@@ -220,28 +210,28 @@ func init() {
// switch e.Ev.(type) {
// case xproto.DestroyNotifyEvent:
- // Handle.Err <- fmt.Errorf("Window destroyed")
+ // Err <- fmt.Errorf("Window destroyed")
// return
// default:
// }
- case id := <- Handle.Destroy:
+ case id := <- Destroy:
bars[id].destroy(state)
delete(bars, id)
- case id := <- Handle.Create:
+ case id := <- Create:
if state == nil {
- Handle.Err <- errors.New("attempted to create a bar with uninitialized state")
+ Err <- errors.New("attempted to create a bar with uninitialized state")
return
}
if _, ok := bars[id]; ok { break }
if err := create(state, id); err != nil {
- Handle.Err <- fmt.Errorf("Couldn't create window: %s\n", err)
+ Err <- fmt.Errorf("Couldn't create window: %s\n", err)
return
}
case blocks = <- status.NewBlocks:
for _, b := range bars {
b.redraw <- drawinfo{state, blocks}
}
- case state = <- Handle.NewState:
+ case state = <- NewState:
finalstate = state
for _, b := range bars {
b.redraw <- drawinfo{state, blocks}
diff --git a/main.go b/main.go
@@ -32,9 +32,9 @@ func main() {
}
defer bspc.Cleanup()
- bar.Handle.NewState <- bspc.Handle.State
+ bar.NewState <- bspc.Handle.State
for _, m := range bspc.Handle.State.Monitors {
- bar.Handle.Create <- m.ID
+ bar.Create <- m.ID
}
for {
@@ -42,7 +42,7 @@ func main() {
case s := <-signals:
common.Error("%s\n", s)
return
- case err := <-bar.Handle.Err:
+ case err := <-bar.Err:
common.Error("%s\n", err)
return
case err := <-bspc.Handle.EvErr:
@@ -55,9 +55,9 @@ func main() {
switch event.Name {
case "monitor_add":
case "monitor_geometry":
- bar.Handle.Create <- id
+ bar.Create <- id
case "monitor_remove":
- bar.Handle.Destroy <- id
+ bar.Destroy <- id
}
}
}
@@ -65,7 +65,7 @@ func main() {
common.Error("Couldn't load bspwm state: %s\n", err)
return
case <-bspc.Handle.StateUpdate:
- bar.Handle.NewState <- bspc.Handle.State
+ bar.NewState <- bspc.Handle.State
}
}
}