1package ports
2
3import (
4 "image"
5 "regexp"
6 "strings"
7 "time"
8)
9
10// DefaultSDRBrightness is the BT.2408 SDR reference white in HDR, in nits.
11const DefaultSDRBrightness = 203
12
13// OutputConfig configures one connector. Name is the connector (e.g. "DP-2").
14// Mode is "WxH" (highest refresh) or "WxH@Hz" (closest refresh); empty picks the
15// monitor's preferred mode. Off disables the connector.
16// Every connected output that is not off is used.
17// Placement, by precedence: Pos (set at runtime by wlr-output-management),
18// then Anchor against another connected output, then automatic: right of
19// everything placed so far (never left of 0), at y=0, in config order, then in
20// connection order.
21// Scale is the output scale (0 means 1); layout works in logical pixels,
22// physical = logical × Scale. Placement and offsets use the transformed
23// logical size.
24// Primary gets the focus and the pointer at startup, wherever it is placed.
25// ScaleOnly marks an entry set only by output.<name> subkeys: it
26// does not select the connector.
27type OutputConfig struct {
28 Name string
29 Mode string
30 Off bool
31 Scale float64
32 // Transform is output.<name>.transform; logical size swaps for 90/270.
33 Transform BufferTransform
34 // Pos is an explicit logical placement set at runtime; nil uses Anchor, else automatic layout.
35 Pos *image.Point
36 // Anchor places the output against another connected one.
37 Anchor OutputAnchor // RelationNone: automatic
38 Primary bool
39 HDR bool // opt-in to HDR10 on capable outputs
40 SDRBrightness int // nits; default DefaultSDRBrightness
41 ScaleOnly bool
42}
43
44// OutputRelation is the side of another output where an output is placed.
45type OutputRelation uint8
46
47const (
48 RelationNone OutputRelation = iota
49 RelationRightOf
50 RelationLeftOf
51 RelationAbove
52 RelationBelow
53)
54
55// OutputAnchor places an output against another connected one, named by To.
56// Offset is in logical pixels, along the shared edge: y for right-of and
57// left-of (positive is down), x for above and below (positive is right).
58type OutputAnchor struct {
59 Relation OutputRelation
60 To string
61 Offset int
62}
63
64// LayoutRules are the layout settings shared by the defaults, screens and
65// named workspaces. Zero MaxColumns and an empty Overflow inherit.
66type LayoutRules struct {
67 // MaxColumns is how many columns share the screen at once.
68 MaxColumns int
69 // Overflow is "scroll" (horizontal scrolling), "fixed" (spiral splits),
70 // or "cascade" (vertically scrolling bands of columns).
71 Overflow string
72}
73
74// Over fills the unset rules of r from base.
75func (r LayoutRules) Over(base LayoutRules) LayoutRules {
76 if r.MaxColumns == 0 {
77 r.MaxColumns = base.MaxColumns
78 }
79 if r.Overflow == "" {
80 r.Overflow = base.Overflow
81 }
82 return r
83}
84
85// OutputLayout is the layout of one screen, matched by connector (DP-2) or
86// monitor key.
87type OutputLayout struct {
88 Output string
89 LayoutRules
90}
91
92// Config is the parsed compositor configuration (see the config adapter for keys).
93type Config struct {
94 Keyboard struct {
95 Layout, Variant, Options string
96 RepeatRate int
97 RepeatDelay int
98 CmdKey string
99 }
100 Terminal struct {
101 Command []string
102 AutoOpen string
103 }
104 // Xwayland is the xwayland-satellite binary serving X11 clients; empty
105 // disables X11.
106 Xwayland string
107 // Startup are commands run once when the session starts, in order.
108 // One startup line may hold several, split by SplitCommands.
109 Startup [][]string
110 Background struct{ Color string }
111 Floating struct{ Dim float64 }
112 // Stash is the strip of windows set aside by toggle-window-stash:
113 // Width is the width of its selected window (10 to 90) and Gap the
114 // space between it and its neighbors (0 to 10), in percent of the
115 // usable width; Dim darkens the neighbors, 0 to 1. Capture puts new
116 // windows in the stash while it is shown. SpawnTerminal makes
117 // toggle-stash-visible on an empty stash open the terminal in it.
118 Stash struct {
119 Width, Gap int
120 Dim float64
121 Capture bool
122 SpawnTerminal bool
123 }
124 // Border is drawn inside the window edge; Width 0 disables it. Radius is
125 // in logical pixels, >= 0 (at most 64 from the file): it rounds floats
126 // always and tiles when gaps > 0; the renderer uses SceneWindow.Radius.
127 Border struct {
128 Radius int
129 Width int
130 Active string
131 Inactive string
132 }
133 Layout struct {
134 Gaps int
135 // LayoutRules are the defaults; Outputs override them per screen and
136 // named workspaces override them again.
137 LayoutRules
138 Outputs []OutputLayout
139 }
140 // InputDevicesConfig holds Touchpad and Mouse, promoted.
141 InputDevicesConfig
142 // Cursor.HideAfter hides the pointer cursor after this long without
143 // motion; the next motion shows it. 0 never hides it.
144 Cursor struct{ HideAfter time.Duration }
145 // Animations: On enables motion (off lands everything instantly);
146 // Slowdown scales every spring's duration, 0.1 to
147 // 10 (the config's animations.speed maps to it).
148 Animations struct {
149 On bool
150 Slowdown float64
151 }
152 Focus struct {
153 // FollowMove shows the target workspace after a column or window
154 // moves to it.
155 FollowMove bool
156 // Flash briefly draws an inner border on the entity an action changed
157 // (window, column, output). FlashWidth is in logical pixels (1 to 8),
158 // FlashOpacity the starting opacity (0.1 to 1), FlashDuration the fade
159 // (50ms to 1s, not scaled by Animations.Slowdown), FlashColor #rrggbb or
160 // empty for Border.Active.
161 PositionHint bool
162 Flash bool
163 FlashWidth int
164 FlashOpacity float64
165 FlashDuration time.Duration
166 FlashColor string
167 }
168 // Hint configures keyboard hint mode (action hint).
169 Hint struct {
170 // Enable turns the experimental hint mode on (hint.enable). It is
171 // read at startup: a reload keeps the startup value.
172 Enable bool
173 // Capture shows the labels in the captures requested by Wayland
174 // clients (hint.capture); the compositor's own scans never see them.
175 Capture bool
176 Size float64 // logical pixels; zero selects automatic density sizing
177 Background, Foreground string // empty derives from Border.Active
178 // Detector is the nefer-hints binary (hint.detector): a path, or a
179 // name looked up in PATH. Model is the directory of its model files
180 // (hint.model), with a leading ~/ already expanded. Threshold is the
181 // minimum detection score (hint.threshold, 0.01 to 0.99); zero leaves
182 // it unset, using model.json or the runner default. All three
183 // are read at startup.
184 Detector, Model string
185 Threshold float64
186 }
187 // Workspaces are declared with workspace.<name>.* keys, in first-seen order.
188 Workspaces []WorkspaceConfig
189 // Rules are the window rules (rule.<name>.* keys), in first-seen order.
190 Rules []WindowRule
191 // Outputs selects and configures physical displays (drm backend).
192 Outputs []OutputConfig
193 Binds map[string]string
194 Render struct {
195 DirectScanout bool
196 // Tearing honours wp_tearing_control_v1 in direct scanout; VRR
197 // turns variable refresh on while a buffer is scanned out.
198 Tearing, VRR bool
199 // VRRFlipGap is the minimum time between a game frame's flip and
200 // the next frame commit under VRR (0: off). It works around
201 // flips that land at the panel's slowest refresh.
202 VRRFlipGap time.Duration
203 }
204 Performance struct{ Realtime bool }
205 Log struct {
206 Level string
207 Debug []string
208 }
209}
210
211// PointerConfig holds the settings mice and touchpads share. NaturalScroll
212// moves the content with the fingers or the wheel instead of against them.
213// AccelSpeed (-1 to 1) and AccelProfile (AccelAdaptive or AccelFlat) set the
214// pointer speed. LeftHanded swaps the left and right buttons.
215type PointerConfig struct {
216 NaturalScroll bool
217 AccelSpeed float64
218 AccelProfile string
219 LeftHanded bool
220}
221
222// TouchpadConfig configures touchpads: the shared pointer settings
223// (NaturalScroll also applies to two-finger scroll and swipes), plus Tap,
224// which clicks on a tap (one finger left, two right, three middle), and
225// ScrollFactor, which multiplies two-finger scroll.
226type TouchpadConfig struct {
227 PointerConfig
228 Tap bool
229 ScrollFactor float64
230}
231
232// InputDevicesConfig is the live configuration of the input devices, sent to
233// the input adapter as one value. It is comparable.
234type InputDevicesConfig struct {
235 Touchpad TouchpadConfig
236 Mouse PointerConfig
237}
238
239// Pointer acceleration profiles, for mice and touchpads.
240const (
241 AccelAdaptive = "adaptive"
242 AccelFlat = "flat"
243)
244
245// WorkspaceConfig declares a bind-only named workspace, outside the numbered list.
246// Zero MaxColumns and an empty Overflow use the layout.* defaults.
247type WorkspaceConfig struct {
248 Name string
249 // Monitor is the home monitor: a connector name (DP-2) or a monitor key
250 // ("make model serial"); empty follows the focused output when shown.
251 Monitor string
252 // Size overrides the workspace's logical width and height. Zero inherits
253 // the monitor; its scale is always inherited.
254 Size [2]int
255 // Slots are the declared columns (workspace.<name>.column.N), by N.
256 Slots []SlotConfig
257 LayoutRules
258}
259
260// CommandSeparator separates commands in config values that run programs
261// (startup, spawn binds): "waybar; mako" starts both, without waiting.
262const CommandSeparator = ";"
263
264// SplitCommands splits v on CommandSeparator, then each command on
265// whitespace. Empty commands are skipped; no shell is involved.
266func SplitCommands(v string) [][]string {
267 var commands [][]string
268 for part := range strings.SplitSeq(v, CommandSeparator) {
269 if argv := strings.Fields(part); len(argv) > 0 {
270 commands = append(commands, argv)
271 }
272 }
273 return commands
274}
275
276// SlotConfig reserves column N of a workspace for the window of one command.
277// neferwl spawns the command at startup; the window it opens goes to the
278// slot. Cells is its width in cells, a cell being one max-columns-th of
279// the usable width (1 to 16; 0 shares the width with the other columns).
280type SlotConfig struct {
281 Index int
282 Cells int
283 Argv []string
284}
285
286// WindowRule places the windows whose app ID it matches when they first map.
287// Matching rules merge in config order, a later rule winning per field.
288type WindowRule struct {
289 Name string
290 // AppID matches the whole app ID (the config anchors it).
291 AppID *regexp.Regexp
292 // Floating forces a window to float (true) or to tile (false); nil leaves it.
293 Floating *bool
294 // Workspace is a 1-based number of a numbered workspace or the name of a
295 // declared one; empty leaves it.
296 Workspace string
297 // Monitor is a connector (DP-2) or a monitor key ("make model serial").
298 Monitor string
299 // Cells is the width in cells of the new column of a tiled window
300 // (1 to 16; 0 leaves it automatic).
301 Cells int
302}