1package ports
2
3import "time"
4
5// ClientCommand carries core → wayland commands.
6type ClientCommand interface{ clientCommand() }
7
8// ShortcutsInhibitState carries core → wayland whether a window's
9// shortcuts inhibitor is in effect (it has keyboard focus).
10type ShortcutsInhibitState struct {
11 Window WindowID
12 Active bool
13}
14
15func (ShortcutsInhibitState) clientCommand() {}
16
17// UserActivity carries core → wayland that the user touched an input
18// device, for idle notifications (ext_idle_notifier_v1). Core sends at
19// most one per ActivityInterval.
20type UserActivity struct{}
21
22func (UserActivity) clientCommand() {}
23
24// ActivityInterval is the most often core reports UserActivity: idle
25// timers may start up to this much early, so no idle timeout is shorter.
26const ActivityInterval = 100 * time.Millisecond
27
28// ConfigureWindow carries core → wayland geometry and state. Output is the
29// connector showing the window, empty while it is hidden.
30type ConfigureWindow struct {
31 ID WindowID
32 Width, Height int
33 Fullscreen, Activated bool
34 // Floating windows are not tiled: no tiled states.
35 Floating bool
36 // Output is the output the window belongs to, kept while it is not
37 // visible (scale, foreign toplevel).
38 Output string
39 // Visible is set while part of the window is on its output: not on a
40 // hidden workspace, scrolled off, behind a maximized column or a
41 // hidden float. An invisible window is suspended and throttled.
42 Visible bool
43 // Captured marks a window drawn only for a capture session (its
44 // workspace is not on screen): Visible stays the physical truth.
45 Captured bool
46}
47
48func (ConfigureWindow) clientCommand() {}
49
50// OutputPlacement is one output in the global layout. X, Y, Width and
51// Height are logical (after Transform: they swap for 90/270);
52// physical = logical × Scale. Info.Width and Info.Height are the physical
53// mode, the untransformed target.
54type OutputPlacement struct {
55 Info OutputInfo
56 X, Y, Width, Height int
57 Scale float64
58 // Transform is how the target holds the scene (wl_output.transform).
59 Transform BufferTransform
60 // Primary is output.<name>.primary: the pointer starts on it.
61 Primary bool
62}
63
64// Contains reports whether the logical point is on the output.
65func (o OutputPlacement) Contains(x, y float64) bool {
66 return x >= float64(o.X) && x < float64(o.X+o.Width) && y >= float64(o.Y) && y < float64(o.Y+o.Height)
67}
68
69// ToTarget maps a global logical point on the output to target pixels.
70func (o OutputPlacement) ToTarget(x, y float64) (float64, float64) {
71 s := o.Scale
72 if s <= 0 {
73 s = 1
74 }
75 px, py := (x-float64(o.X))*s, (y-float64(o.Y))*s
76 sw, sh := o.Transform.Size(o.Info.Width, o.Info.Height)
77 return o.Transform.ToBuffer(px, py, float64(sw), float64(sh))
78}
79
80// Layout is the global arrangement of outputs in logical pixels.
81type Layout []OutputPlacement
82
83// At returns the output under the logical point.
84func (l Layout) At(x, y float64) (OutputPlacement, bool) {
85 for _, o := range l {
86 if o.Contains(x, y) {
87 return o, true
88 }
89 }
90 return OutputPlacement{}, false
91}
92
93// Clamp keeps the pointer on an output: a point outside every output stays
94// on the output under (fromX, fromY), or the first one, clamped to its edges.
95func (l Layout) Clamp(fromX, fromY, x, y float64) (float64, float64) {
96 if len(l) == 0 {
97 return x, y
98 }
99 if _, ok := l.At(x, y); ok {
100 return x, y
101 }
102 o, ok := l.At(fromX, fromY)
103 if !ok {
104 o = l[0]
105 }
106 x = min(max(x, float64(o.X)), float64(o.X+o.Width)-1)
107 y = min(max(y, float64(o.Y)), float64(o.Y+o.Height)-1)
108 return x, y
109}
110
111// SetOutputs carries core → wayland every output and the focused one (where
112// new surfaces start). It is sent when the list, a placement or the focus changes.
113type SetOutputs struct {
114 Outputs Layout
115 Focused string
116 // Off lists the outputs a client turned off (output power management),
117 // in Outputs order.
118 Off []string
119}
120
121func (SetOutputs) clientCommand() {}
122
123// CloseWindow carries core → wayland close requests.
124type CloseWindow struct{ ID WindowID }
125
126func (CloseWindow) clientCommand() {}
127
128// FocusWindow carries core → wayland keyboard focus (0 means none).
129type FocusWindow struct{ ID WindowID }
130
131func (FocusWindow) clientCommand() {}
132
133// ConfigurePopup carries core → wayland a popup's place, relative to its
134// parent's window geometry. Reposition answers a reposition request.
135type ConfigurePopup struct {
136 ID WindowID
137 Rect Rect
138 Reposition bool
139 Token uint32
140}
141
142func (ConfigurePopup) clientCommand() {}
143
144// ClosePopup carries core → wayland a popup to dismiss (popup_done).
145type ClosePopup struct{ ID WindowID }
146
147func (ClosePopup) clientCommand() {}
148
149// PointerFocus changes the pointer surface; ID 0 clears focus. Coordinates are surface-local.
150type PointerFocus struct {
151 ID WindowID
152 X, Y float64
153}
154
155func (PointerFocus) clientCommand() {}
156
157// PointerMotionTo carries core → wayland motion for the pointer focus, in
158// window coordinates. The deltas and Time feed zwp_relative_pointer_v1;
159// While the window locks the pointer, wayland sends only relative motion.
160type PointerMotionTo struct {
161 ID WindowID
162 X, Y float64
163 DX, DY float64
164 UnaccelDX, UnaccelDY float64
165 // Time is the device timestamp (CLOCK_MONOTONIC).
166 Time time.Duration
167}
168
169func (PointerMotionTo) clientCommand() {}
170
171type PointerButtonTo struct {
172 ID WindowID
173 Button uint32
174 Pressed bool
175 // Grab marks the press that starts the implicit grab: no other button
176 // was held. start_drag must name its serial.
177 Grab bool
178 // Time is the device timestamp (CLOCK_MONOTONIC).
179 Time time.Duration
180}
181
182func (PointerButtonTo) clientCommand() {}
183
184// PointerAxisTo sends a scroll frame to a window.
185type PointerAxisTo struct {
186 ID WindowID
187 Axis PointerAxis
188}
189
190func (PointerAxisTo) clientCommand() {}
191
192// GestureKind is a touchpad gesture a client can receive
193// (zwp_pointer_gestures_v1).
194type GestureKind uint8
195
196const (
197 GestureSwipe GestureKind = iota
198 GesturePinch
199 GestureHold
200)
201
202// GestureBeginTo starts a gesture on a window with the pointer focus.
203// Wayland assigns the serial. Time is the device timestamp
204// (CLOCK_MONOTONIC), like the updates and the end of the gesture.
205type GestureBeginTo struct {
206 ID WindowID
207 Kind GestureKind
208 Fingers int
209 Time time.Duration
210}
211
212func (GestureBeginTo) clientCommand() {}
213
214// GestureUpdateTo moves the gesture of a window. DX and DY are the
215// centre's movement; Scale and Rotation are only for a pinch (see
216// PinchUpdate). A hold has no updates.
217type GestureUpdateTo struct {
218 ID WindowID
219 Kind GestureKind
220 DX, DY float64
221 Scale float64
222 Rotation float64
223 Time time.Duration
224}
225
226func (GestureUpdateTo) clientCommand() {}
227
228// GestureEndTo ends the gesture of a window. Cancelled is set when the
229// gesture did not complete: the pointer focus moved, the window went away
230// or the device cancelled it. Ending a gesture that is not running does
231// nothing.
232type GestureEndTo struct {
233 ID WindowID
234 Kind GestureKind
235 Cancelled bool
236 Time time.Duration
237}
238
239func (GestureEndTo) clientCommand() {}
240
241// ForwardKey carries core → wayland unbound keys.
242type ForwardKey struct {
243 ID WindowID
244 Key KeyEvent
245}
246
247func (ForwardKey) clientCommand() {}
248
249// SetKeymap carries app → wayland repeat info and, unless Keymap is empty, a new
250// xkb keymap in text format.
251type SetKeymap struct {
252 Keymap string
253 RepeatRate, RepeatDelay int
254}
255
256func (SetKeymap) clientCommand() {}
257
258// CursorImage is a cursor frame in premultiplied B8G8R8A8, W*4 bytes per
259// row; (HotX, HotY) is the click point. Sizes are physical pixels.
260type CursorImage struct {
261 W, H, HotX, HotY int
262 Pixels []byte
263}
264
265// CursorChange carries wayland → outputs the cursor the focused client asks
266// for: a CSS cursor name (wp_cursor_shape_v1), its own image, or none.
267// The zero value is the default arrow.
268type CursorChange struct {
269 // Shape is a CSS cursor name such as "pointer" or "text".
270 Shape string
271 // Image is a client cursor at Scale buffer pixels per logical pixel.
272 Image *CursorImage
273 Scale int
274 Hidden bool
275}
276
277// SpawnRequest carries core → launcher process arguments.
278type SpawnRequest struct {
279 // Security retains the admitting owner epoch through launcher backpressure.
280 // A wired launcher rejects stale or protected requests before execution.
281 Security SecurityState
282 Argv []string
283 // Env adds KEY=value entries to the child environment.
284 Env []string
285}
286
287// SetModifiers carries core → wayland a temporary modifier override for the
288// focused window's keyboards: Mods are sent as depressed modifiers (mapped
289// to the current keymap's masks), latched/locked/group kept from the real
290// state. Mods 0 with Restore true sends the real modifier state again: State
291// is that state as core last saw it, which the seat adopts.
292type SetModifiers struct {
293 ID WindowID
294 Mods Mods
295 Restore bool
296 State ModState
297}
298
299func (SetModifiers) clientCommand() {}
300
301// CursorOverride carries core -> wayland the cursor a compositor pointer
302// interaction (border resize, future column move) shows instead of the
303// client's: a CSS cursor name; "" clears it.
304type CursorOverride struct{ Shape string }
305
306func (CursorOverride) clientCommand() {}