exclusion.go RawHistoryFolder
1package testserver
2
3import (
4 "github.com/bnema/purego-libwayland/protocol/extimagecopycapture"
5 "github.com/bnema/purego-libwayland/protocol/wayland"
6
7 "github.com/bnema/nefercap/internal/adapters/wayland/testserver/neferwl"
8)
9
10type exclusionManager struct{ s *Server }
11
12func (exclusionManager) Destroy(*neferwl.NeferwlCaptureExclusionManagerV1) {}
13
14func (m exclusionManager) GetExclusion(self *neferwl.NeferwlCaptureExclusionManagerV1, id uint32, sess *extimagecopycapture.ExtImageCopyCaptureSessionV1) {
15 s := m.s
16 res, err := neferwl.NewNeferwlCaptureExclusionV1(self.Client(), 1, id, exclusionHandler{s})
17 if err != nil {
18 return
19 }
20 s.stats.Exclusions++
21 res.OnDestroy = func() { s.stats.DestroyedExclusions++ }
22 if s.cfg.ExclusionFail != 0 {
23 res.SendFailed(s.cfg.ExclusionFail - 1)
24 return
25 }
26 res.SendToken(Token)
27}
28
29func (m exclusionManager) AttachSurface(self *neferwl.NeferwlCaptureExclusionManagerV1, id uint32, token string, _ *wayland.Surface) {
30 s := m.s
31 res, err := neferwl.NewNeferwlCaptureLayerV1(self.Client(), 1, id, layerHandler{})
32 if err != nil {
33 return
34 }
35 s.stats.Attached = append(s.stats.Attached, token)
36 s.layers = append(s.layers, res.Resource)
37 layer := res
38 switch {
39 case s.cfg.AttachSilent:
40 case s.cfg.AttachFail != 0:
41 layer.SendFailed(s.cfg.AttachFail - 1)
42 default:
43 layer.SendAttached()
44 }
45}
46
47type exclusionHandler struct{ s *Server }
48
49func (exclusionHandler) Destroy(*neferwl.NeferwlCaptureExclusionV1) {}
50
51type layerHandler struct{}
52
53func (layerHandler) Destroy(*neferwl.NeferwlCaptureLayerV1) {}
54
55// Detach sends detached(reason) on the n-th attached layer.
56func (s *Server) Detach(n int, reason uint32) {
57 s.Do(func() {
58 if n < len(s.layers) {
59 neferwl.WrapNeferwlCaptureLayerV1(s.layers[n]).SendDetached(reason)
60 }
61 })
62}
63
64// SendRaw posts a layer event out of order, to test violations: opcode 0
65// attached, 1 failed, 2 detached.
66func (s *Server) SendRaw(n int, opcode uint32, arg uint32) {
67 s.Do(func() {
68 if n >= len(s.layers) {
69 return
70 }
71 l := neferwl.WrapNeferwlCaptureLayerV1(s.layers[n])
72 switch opcode {
73 case 0:
74 l.SendAttached()
75 case 1:
76 l.SendFailed(arg)
77 default:
78 l.SendDetached(arg)
79 }
80 })
81}