v0.8.0 446d1e3

headless.go RawHistoryFolder

1package app
2
3import (
4	"context"
5	"errors"
6	"fmt"
7	"os"
8	"path/filepath"
9
10	"github.com/bnema/neferwl/internal/adapters/headless"
11	"github.com/bnema/neferwl/internal/ports"
12	"github.com/bnema/zerowrap"
13)
14
15// headlessOptions are the settings of the virtual outputs.
16type headlessOptions struct {
17	sizes [][2]int
18	shots string
19	hdr   bool
20	raw   bool // also write latest-pq.png (headless.Options.RawHDR)
21}
22
23// runHeadless drives one virtual output per size, named HEADLESS-1, -2, ...
24// With several outputs, screenshots go to a subdirectory per output. Modes
25// are fixed, so apply answers every configuration without backend work.
26//
27// newRenderer is configured for virtual outputs by newVulkanRenderer.
28func runHeadless(ctx context.Context, o headlessOptions, apply *outputApply, ch outputChannels, curs *cursors, newRenderer func(w, h int) (ports.Renderer, error), log zerowrap.Logger) error {
29	set := newOutputSet(ctx, ch.captured)
30	set.wireSecurity(ch)
31	inventory := ports.OutputHeads{}
32	for i, size := range o.sizes {
33		name := fmt.Sprintf("HEADLESS-%d", i+1)
34		mode := ports.OutputMode{Width: size[0], Height: size[1], RefreshMilli: 60000, Preferred: true}
35		inventory.Heads = append(inventory.Heads, ports.OutputHead{Info: ports.OutputInfo{Name: name, Width: size[0], Height: size[1], RefreshMilli: 60000}, Modes: []ports.OutputMode{mode}, Current: &mode, Enabled: true})
36		dir := o.shots
37		if dir != "" && len(o.sizes) > 1 {
38			dir = filepath.Join(o.shots, name)
39			if err := os.MkdirAll(dir, 0o755); err != nil {
40				// Outputs already started stop and release their captures.
41				return errors.Join(err, set.wait())
42			}
43		}
44		cur := &headless.Cursor{}
45		curs.set(name, cur)
46		opts := headless.Options{Cursor: cur, LoadCursor: loadCursor, Width: size[0], Height: size[1], ScreenshotDir: dir, HDR: o.hdr, RawHDR: o.raw, Formats: ch.formats, Log: log, NewRenderer: newRenderer, NewCaptureRenderer: newRenderer, Name: name, Presented: ch.presented, Captured: ch.captured}
47		started := set.start(ctx, name, func(octx context.Context, sc <-chan ports.Scene, cc <-chan ports.SurfaceContent, cu <-chan ports.CursorChange, cap <-chan ports.CaptureRequest, secure <-chan ports.SecurityState, instance ports.OutputInstance) error {
48			opts.Security, opts.SecurityChanges, opts.Instance = ch.security, secure, instance
49			return headless.Run(octx, opts, sc, cc, cu, cap)
50		}, &opts.SecurityEvents)
51		if !started {
52			return set.wait()
53		}
54		select {
55		case ch.events <- ports.OutputAdded{Info: ports.OutputInfo{Name: name, Width: size[0], Height: size[1]}}:
56		case <-ctx.Done():
57			return set.wait()
58		}
59	}
60	// All virtual lifetimes have registered before this no-lease barrier.
61	if set.state.Protected {
62		set.securityEvent(ports.SecurityBackendBarrier{Generation: set.state.Generation})
63	}
64	apply.heads(inventory)
65	// The pointer starts centred on the first output, like libinput's.
66	curs.move("HEADLESS-1", float64(o.sizes[0][0])/2, float64(o.sizes[0][1])/2, false)
67	for {
68		configs, configNext := apply.configOut(ch.configured), apply.config
69		replies, replyNext := apply.replyOut(ch.replies)
70		heads, headsNext := apply.headsOut(ch.heads)
71		contents, contentOut, contentNext, contentOwner := set.contentOut(ch.contents)
72		select {
73		case <-ctx.Done():
74			return set.wait()
75		case state, ok := <-ch.securityChanges:
76			if !ok {
77				ch.securityChanges = nil
78				continue
79			}
80			if set.setSecurity(state) && set.state.Protected {
81				set.securityEvent(ports.SecurityBackendBarrier{Generation: set.state.Generation})
82			}
83		case ev := <-ch.reloads:
84			apply.reload(ev.Config)
85		case req := <-ch.requests:
86			apply.request(req)
87		case configs <- configNext:
88			apply.configSent()
89		case replies <- replyNext:
90			apply.replySent()
91		case heads <- headsNext:
92			apply.headsSent()
93		case s := <-ch.scenes:
94			set.scenes(s)
95		case c := <-contents:
96			set.content(c)
97		case contentOut <- contentNext:
98			contentOwner.contentSent()
99		case q := <-ch.captures:
100			set.routeCapture(q)
101		case c := <-ch.cursorChanges:
102			set.setCursor(c)
103		case stopped := <-set.stopped:
104			if !set.stoppedCurrent(stopped) {
105				continue
106			}
107			// An owner error is not protection or removal evidence.
108			err := set.finish(stopped.name)
109			return errors.Join(err, set.wait())
110		}
111	}
112}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 23

Tags 10

↑↓ moveenter openesc close