Fix bug where wheel wasn't being reported if a modifier was pressed

This commit is contained in:
Christian Rocha 2020-06-23 10:34:46 -04:00
parent 5ec2c0712a
commit d6cf9e69b6
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 18 additions and 3 deletions

View File

@ -26,7 +26,8 @@ func (m MouseEvent) String() (s string) {
type MouseButton int type MouseButton int
const ( const (
MouseLeft MouseButton = iota MouseUnknown MouseButton = iota
MouseLeft
MouseRight MouseRight
MouseMiddle MouseMiddle
MouseRelease MouseRelease
@ -36,6 +37,7 @@ const (
) )
var mouseButtonNames = map[MouseButton]string{ var mouseButtonNames = map[MouseButton]string{
MouseUnknown: "unknown",
MouseLeft: "left", MouseLeft: "left",
MouseRight: "right", MouseRight: "right",
MouseMiddle: "middle", MouseMiddle: "middle",
@ -47,6 +49,11 @@ var mouseButtonNames = map[MouseButton]string{
// Parse an X10-encoded mouse event. The simplest kind. The last release of // Parse an X10-encoded mouse event. The simplest kind. The last release of
// X10 was December 1986, by the way. // X10 was December 1986, by the way.
//
// X10 mouse events look like:
//
// ESC [M Cb Cx Cy
//
func parseX10MouseEvent(buf []byte) (m MouseEvent, err error) { func parseX10MouseEvent(buf []byte) (m MouseEvent, err error) {
if len(buf) != 6 || string(buf[:3]) != "\x1b[M" { if len(buf) != 6 || string(buf[:3]) != "\x1b[M" {
return m, errors.New("not an X10 mouse event") return m, errors.New("not an X10 mouse event")
@ -64,9 +71,17 @@ func parseX10MouseEvent(buf []byte) (m MouseEvent, err error) {
default: default:
switch e & 3 { switch e & 3 {
case 0: case 0:
m.Button = MouseLeft if e&64 != 0 {
m.Button = MouseWheelUp
} else {
m.Button = MouseLeft
}
case 1: case 1:
m.Button = MouseMiddle if e&64 != 0 {
m.Button = MouseWheelDown
} else {
m.Button = MouseMiddle
}
case 2: case 2:
m.Button = MouseRight m.Button = MouseRight
case 3: case 3: