mirror of https://github.com/liamg/aminal.git
Fix VT200 and X10 mouse mode support
This commit is contained in:
parent
e5e7d09656
commit
f0a1742c0a
19
gui/mouse.go
19
gui/mouse.go
|
@ -2,6 +2,7 @@ package gui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/go-gl/glfw/v3.2/glfw"
|
||||
"gitlab.com/liamg/raft/terminal"
|
||||
|
@ -38,10 +39,12 @@ func (gui *GUI) mouseButtonCallback(w *glfw.Window, button glfw.MouseButton, act
|
|||
*/
|
||||
|
||||
if action == glfw.Press {
|
||||
b := rune(byte(button & 0xff))
|
||||
x := rune(byte((gui.terminal.ActiveBuffer().CursorColumn() + 31) & 0xff))
|
||||
y := rune(byte((gui.terminal.ActiveBuffer().CursorLine() + 31) & 0xff))
|
||||
packet := fmt.Sprintf("\x1b[M%c%c%c", b, x, y)
|
||||
b := rune(button)
|
||||
px, py := w.GetCursorPos()
|
||||
x := int(math.Floor(px/float64(gui.renderer.CellWidth()))) + 1
|
||||
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))
|
||||
}
|
||||
case terminal.MouseModeVT200: // normal
|
||||
|
@ -93,9 +96,11 @@ func (gui *GUI) mouseButtonCallback(w *glfw.Window, button glfw.MouseButton, act
|
|||
if mod&glfw.ModControl > 0 {
|
||||
b |= 16
|
||||
}
|
||||
x := rune(byte((gui.terminal.ActiveBuffer().CursorColumn() + 31) & 0xff))
|
||||
y := rune(byte((gui.terminal.ActiveBuffer().CursorLine() + 31) & 0xff))
|
||||
packet := fmt.Sprintf("\x1b[M%c%c%c", b, x, y)
|
||||
px, py := w.GetCursorPos()
|
||||
x := int(math.Floor(px/float64(gui.renderer.CellWidth()))) + 1
|
||||
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))
|
||||
|
||||
case terminal.MouseModeVT200Highlight:
|
||||
|
|
|
@ -15,6 +15,8 @@ type Renderer interface {
|
|||
DrawCellText(cell buffer.Cell, col uint, row uint)
|
||||
DrawCursor(col uint, row uint, colour config.Colour)
|
||||
GetTermSize() (uint, uint)
|
||||
CellWidth() float32
|
||||
CellHeight() float32
|
||||
}
|
||||
|
||||
type OpenGLRenderer struct {
|
||||
|
@ -44,6 +46,14 @@ type rectangle struct {
|
|||
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 {
|
||||
|
||||
halfAreaWidth := float32(r.areaWidth / 2)
|
||||
|
|
|
@ -103,10 +103,10 @@ func csiSetMode(modeStr string, enabled bool, terminal *Terminal) error {
|
|||
terminal.ActiveBuffer().SetAutoWrap(enabled)
|
||||
case "?9":
|
||||
if enabled {
|
||||
terminal.logger.Debugf("Turning on X10 mouse mode")
|
||||
terminal.logger.Infof("Turning on X10 mouse mode")
|
||||
terminal.SetMouseMode(MouseModeX10)
|
||||
} else {
|
||||
terminal.logger.Debugf("Turning off X10 mouse mode")
|
||||
terminal.logger.Infof("Turning off X10 mouse mode")
|
||||
terminal.SetMouseMode(MouseModeNone)
|
||||
}
|
||||
case "?12", "?13":
|
||||
|
@ -123,10 +123,10 @@ func csiSetMode(modeStr string, enabled bool, terminal *Terminal) error {
|
|||
// enable mouse tracking
|
||||
// 1000 refers to ext mode for extended mouse click area - otherwise only x <= 255-31
|
||||
if enabled {
|
||||
terminal.logger.Debugf("Turning on VT200 mouse mode")
|
||||
terminal.logger.Infof("Turning on VT200 mouse mode")
|
||||
terminal.SetMouseMode(MouseModeVT200)
|
||||
} else {
|
||||
terminal.logger.Debugf("Turning off VT200 mouse mode")
|
||||
terminal.logger.Infof("Turning off VT200 mouse mode")
|
||||
terminal.SetMouseMode(MouseModeNone)
|
||||
}
|
||||
case "?1048":
|
||||
|
|
Loading…
Reference in New Issue