fixes #358 EventMouse button mapping

This commit is contained in:
Garrett D'Amore 2020-08-25 15:39:20 -07:00
parent fcaa20f283
commit 5bef26acc2
2 changed files with 13 additions and 7 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2015 The TCell Authors // Copyright 2020 The TCell Authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use file except in compliance with the License. // you may not use file except in compliance with the License.
@ -79,11 +79,13 @@ func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *EventMouse {
// emulations (such as vt100) won't support mice at all, of course. // emulations (such as vt100) won't support mice at all, of course.
type ButtonMask int16 type ButtonMask int16
// These are the actual button values. // These are the actual button values. Note that tcell version 1.x reversed buttons
// two and three on *nix based terminals. We use button 1 as the primary, and
// button 2 as the secondary, and button 3 (which is often missing) as the middle.
const ( const (
Button1 ButtonMask = 1 << iota // Usually left mouse button. Button1 ButtonMask = 1 << iota // Usually the left (primary) mouse button.
Button2 // Usually the middle mouse button. Button2 // Usually the right (secondary) mouse button.
Button3 // Usually the right mouse button. Button3 // Usually the middle mouse button.
Button4 // Often a side button (thumb/next). Button4 // Often a side button (thumb/next).
Button5 // Often a side button (thumb/prev). Button5 // Often a side button (thumb/prev).
Button6 Button6
@ -94,4 +96,8 @@ const (
WheelLeft // Wheel motion to left. WheelLeft // Wheel motion to left.
WheelRight // Wheel motion to right. WheelRight // Wheel motion to right.
ButtonNone ButtonMask = 0 // No button or wheel events. ButtonNone ButtonMask = 0 // No button or wheel events.
ButtonPrimary = Button1
ButtonSecondary = Button2
ButtonMiddle = Button3
) )

View File

@ -919,10 +919,10 @@ func (t *tScreen) buildMouseEvent(x, y, btn int) *EventMouse {
button = Button1 button = Button1
t.wasbtn = true t.wasbtn = true
case 1: case 1:
button = Button2 button = Button3 // Note we prefer to treat right as button 2
t.wasbtn = true t.wasbtn = true
case 2: case 2:
button = Button3 button = Button2 // And the middle button as button 3
t.wasbtn = true t.wasbtn = true
case 3: case 3:
button = ButtonNone button = ButtonNone