cursor.go RawHistoryFolder

1package headless
2
3import (
4	"image"
5	"sync"
6
7	"github.com/bnema/neferwl/internal/ports"
8)
9
10// Cursor is the software cursor drawn into screenshots; it plays the role of
11// the DRM cursor plane. Move is called from the input goroutine.
12type Cursor struct {
13	mu     sync.Mutex
14	x, y   float64
15	img    ports.CursorImage
16	hidden bool
17}
18
19func (c *Cursor) Move(x, y float64) {
20	c.mu.Lock()
21	c.x, c.y, c.hidden = x, y, false
22	c.mu.Unlock()
23}
24
25// Hide stops drawing the cursor until the next move.
26func (c *Cursor) Hide() {
27	c.mu.Lock()
28	c.hidden = true
29	c.mu.Unlock()
30}
31
32func (c *Cursor) set(img ports.CursorImage) {
33	c.mu.Lock()
34	c.img = img
35	c.mu.Unlock()
36}
37
38// draw blends the premultiplied cursor over dst with its hotspot at (x, y).
39func (c *Cursor) draw(dst *image.RGBA) {
40	c.drawSecure(dst, nil)
41}
42
43func (c *Cursor) drawSecure(dst *image.RGBA, security ports.SessionSecurity) {
44	c.mu.Lock()
45	defer c.mu.Unlock()
46	if c.hidden || security != nil && security.Snapshot().Protected {
47		return
48	}
49	img := c.img
50	ox, oy := int(c.x)-img.HotX, int(c.y)-img.HotY
51	b := dst.Bounds()
52	for y := range img.H {
53		for x := range img.W {
54			dx, dy := ox+x, oy+y
55			if !image.Pt(dx, dy).In(b) {
56				continue
57			}
58			s := img.Pixels[(y*img.W+x)*4:]
59			a := int(s[3])
60			if a == 0 {
61				continue
62			}
63			d := dst.Pix[dst.PixOffset(dx, dy):]
64			// Source is premultiplied B,G,R,A; dst is straight R,G,B,A (opaque).
65			// min guards against themes that are not really premultiplied.
66			d[0] = byte(min(255, int(s[2])+int(d[0])*(255-a)/255))
67			d[1] = byte(min(255, int(s[1])+int(d[1])*(255-a)/255))
68			d[2] = byte(min(255, int(s[0])+int(d[2])*(255-a)/255))
69		}
70	}
71}

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 25

Tags 10

↑↓ moveenter openesc close