v0.6.0 d4696de

args.go RawHistoryFolder

1package server
2
3import (
4	"math"
5	"runtime"
6	"unsafe"
7)
8
9// Arg is one raw union wl_argument value.
10type Arg uint64
11
12// Fixed is a wl_fixed_t: a signed 24.8 fixed-point number.
13type Fixed int32
14
15func FixedFromFloat(v float64) Fixed { return Fixed(math.Round(v * 256)) }
16func (f Fixed) Float() float64       { return float64(f) / 256 }
17
18// Argument constructors for PostEvent.
19func Uint(v uint32) Arg    { return Arg(v) }
20func Int(v int32) Arg      { return Arg(uint32(v)) }
21func FixedArg(v Fixed) Arg { return Arg(uint32(v)) }
22
23// Fd passes a file descriptor. libwayland duplicates it, so the caller keeps
24// ownership.
25func Fd(fd int) Arg { return Arg(uint32(int32(fd))) }
26
27// Object passes a resource, or a null object when r is nil.
28func Object(r *Resource) Arg {
29	if r == nil {
30		return 0
31	}
32	return Arg(r.c)
33}
34
35// NewID passes a resource created for a new_id event argument.
36func NewID(r *Resource) Arg { return Object(r) }
37
38// String passes a string. The bytes stay pinned until p is unpinned, which
39// must happen after PostEvent returns. With null set, "" is sent as NULL.
40func String(p *runtime.Pinner, s string, null bool) Arg {
41	if null && s == "" {
42		return 0
43	}
44	b := make([]byte, len(s)+1)
45	copy(b, s)
46	p.Pin(&b[0])
47	return Arg(uintptr(unsafe.Pointer(&b[0])))
48}
49
50// wlArray matches struct wl_array on LP64 (size_t, size_t, void *).
51type wlArray struct {
52	size  uintptr
53	alloc uintptr
54	data  unsafe.Pointer
55}
56
57// Array passes a byte array. See String for the pinning rule.
58func Array(p *runtime.Pinner, b []byte) Arg {
59	a := &wlArray{size: uintptr(len(b)), alloc: uintptr(len(b))}
60	if len(b) > 0 {
61		p.Pin(&b[0])
62		a.data = unsafe.Pointer(&b[0])
63	}
64	p.Pin(a)
65	return Arg(uintptr(unsafe.Pointer(a)))
66}
67
68// Request argument accessors. Values are only valid during dispatch; the
69// String and Array accessors copy.
70func (a Arg) Uint() uint32  { return uint32(a) }
71func (a Arg) Int() int32    { return int32(uint32(a)) }
72func (a Arg) Fixed() Fixed  { return Fixed(int32(uint32(a))) }
73func (a Arg) NewID() uint32 { return uint32(a) }
74
75// Resource returns the object argument, nil for a null object. An object
76// libwayland created itself (wl_registry, wl_callback of wl_display) comes
77// back as a bare handle: Destroy works, it has no handler, version or client.
78// Like other arguments, a bare handle is only valid during the dispatch; do
79// not retain it.
80func (a Arg) Resource() *Resource {
81	if r := live.resources[uintptr(a)]; r != nil || a == 0 {
82		return r
83	}
84	return &Resource{c: uintptr(a), bare: true}
85}
86
87// Fd returns a received file descriptor. The handler owns it and must close it.
88func (a Arg) Fd() int { return int(int32(uint32(a))) }
89
90// String copies a received string; NULL becomes "".
91func (a Arg) String() string {
92	p := *(*unsafe.Pointer)(unsafe.Pointer(&a)) // C memory owned by libwayland
93	if p == nil {
94		return ""
95	}
96	n := 0
97	for *(*byte)(unsafe.Add(p, n)) != 0 {
98		n++
99	}
100	return string(unsafe.Slice((*byte)(p), n))
101}
102
103// Array copies a received wl_array.
104func (a Arg) Array() []byte {
105	arr := (*wlArray)(*(*unsafe.Pointer)(unsafe.Pointer(&a))) // C memory owned by libwayland
106	if arr == nil || arr.size == 0 {
107		return nil
108	}
109	return append([]byte(nil), unsafe.Slice((*byte)(arr.data), arr.size)...)
110}

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 1

Tags 14

↑↓ moveenter openesc close