1package wayland
2
3import (
4 "math"
5
6 "github.com/bnema/go-wayland-bindings/server/singlepixelbuffer"
7 "github.com/bnema/go-wayland-bindings/server/wayland"
8 "github.com/bnema/neferwl/internal/ports"
9 "github.com/bnema/purego-libwayland/server"
10)
11
12// wp_single_pixel_buffer_v1: a 1x1 wl_buffer of one color. Clients use it
13// for solid backgrounds and letterbox bars; the renderer draws it as a fill
14// (ports.SurfaceContent.Solid) and no pixels are ever read or imported.
15
16func registerSinglePixelBuffer(d *server.Display, s *Server) error {
17 return singlepixelbuffer.NewWpSinglePixelBufferManagerV1Global(d, 1, func(c server.Client, v, id uint32) {
18 _, _ = singlepixelbuffer.NewWpSinglePixelBufferManagerV1(c, int32(v), id, singlePixelManager{s})
19 })
20}
21
22type singlePixelManager struct{ server *Server }
23
24func (singlePixelManager) Destroy(*singlepixelbuffer.WpSinglePixelBufferManagerV1) {}
25
26// CreateU32RgbaBuffer takes 32-bit components already premultiplied by
27// alpha, like client pixels; they become unit floats.
28func (m singlePixelManager) CreateU32RgbaBuffer(r *singlepixelbuffer.WpSinglePixelBufferManagerV1, id, red, green, blue, alpha uint32) {
29 unit := func(v uint32) float32 { return float32(float64(v) / math.MaxUint32) }
30 buf := &singlePixelBuffer{
31 color: ports.SolidColor{R: unit(red), G: unit(green), B: unit(blue), A: unit(alpha)},
32 opaque: alpha == math.MaxUint32,
33 }
34 res, err := wayland.NewBuffer(r.Client(), 1, id, buf)
35 if err != nil {
36 return
37 }
38 m.server.addBuffer(res, buf)
39}
40
41// singlePixelBuffer is a wl_buffer of one color. The color is never mutated,
42// so content shares it between commits.
43type singlePixelBuffer struct {
44 color ports.SolidColor
45 opaque bool
46}
47
48func (*singlePixelBuffer) Destroy(*wayland.Buffer) {}
49
50func (*singlePixelBuffer) size() (int, int) { return 1, 1 }
51
52func (b *singlePixelBuffer) content(id ports.WindowID) (ports.SurfaceContent, bool) {
53 return ports.SurfaceContent{ID: id, Width: 1, Height: 1, Opaque: b.opaque, Solid: &b.color}, true
54}