enrich mouse events

This commit is contained in:
Tony Worm 2018-01-11 11:01:45 -07:00
parent e9a3a6b3d6
commit a433c24293

View File

@ -99,10 +99,8 @@ func crtTermboxEvt(e termbox.Event) Event {
ne.Path = "/sys/err"
ne.Data = err
case termbox.EventMouse:
m := EvtMouse{}
m.X = e.MouseX
m.Y = e.MouseY
ne.Path = "/sys/mouse"
m := evtMouse(e)
ne.Path = "/sys/mouse/" + m.Press
ne.Data = m
}
return ne
@ -116,9 +114,40 @@ type EvtWnd struct {
type EvtMouse struct {
X int
Y int
Drag bool
Press string
}
func evtMouse(e termbox.Event) EvtMouse {
em := EvtMouse{}
em.X = e.MouseX
em.Y = e.MouseY
if e.Mod == termbox.ModMotion {
em.Drag = true
}
switch e.Key {
case termbox.MouseLeft:
em.Press = "left"
case termbox.MouseMiddle:
em.Press = "middle"
case termbox.MouseRight:
em.Press = "right"
case termbox.MouseRelease:
em.Press = "release"
case termbox.MouseWheelUp:
em.Press = "wheel/up"
case termbox.MouseWheelDown:
em.Press = "wheel/down"
}
return em
}
type EvtErr error
func hookTermboxEvt() {
@ -126,7 +155,7 @@ func hookTermboxEvt() {
e := termbox.PollEvent()
for _, c := range sysEvtChs {
func(ch chan Event) {
go func(ch chan Event) {
ch <- crtTermboxEvt(e)
}(c)
}
@ -244,7 +273,7 @@ func (es *EvtStream) Loop() {
case "/sig/stoploop":
return
}
func(a Event) {
go func(a Event) {
es.RLock()
defer es.RUnlock()
if pattern := es.match(a.Path); pattern != "" {
@ -274,10 +303,6 @@ func Handle(path string, handler func(Event)) {
DefaultEvtStream.Handle(path, handler)
}
func ResetHandlers() {
DefaultEvtStream.ResetHandlers()
}
func Loop() {
DefaultEvtStream.Loop()
}