diff --git a/application.go b/application.go index fc2d865..063b4e2 100644 --- a/application.go +++ b/application.go @@ -38,6 +38,7 @@ type FocusableComponent interface { type Application struct { screenLock sync.RWMutex screen tcell.Screen + prevMouseEvt *tcell.EventMouse root Component updates chan interface{} redrawTicker *time.Ticker @@ -50,6 +51,7 @@ const queueSize = 255 func NewApplication() *Application { return &Application{ + prevMouseEvt: &tcell.EventMouse{}, updates: make(chan interface{}, queueSize), redrawTicker: time.NewTicker(1 * time.Minute), stop: make(chan struct{}, 1), @@ -132,7 +134,14 @@ func (app *Application) Start() error { redraw = app.root.OnPasteEvent(customEvt) } case *tcell.EventMouse: - redraw = app.root.OnMouseEvent(event) + var customEvt customMouseEvent + if app.prevMouseEvt.Buttons() == event.Buttons() { + customEvt = customMouseEvent{event, true} + } else { + customEvt = customMouseEvent{event, false} + } + app.prevMouseEvt = event + redraw = app.root.OnMouseEvent(customEvt) case *tcell.EventResize: clear = true redraw = true diff --git a/eventhandler.go b/eventhandler.go index 3d45b78..dd6d2ed 100644 --- a/eventhandler.go +++ b/eventhandler.go @@ -51,6 +51,15 @@ type MouseEvent interface { HasMotion() bool } +type customMouseEvent struct { + *tcell.EventMouse + motion bool +} + +func (cme customMouseEvent) HasMotion() bool { + return cme.motion +} + // SimpleEventHandler is a simple implementation of the event handling methods required for components. type SimpleEventHandler struct { OnKey func(event KeyEvent) bool