Skip to content

Commit

Permalink
Add HasMotion to mouse events
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir authored and n-peugnet committed Nov 9, 2022
1 parent c1778dd commit 11b8e48
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion console_win.go
Expand Up @@ -779,7 +779,7 @@ func (s *cScreen) getConsoleInput() error {
btns := mrec2btns(mrec.btns, mrec.flags)
// we ignore double click, events are delivered normally
s.PostEventWait(NewEventMouse(int(mrec.x), int(mrec.y), btns,
mod2mask(mrec.mod)))
mod2mask(mrec.mod), false))

case resizeEvent:
var rrec resizeRecord
Expand Down
9 changes: 7 additions & 2 deletions mouse.go
Expand Up @@ -40,6 +40,7 @@ type EventMouse struct {
mod ModMask
x int
y int
mtn bool
}

// When returns the time when this EventMouse was created.
Expand All @@ -64,10 +65,14 @@ func (ev *EventMouse) Position() (int, int) {
return ev.x, ev.y
}

func (ev *EventMouse) HasMotion() bool {
return ev.mtn
}

// NewEventMouse is used to create a new mouse event. Applications
// shouldn't need to use this; its mostly for screen implementors.
func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *EventMouse {
return &EventMouse{t: time.Now(), x: x, y: y, btn: btn, mod: mod}
func NewEventMouse(x, y int, btn ButtonMask, mod ModMask, motion bool) *EventMouse {
return &EventMouse{t: time.Now(), x: x, y: y, btn: btn, mod: mod, mtn: motion}
}

// ButtonMask is a mask of mouse buttons and wheel events. Mouse button presses
Expand Down
2 changes: 1 addition & 1 deletion simulation.go
Expand Up @@ -393,7 +393,7 @@ func (s *simscreen) PostEvent(ev Event) error {
}

func (s *simscreen) InjectMouse(x, y int, buttons ButtonMask, mod ModMask) {
ev := NewEventMouse(x, y, buttons, mod)
ev := NewEventMouse(x, y, buttons, mod, false)
s.PostEvent(ev)
}

Expand Down
8 changes: 4 additions & 4 deletions tscreen.go
Expand Up @@ -1215,7 +1215,7 @@ func (t *tScreen) clip(x, y int) (int, int) {
// buildMouseEvent returns an event based on the supplied coordinates and button
// state. Note that the screen's mouse button state is updated based on the
// input to this function (i.e. it mutates the receiver).
func (t *tScreen) buildMouseEvent(x, y, btn int) *EventMouse {
func (t *tScreen) buildMouseEvent(x, y, btn int, motion bool) *EventMouse {

// XTerm mouse events only report at most one button at a time,
// which may include a wheel button. Wheel motion events are
Expand Down Expand Up @@ -1259,7 +1259,7 @@ func (t *tScreen) buildMouseEvent(x, y, btn int) *EventMouse {
// to the screen in that case.
x, y = t.clip(x, y)

return NewEventMouse(x, y, button, mod)
return NewEventMouse(x, y, button, mod, motion)
}

// parseSgrMouse attempts to locate an SGR mouse record at the start of the
Expand Down Expand Up @@ -1375,7 +1375,7 @@ func (t *tScreen) parseSgrMouse(buf *bytes.Buffer, evs *[]Event) (bool, bool) {
_, _ = buf.ReadByte()
i--
}
*evs = append(*evs, t.buildMouseEvent(x, y, btn))
*evs = append(*evs, t.buildMouseEvent(x, y, btn, motion))
return true, true
}
}
Expand Down Expand Up @@ -1428,7 +1428,7 @@ func (t *tScreen) parseXtermMouse(buf *bytes.Buffer, evs *[]Event) (bool, bool)
_, _ = buf.ReadByte()
i--
}
*evs = append(*evs, t.buildMouseEvent(x, y, btn))
*evs = append(*evs, t.buildMouseEvent(x, y, btn, false))
return true, true
}
}
Expand Down

0 comments on commit 11b8e48

Please sign in to comment.