Skip to content

Commit

Permalink
Merge pull request #11 from n-peugnet/custom-mouse-event
Browse files Browse the repository at this point in the history
Add a custom mouse event wrapper around tcell's one
  • Loading branch information
tulir authored Mar 17, 2024
2 parents d3eaa9a + 562ac8f commit 7bcc294
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -132,7 +134,10 @@ func (app *Application) Start() error {
redraw = app.root.OnPasteEvent(customEvt)
}
case *tcell.EventMouse:
redraw = app.root.OnMouseEvent(event)
hasMotion := app.prevMouseEvt.Buttons() == event.Buttons()
customEvt := customMouseEvent{event, hasMotion}
app.prevMouseEvt = event
redraw = app.root.OnMouseEvent(customEvt)
case *tcell.EventResize:
clear = true
redraw = true
Expand Down
9 changes: 9 additions & 0 deletions eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ type PasteEvent interface {
Text() string
}

type customMouseEvent struct {
*tcell.EventMouse
motion bool
}

func (cme customMouseEvent) HasMotion() bool {
return cme.motion
}

// MouseEvent is an interface of the *tcell.EventMouse type.
type MouseEvent interface {
tcell.Event
Expand Down

0 comments on commit 7bcc294

Please sign in to comment.