input_events.go RawHistoryFolder
1package ports
2
3import "time"
4
5// Mods carries input → core modifier flags.
6type Mods uint8
7
8const (
9 ModShift Mods = 1 << iota
10 ModCtrl
11 ModAlt
12 ModSuper
13)
14
15// InputEvent carries input → core notifications.
16type InputEvent interface{ inputEvent() }
17
18// KeyEvent carries input → core key transitions; Keysym is an xkb keysym name.
19// Keycode is the evdev code (xkb keycode - 8) and State the xkb modifier state
20// after this transition; wayland forwards both to clients unchanged. Time is
21// the device timestamp (CLOCK_MONOTONIC), like SwipeBegin.Time.
22type KeyEvent struct {
23 Keysym string
24 // Base is the key's unshifted keysym in the active layout, so Cmd+Shift+1
25 // still matches a cmd+shift+1 bind although it prints exclam.
26 Base string
27 Mods Mods
28 Pressed bool
29 Time time.Duration
30 Keycode uint32
31 State ModState
32}
33
34// ModState is the serialized xkb modifier state sent in wl_keyboard.modifiers.
35type ModState struct{ Depressed, Latched, Locked, Group uint32 }
36
37func (KeyEvent) inputEvent() {}
38
39// PointerMotion uses global layout coordinates in logical pixels (see OutputPlacement).
40// DX and DY are the accelerated logical deltas and UnaccelDX, UnaccelDY the
41// raw device deltas; all four are 0 for absolute devices. Time is the device
42// timestamp (CLOCK_MONOTONIC).
43type PointerMotion struct {
44 X, Y float64
45 DX, DY float64
46 UnaccelDX, UnaccelDY float64
47 Time time.Duration
48}
49
50func (PointerMotion) inputEvent() {}
51
52// PointerButton uses evdev button codes (BTN_LEFT is 0x110). Time is the
53// device timestamp (CLOCK_MONOTONIC).
54type PointerButton struct {
55 Button uint32
56 Pressed bool
57 Time time.Duration
58}
59
60func (PointerButton) inputEvent() {}
61
62// AxisSource tells how a scroll was made; values match wl_pointer.axis_source.
63type AxisSource uint8
64
65const (
66 AxisWheel AxisSource = iota
67 AxisFinger
68 AxisContinuous
69)
70
71// ScrollAxis is one scroll direction in a pointer frame. Value is in
72// surface pixels; V120 counts wheel detents in 1/120 steps (wheel only).
73// Stop ends a finger or continuous scroll on this axis.
74type ScrollAxis struct {
75 Set bool
76 Value float64
77 V120 int32
78 Stop bool
79}
80
81// PointerAxis is one scroll frame: Vertical, then Horizontal. Time is the
82// device timestamp (CLOCK_MONOTONIC).
83type PointerAxis struct {
84 Source AxisSource
85 Vertical, Horizontal ScrollAxis
86 Time time.Duration
87}
88
89func (PointerAxis) inputEvent() {}
90
91// SwipeBegin starts a touchpad swipe of any finger count; core keeps three
92// and four fingers and forwards the others to the window under the
93// pointer. Time is the device timestamp (CLOCK_MONOTONIC), shared by the
94// updates and the end.
95type SwipeBegin struct {
96 Fingers int
97 Time time.Duration
98}
99
100// SwipeUpdate moves the fingers by the unaccelerated deltas DX, DY
101// (touchpad units, as libinput reports them, not natural-scroll inverted),
102// which the compositor's own swipes follow. AccelDX, AccelDY are the same
103// move with pointer acceleration, what a client gets.
104type SwipeUpdate struct {
105 DX, DY float64
106 AccelDX, AccelDY float64
107 Time time.Duration
108}
109
110// SwipeEnd lifts the fingers. Cancelled is set when libinput cancelled
111// the swipe (another finger landed).
112type SwipeEnd struct {
113 Cancelled bool
114 Time time.Duration
115}
116
117func (SwipeBegin) inputEvent() {}
118func (SwipeUpdate) inputEvent() {}
119func (SwipeEnd) inputEvent() {}
120
121// PinchBegin starts a touchpad pinch. Time is the device timestamp
122// (CLOCK_MONOTONIC), shared by the updates and the end. A pinch always goes
123// to the window under the pointer.
124type PinchBegin struct {
125 Fingers int
126 Time time.Duration
127}
128
129// PinchUpdate moves a pinch: the fingers' centre by the deltas DX, DY with
130// pointer acceleration, as clients get them, Scale is the spread of the fingers
131// relative to the begin (1.0 there) and Rotation the angle turned since the
132// previous event, in degrees clockwise.
133type PinchUpdate struct {
134 DX, DY float64
135 Scale float64
136 Rotation float64
137 Time time.Duration
138}
139
140// PinchEnd lifts the fingers. Cancelled is set when libinput cancelled the
141// pinch.
142type PinchEnd struct {
143 Cancelled bool
144 Time time.Duration
145}
146
147// HoldBegin starts a touchpad hold: fingers resting on the pad. Like a
148// pinch it goes to the window under the pointer.
149type HoldBegin struct {
150 Fingers int
151 Time time.Duration
152}
153
154// HoldEnd lifts the fingers. Cancelled is set when the fingers moved or
155// another finger landed, so the hold became something else.
156type HoldEnd struct {
157 Cancelled bool
158 Time time.Duration
159}
160
161func (PinchBegin) inputEvent() {}
162func (PinchUpdate) inputEvent() {}
163func (PinchEnd) inputEvent() {}
164func (HoldBegin) inputEvent() {}
165func (HoldEnd) inputEvent() {}