Fix VT200 and X10 mouse mode support

This commit is contained in:
Liam Galvin 2018-09-01 20:24:16 +01:00
parent e5e7d09656
commit f0a1742c0a
3 changed files with 26 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package gui
import ( import (
"fmt" "fmt"
"math"
"github.com/go-gl/glfw/v3.2/glfw" "github.com/go-gl/glfw/v3.2/glfw"
"gitlab.com/liamg/raft/terminal" "gitlab.com/liamg/raft/terminal"
@ -38,10 +39,12 @@ func (gui *GUI) mouseButtonCallback(w *glfw.Window, button glfw.MouseButton, act
*/ */
if action == glfw.Press { if action == glfw.Press {
b := rune(byte(button & 0xff)) b := rune(button)
x := rune(byte((gui.terminal.ActiveBuffer().CursorColumn() + 31) & 0xff)) px, py := w.GetCursorPos()
y := rune(byte((gui.terminal.ActiveBuffer().CursorLine() + 31) & 0xff)) x := int(math.Floor(px/float64(gui.renderer.CellWidth()))) + 1
packet := fmt.Sprintf("\x1b[M%c%c%c", b, x, y) y := int(math.Floor(py/float64(gui.renderer.CellHeight()))) + 1
packet := fmt.Sprintf("\x1b[M%c%c%c", (rune(b + 32)), (rune(x + 32)), (rune(y + 32)))
gui.terminal.Write([]byte(packet)) gui.terminal.Write([]byte(packet))
} }
case terminal.MouseModeVT200: // normal case terminal.MouseModeVT200: // normal
@ -93,9 +96,11 @@ func (gui *GUI) mouseButtonCallback(w *glfw.Window, button glfw.MouseButton, act
if mod&glfw.ModControl > 0 { if mod&glfw.ModControl > 0 {
b |= 16 b |= 16
} }
x := rune(byte((gui.terminal.ActiveBuffer().CursorColumn() + 31) & 0xff)) px, py := w.GetCursorPos()
y := rune(byte((gui.terminal.ActiveBuffer().CursorLine() + 31) & 0xff)) x := int(math.Floor(px/float64(gui.renderer.CellWidth()))) + 1
packet := fmt.Sprintf("\x1b[M%c%c%c", b, x, y) y := int(math.Floor(py/float64(gui.renderer.CellHeight()))) + 1
packet := fmt.Sprintf("\x1b[M%c%c%c", (rune(b + 32)), (rune(x + 32)), (rune(y + 32)))
gui.logger.Infof("Sending mouse packet: '%v'", packet)
gui.terminal.Write([]byte(packet)) gui.terminal.Write([]byte(packet))
case terminal.MouseModeVT200Highlight: case terminal.MouseModeVT200Highlight:

View File

@ -15,6 +15,8 @@ type Renderer interface {
DrawCellText(cell buffer.Cell, col uint, row uint) DrawCellText(cell buffer.Cell, col uint, row uint)
DrawCursor(col uint, row uint, colour config.Colour) DrawCursor(col uint, row uint, colour config.Colour)
GetTermSize() (uint, uint) GetTermSize() (uint, uint)
CellWidth() float32
CellHeight() float32
} }
type OpenGLRenderer struct { type OpenGLRenderer struct {
@ -44,6 +46,14 @@ type rectangle struct {
prog uint32 prog uint32
} }
func (r *OpenGLRenderer) CellWidth() float32 {
return r.cellWidth
}
func (r *OpenGLRenderer) CellHeight() float32 {
return r.cellHeight
}
func (r *OpenGLRenderer) newRectangle(x float32, y float32, colourAttr uint32) *rectangle { func (r *OpenGLRenderer) newRectangle(x float32, y float32, colourAttr uint32) *rectangle {
halfAreaWidth := float32(r.areaWidth / 2) halfAreaWidth := float32(r.areaWidth / 2)

View File

@ -103,10 +103,10 @@ func csiSetMode(modeStr string, enabled bool, terminal *Terminal) error {
terminal.ActiveBuffer().SetAutoWrap(enabled) terminal.ActiveBuffer().SetAutoWrap(enabled)
case "?9": case "?9":
if enabled { if enabled {
terminal.logger.Debugf("Turning on X10 mouse mode") terminal.logger.Infof("Turning on X10 mouse mode")
terminal.SetMouseMode(MouseModeX10) terminal.SetMouseMode(MouseModeX10)
} else { } else {
terminal.logger.Debugf("Turning off X10 mouse mode") terminal.logger.Infof("Turning off X10 mouse mode")
terminal.SetMouseMode(MouseModeNone) terminal.SetMouseMode(MouseModeNone)
} }
case "?12", "?13": case "?12", "?13":
@ -123,10 +123,10 @@ func csiSetMode(modeStr string, enabled bool, terminal *Terminal) error {
// enable mouse tracking // enable mouse tracking
// 1000 refers to ext mode for extended mouse click area - otherwise only x <= 255-31 // 1000 refers to ext mode for extended mouse click area - otherwise only x <= 255-31
if enabled { if enabled {
terminal.logger.Debugf("Turning on VT200 mouse mode") terminal.logger.Infof("Turning on VT200 mouse mode")
terminal.SetMouseMode(MouseModeVT200) terminal.SetMouseMode(MouseModeVT200)
} else { } else {
terminal.logger.Debugf("Turning off VT200 mouse mode") terminal.logger.Infof("Turning off VT200 mouse mode")
terminal.SetMouseMode(MouseModeNone) terminal.SetMouseMode(MouseModeNone)
} }
case "?1048": case "?1048":