Skip to content

Commit

Permalink
Adding missing Middle mouse button handling (#68)
Browse files Browse the repository at this point in the history
* Adding missing Middle mouse button handling

* correct the comment about MouseWheelMask
  • Loading branch information
ldemailly authored Oct 9, 2024
1 parent 08b45cc commit 58d343f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ansipixels/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package ansipixels
import "bytes"

func (ap *AnsiPixels) MouseClickOn() {
// https://github.com/ghostty-org/ghostty/blame/main/website/app/vt/xtshiftescape/page.mdx
// Let us see shift key modifiers:
ap.WriteString("\033[>1s")
ap.WriteString("\033[?1000h")
}

Expand All @@ -11,7 +14,6 @@ func (ap *AnsiPixels) MouseClickOff() {
}

func (ap *AnsiPixels) MouseTrackingOn() {
// Note default is supposed to be 1 but it isn't as of 2024-11-02
// https://github.com/ghostty-org/ghostty/blame/main/website/app/vt/xtshiftescape/page.mdx
// Let us see shift key modifiers:
ap.WriteString("\033[>1s")
Expand Down Expand Up @@ -63,6 +65,7 @@ func (ap *AnsiPixels) MouseDecode() {

const (
MouseLeft = 0b00
MouseMiddle = 0b01
MouseRight = 0b10
MouseMove = 0b100000
MouseWheelUp = 0b1000000
Expand All @@ -72,7 +75,8 @@ const (
Ctrl = 0b010000
AllModifiers = Shift | Alt | Ctrl
AnyModifierMask = ^AllModifiers
// For some reason iterm2 and kitty etc set the MouseRight bit when shift-mousewheeling.
// On a mac with a physical mouse, shift mousewheel is translated to button 6,7 which
// here looks like we set the MouseRight bit (when shift-mousewheeling).
MouseWheelMask = ^(AllModifiers | MouseRight)
)

Expand Down Expand Up @@ -104,6 +108,10 @@ func (ap *AnsiPixels) LeftClick() bool {
return ap.Mouse && ((ap.Mbuttons & AnyModifierMask) == MouseLeft)
}

func (ap *AnsiPixels) Middle() bool {
return ap.Mouse && ((ap.Mbuttons & AnyModifierMask) == MouseMiddle)
}

func (ap *AnsiPixels) RightClick() bool {
return ap.Mouse && ((ap.Mbuttons & AnyModifierMask) == MouseRight)
}
Expand All @@ -112,6 +120,10 @@ func (ap *AnsiPixels) LeftDrag() bool {
return ap.Mouse && ((ap.Mbuttons & AnyModifierMask) == MouseMove|MouseLeft)
}

func (ap *AnsiPixels) MiddleDrag() bool {
return ap.Mouse && ((ap.Mbuttons & AnyModifierMask) == MouseMove|MouseMiddle)
}

func (ap *AnsiPixels) RightDrag() bool {
return ap.Mouse && ((ap.Mbuttons & AnyModifierMask) == MouseMove|MouseRight)
}

0 comments on commit 58d343f

Please sign in to comment.