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// SlotsPending tells wayland whether a slot waits for its window. Only then
124// does it read the SlotEnv of mapping clients.
125type SlotsPending struct{ Pending bool }
126
127func (SlotsPending) clientCommand() {}
128
129// CloseWindow carries core → wayland close requests.
130type CloseWindow struct{ ID WindowID }
131
132func (CloseWindow) clientCommand() {}
133
134// FocusWindow carries core → wayland keyboard focus (0 means none).
135type FocusWindow struct{ ID WindowID }
136
137func (FocusWindow) clientCommand() {}
138
139// ConfigurePopup carries core → wayland a popup's place, relative to its
140// parent's window geometry. Reposition answers a reposition request.
141type ConfigurePopup struct {
142 ID WindowID
143 Rect Rect
144 Reposition bool
145 Token uint32
146}
147
148func (ConfigurePopup) clientCommand() {}
149
150// ClosePopup carries core → wayland a popup to dismiss (popup_done).
151type ClosePopup struct{ ID WindowID }
152
153func (ClosePopup) clientCommand() {}
154
155// PointerFocus changes the pointer surface; ID 0 clears focus. Coordinates are surface-local.
156type PointerFocus struct {
157 ID WindowID
158 X, Y float64
159}
160
161func (PointerFocus) clientCommand() {}
162
163// PointerMotionTo carries core → wayland motion for the pointer focus, in
164// window coordinates. The deltas and Time feed zwp_relative_pointer_v1;
165// While the window locks the pointer, wayland sends only relative motion.
166type PointerMotionTo struct {
167 ID WindowID
168 X, Y float64
169 DX, DY float64
170 UnaccelDX, UnaccelDY float64
171 // Time is the device timestamp (CLOCK_MONOTONIC).
172 Time time.Duration
173}
174
175func (PointerMotionTo) clientCommand() {}
176
177type PointerButtonTo struct {
178 ID WindowID
179 Button uint32
180 Pressed bool
181 // Time is the device timestamp (CLOCK_MONOTONIC).
182 Time time.Duration
183}
184
185func (PointerButtonTo) clientCommand() {}
186
187// PointerAxisTo sends a scroll frame to a window.
188type PointerAxisTo struct {
189 ID WindowID
190 Axis PointerAxis
191}
192
193func (PointerAxisTo) clientCommand() {}
194
195// GestureKind is a touchpad gesture a client can receive
196// (zwp_pointer_gestures_v1).
197type GestureKind uint8
198
199const (
200 GestureSwipe GestureKind = iota
201 GesturePinch
202 GestureHold
203)
204
205// GestureBeginTo starts a gesture on a window with the pointer focus.
206// Wayland assigns the serial. Time is the device timestamp
207// (CLOCK_MONOTONIC), like the updates and the end of the gesture.
208type GestureBeginTo struct {
209 ID WindowID
210 Kind GestureKind
211 Fingers int
212 Time time.Duration
213}
214
215func (GestureBeginTo) clientCommand() {}
216
217// GestureUpdateTo moves the gesture of a window. DX and DY are the
218// centre's movement; Scale and Rotation are only for a pinch (see
219// PinchUpdate). A hold has no updates.
220type GestureUpdateTo struct {
221 ID WindowID
222 Kind GestureKind
223 DX, DY float64
224 Scale float64
225 Rotation float64
226 Time time.Duration
227}
228
229func (GestureUpdateTo) clientCommand() {}
230
231// GestureEndTo ends the gesture of a window. Cancelled is set when the
232// gesture did not complete: the pointer focus moved, the window went away
233// or the device cancelled it. Ending a gesture that is not running does
234// nothing.
235type GestureEndTo struct {
236 ID WindowID
237 Kind GestureKind
238 Cancelled bool
239 Time time.Duration
240}
241
242func (GestureEndTo) clientCommand() {}
243
244// ForwardKey carries core → wayland unbound keys.
245type ForwardKey struct {
246 ID WindowID
247 Key KeyEvent
248}
249
250func (ForwardKey) clientCommand() {}
251
252// SetKeymap carries app → wayland repeat info and, unless Keymap is empty, a new
253// xkb keymap in text format.
254type SetKeymap struct {
255 Keymap string
256 RepeatRate, RepeatDelay int
257}
258
259func (SetKeymap) clientCommand() {}
260
261// CursorImage is a cursor frame in premultiplied B8G8R8A8, W*4 bytes per
262// row; (HotX, HotY) is the click point. Sizes are physical pixels.
263type CursorImage struct {
264 W, H, HotX, HotY int
265 Pixels []byte
266}
267
268// CursorChange carries wayland → outputs the cursor the focused client asks
269// for: a CSS cursor name (wp_cursor_shape_v1), its own image, or none.
270// The zero value is the default arrow.
271type CursorChange struct {
272 // Shape is a CSS cursor name such as "pointer" or "text".
273 Shape string
274 // Image is a client cursor at Scale buffer pixels per logical pixel.
275 Image *CursorImage
276 Scale int
277 Hidden bool
278}
279
280// SpawnRequest carries core → launcher process arguments.
281type SpawnRequest struct {
282 // Security retains the admitting owner epoch through launcher backpressure.
283 // A wired launcher rejects stale or protected requests before execution.
284 Security SecurityState
285 Argv []string
286 // Env adds KEY=value entries to the child environment.
287 Env []string
288}