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// ForwardKey carries core → wayland unbound keys.
196type ForwardKey struct {
197 ID WindowID
198 Key KeyEvent
199}
200
201func (ForwardKey) clientCommand() {}
202
203// SetKeymap carries app → wayland repeat info and, unless Keymap is empty, a new
204// xkb keymap in text format.
205type SetKeymap struct {
206 Keymap string
207 RepeatRate, RepeatDelay int
208}
209
210func (SetKeymap) clientCommand() {}
211
212// CursorImage is a cursor frame in premultiplied B8G8R8A8, W*4 bytes per
213// row; (HotX, HotY) is the click point. Sizes are physical pixels.
214type CursorImage struct {
215 W, H, HotX, HotY int
216 Pixels []byte
217}
218
219// CursorChange carries wayland → outputs the cursor the focused client asks
220// for: a CSS cursor name (wp_cursor_shape_v1), its own image, or none.
221// The zero value is the default arrow.
222type CursorChange struct {
223 // Shape is a CSS cursor name such as "pointer" or "text".
224 Shape string
225 // Image is a client cursor at Scale buffer pixels per logical pixel.
226 Image *CursorImage
227 Scale int
228 Hidden bool
229}
230
231// SpawnRequest carries core → launcher process arguments.
232type SpawnRequest struct {
233 // Security retains the admitting owner epoch through launcher backpressure.
234 // A wired launcher rejects stale or protected requests before execution.
235 Security SecurityState
236 Argv []string
237 // Env adds KEY=value entries to the child environment.
238 Env []string
239}