-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouse_state.go
More file actions
96 lines (82 loc) · 2.32 KB
/
Copy pathmouse_state.go
File metadata and controls
96 lines (82 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/studiowebux/zurm/pane"
)
// inputTracker groups all input edge-detection, drag, click, scroll, and mouse state.
type inputTracker struct {
PrevKeys map[ebiten.Key]bool
PrevMouseButtons map[ebiten.MouseButton]bool
PrevMX, PrevMY int
PtyRepeat KeyRepeatHandler
RepeatSeq []byte // exact bytes to resend on PTY repeat
SelDrag SelectionDragger
DivDrag DividerDragHandler
LastMouseCol int // last col sent to PTY (1-based)
LastMouseRow int // last row sent to PTY (1-based)
MouseHeldBtn int // -1 = none, 0=left, 1=mid, 2=right
ScrollAccum float64 // fractional trackpad wheel accumulation
LastClickTime time.Time
LastClickRow int
LastClickCol int
ClickCount int
// TabClickTime tracks the last click in the tab bar for double-click rename
// detection. Kept separate from LastClickTime so tab clicks do not
// contaminate the terminal's click-count sequence.
TabClickTime time.Time
}
// SelectionDragger tracks whether a text selection drag is in progress.
// The actual selection coordinates live on terminal.ScreenBuffer.Selection.
type SelectionDragger struct {
Active bool
}
// DividerDragHandler tracks pane divider resize dragging.
type DividerDragHandler struct {
Active bool
Split *pane.LayoutNode
}
// Start begins a divider drag on the given split node.
func (dh *DividerDragHandler) Start(split *pane.LayoutNode) {
dh.Active = true
dh.Split = split
}
// Update adjusts the split ratio based on cursor position.
// Returns true if the ratio changed (screen needs redraw).
func (dh *DividerDragHandler) Update(mx, my int) bool {
if dh.Split == nil {
return false
}
switch dh.Split.Kind {
case pane.HSplit:
dx := dh.Split.Rect.Dx()
if dx == 0 {
return false
}
newRatio := float64(mx-dh.Split.Rect.Min.X) / float64(dx)
if newRatio < 0.1 {
newRatio = 0.1
} else if newRatio > 0.9 {
newRatio = 0.9
}
dh.Split.Ratio = newRatio
case pane.VSplit:
dy := dh.Split.Rect.Dy()
if dy == 0 {
return false
}
newRatio := float64(my-dh.Split.Rect.Min.Y) / float64(dy)
if newRatio < 0.1 {
newRatio = 0.1
} else if newRatio > 0.9 {
newRatio = 0.9
}
dh.Split.Ratio = newRatio
}
return true
}
// End stops the divider drag.
func (dh *DividerDragHandler) End() {
dh.Active = false
dh.Split = nil
}