v0.10.0 d5d679d

queue.go RawHistoryFolder

1// Package presented queues the OutputPresented reports an output owner sends
2// to wayland: what the output read, held and flipped.
3package presented
4
5import (
6	"maps"
7
8	"github.com/bnema/neferwl/internal/ports"
9)
10
11// Queue holds the reports an output has not pushed to wayland yet. The owner
12// goroutine flushes it every loop turn, so it holds the few reports of one
13// turn; the sink alone bounds what waits for the display loop (and merges
14// flips when that stalls). Its owner goroutine is the only user. The Seen and
15// ChildReads maps of a queued report are immutable snapshots: wayland may
16// still read an earlier report on another goroutine, so a snapshot is
17// replaced by a clone when its content changes and an unchanged report
18// allocates nothing.
19type Queue struct {
20	unsent      []ports.OutputPresented
21	seen, reads map[ports.WindowID]uint64
22}
23
24// Push queues r. Its Seen and ChildReads may be the caller's scratch maps:
25// the queue keeps snapshots. A flip-less report replaces the newest queued
26// one when that one has no flip, or keeps its flip; every flip is queued.
27func (q *Queue) Push(r ports.OutputPresented) {
28	if !maps.Equal(q.seen, r.Seen) {
29		q.seen = maps.Clone(r.Seen)
30	}
31	if !maps.Equal(q.reads, r.ChildReads) {
32		q.reads = maps.Clone(r.ChildReads)
33	}
34	r.Seen, r.ChildReads = q.seen, q.reads
35	if n := len(q.unsent); n > 0 && (r.Flip == nil || q.unsent[n-1].Flip == nil) {
36		if r.Flip == nil {
37			r.Flip = q.unsent[n-1].Flip
38		}
39		q.unsent[n-1] = r
40		return
41	}
42	q.unsent = append(q.unsent, r)
43}
44
45// Merge folds old into next: next counts it as merged and shows what
46// old showed, so feedbacks waiting on old are answered (as discarded).
47// Wayland's presentation sink uses it when its ring overflows.
48func Merge(old, next *ports.FlipInfo) {
49	next.Merged += 1 + old.Merged
50	// A snapshot can be shared with previously sent flips. Clone only when
51	// a merge actually needs to add an absent window.
52	cloned := false
53	for id, seq := range old.Shows {
54		if _, ok := next.Shows[id]; ok {
55			continue
56		}
57		if !cloned {
58			next.Shows = maps.Clone(next.Shows)
59			cloned = true
60		}
61		if next.Shows == nil {
62			next.Shows = make(map[ports.WindowID]uint64)
63		}
64		next.Shows[id] = seq
65	}
66}
67
68// Flush pushes every queued report to sink, oldest first, and empties the
69// queue. Push never blocks.
70func (q *Queue) Flush(sink ports.PresentationSink) {
71	for _, r := range q.unsent {
72		sink.Push(r)
73	}
74	q.Reset()
75}
76
77// Len is the number of queued reports.
78func (q *Queue) Len() int { return len(q.unsent) }
79
80// Unsent returns the queued reports, oldest first. Callers must not modify
81// them.
82func (q *Queue) Unsent() []ports.OutputPresented { return q.unsent }
83
84// Seen is the Seen snapshot of the last pushed report.
85func (q *Queue) Seen() map[ports.WindowID]uint64 { return q.seen }
86
87// Reset drops queued reports, e.g. when a security epoch makes them stale.
88// Snapshots stay: they may be shared with reports already sent.
89func (q *Queue) Reset() {
90	clear(q.unsent)
91	q.unsent = q.unsent[:0]
92}

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