Skip to content

Commit

Permalink
Persist mouse mode during buffer switching (#299)
Browse files Browse the repository at this point in the history
* Persist mouse mode during buffer switching

* Update mouse.go
  • Loading branch information
liamg authored Jul 31, 2021
1 parent 80b4d6a commit 1f2980c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 34 deletions.
4 changes: 2 additions & 2 deletions internal/app/darktile/gui/mouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (g *GUI) handleMouseRemotely(x, y int, pressedLeft, pressedMiddle, pressedR

tx, ty := 1+(x/g.fontManager.CharSize().X), 1+(y/g.fontManager.CharSize().Y)

mode := g.terminal.GetActiveBuffer().GetMouseMode()
mode := g.terminal.GetMouseMode()

switch mode {
case termutil.MouseModeNone:
Expand All @@ -295,7 +295,7 @@ func (g *GUI) handleMouseRemotely(x, y int, pressedLeft, pressedMiddle, pressedR

var button rune

extMode := g.terminal.GetActiveBuffer().GetMouseExtMode()
extMode := g.terminal.GetMouseExtMode()

switch true {
case pressedLeft:
Expand Down
10 changes: 0 additions & 10 deletions internal/app/darktile/termutil/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ type Buffer struct {
charsets []*map[rune]rune // array of 2 charsets, nil means ASCII (no conversion)
currentCharset int // active charset index in charsets array, valid values are 0 or 1
modes Modes
mouseMode MouseMode
mouseExtMode MouseExtMode
selectionStart *Position
selectionEnd *Position
highlightStart *Position
Expand Down Expand Up @@ -80,14 +78,6 @@ func (buffer *Buffer) IsCursorVisible() bool {
return buffer.modes.ShowCursor
}

func (buffer *Buffer) GetMouseMode() MouseMode {
return buffer.mouseMode
}

func (buffer *Buffer) GetMouseExtMode() MouseExtMode {
return buffer.mouseExtMode
}

func (buffer *Buffer) IsApplicationCursorKeysModeEnabled() bool {
return buffer.modes.ApplicationCursorKeys
}
Expand Down
36 changes: 14 additions & 22 deletions internal/app/darktile/termutil/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,11 +717,9 @@ func (t *Terminal) csiSetMode(modes string, enabled bool) bool {
t.activeBuffer.modes.AutoWrap = enabled
case "?9":
if enabled {
//terminal.logger.Infof("Turning on X10 mouse mode")
t.activeBuffer.mouseMode = (MouseModeX10)
t.mouseMode = (MouseModeX10)
} else {
//terminal.logger.Infof("Turning off X10 mouse mode")
t.activeBuffer.mouseMode = (MouseModeNone)
t.mouseMode = (MouseModeNone)
}
case "?12", "?13":
t.activeBuffer.modes.BlinkingCursor = enabled
Expand All @@ -737,46 +735,40 @@ func (t *Terminal) csiSetMode(modes string, enabled bool) bool {
// enable mouse tracking
// 1000 refers to ext mode for extended mouse click area - otherwise only x <= 255-31
if enabled {
t.activeBuffer.mouseMode = (MouseModeVT200)
t.mouseMode = (MouseModeVT200)
} else {
t.activeBuffer.mouseMode = (MouseModeNone)
t.mouseMode = (MouseModeNone)
}
case "?1002":
if enabled {
//terminal.logger.Infof("Turning on Button Event mouse mode")
t.activeBuffer.mouseMode = (MouseModeButtonEvent)
t.mouseMode = (MouseModeButtonEvent)
} else {
//terminal.logger.Infof("Turning off Button Event mouse mode")
t.activeBuffer.mouseMode = (MouseModeNone)
t.mouseMode = (MouseModeNone)
}
case "?1003":
if enabled {
t.activeBuffer.mouseMode = MouseModeAnyEvent
t.mouseMode = MouseModeAnyEvent
} else {
t.activeBuffer.mouseMode = MouseModeNone
t.mouseMode = MouseModeNone
}
case "?1005":
if enabled {
t.activeBuffer.mouseExtMode = MouseExtUTF
t.mouseExtMode = MouseExtUTF
} else {
t.activeBuffer.mouseExtMode = MouseExtNone
t.mouseExtMode = MouseExtNone
}

case "?1006":
if enabled {
//.logger.Infof("Turning on SGR ext mouse mode")
t.activeBuffer.mouseExtMode = MouseExtSGR
t.mouseExtMode = MouseExtSGR
} else {
//terminal.logger.Infof("Turning off SGR ext mouse mode")
t.activeBuffer.mouseExtMode = (MouseExtNone)
t.mouseExtMode = (MouseExtNone)
}
case "?1015":
if enabled {
//terminal.logger.Infof("Turning on URXVT ext mouse mode")
t.activeBuffer.mouseExtMode = (MouseExtURXVT)
t.mouseExtMode = (MouseExtURXVT)
} else {
//terminal.logger.Infof("Turning off URXVT ext mouse mode")
t.activeBuffer.mouseExtMode = (MouseExtNone)
t.mouseExtMode = (MouseExtNone)
}
case "?1048":
if enabled {
Expand Down
10 changes: 10 additions & 0 deletions internal/app/darktile/termutil/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type Terminal struct {
closeChan chan struct{}
buffers []*Buffer
activeBuffer *Buffer
mouseMode MouseMode
mouseExtMode MouseExtMode
logFile *os.File
theme *Theme
running bool
Expand Down Expand Up @@ -285,6 +287,14 @@ func (t *Terminal) switchBuffer(index uint8) {
}
}

func (t *Terminal) GetMouseMode() MouseMode {
return t.mouseMode
}

func (t *Terminal) GetMouseExtMode() MouseExtMode {
return t.mouseExtMode
}

func (t *Terminal) GetActiveBuffer() *Buffer {
return t.activeBuffer
}
Expand Down

0 comments on commit 1f2980c

Please sign in to comment.