summaryrefslogtreecommitdiff
path: root/bar/bar.go
diff options
context:
space:
mode:
authorhhvn <dev@hhvn.uk>2024-01-27 15:26:47 +0000
committerhhvn <dev@hhvn.uk>2024-01-27 15:26:47 +0000
commit0a5f0070526a2c32e7b7f65a50ecd993babfedfa (patch)
tree553721f479a83c9bc9437cc9329eed51c3ae7ded /bar/bar.go
parent764d1c63768b1bef017bb6c8c31b3dc8540a37fb (diff)
Remove handle structure from bar/
Diffstat (limited to 'bar/bar.go')
-rw-r--r--bar/bar.go40
1 files changed, 15 insertions, 25 deletions
diff --git a/bar/bar.go b/bar/bar.go
index 55914e0..0b9c271 100644
--- 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}