detached 7576621

feat(core): generate canonical core bindings and harden event transport

commit
75766210f33cf0f15489c80f4b602dfd3331388f
author
brice · · 2026-09-28 07:15 UTC
parent
d5c3b4c
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
13 files · +4780 -687
A benchmark_test.go +26 -0
@@ -0,0 +1,26 @@
1+package wlturbo
2+
3+import "testing"
4+
5+// BenchmarkWireDispatch isolates framed typed dispatch from socket scheduling.
6+func BenchmarkWireDispatch(b *testing.B) {
7+ d := newDisplay(&chunkConn{})
8+ p := &benchProxy{BaseProxy: BaseProxy{id: 7, context: d.context}}
9+ d.context.Register(p)
10+ f := receivedFrame{object: 7, opcode: 0, body: []byte{1, 0, 0, 0}}
11+ b.ReportAllocs()
12+ b.ResetTimer()
13+ for i := 0; i < b.N; i++ {
14+ if err := d.dispatchFrame(f); err != nil {
15+ b.Fatal(err)
16+ }
17+ }
18+}
19+
20+type benchProxy struct {
21+ BaseProxy
22+ value uint32
23+}
24+
25+func (p *benchProxy) EventSignature(op uint16) (string, bool) { return "uint,", op == 0 }
26+func (p *benchProxy) Dispatch(e *Event) { p.value = e.Uint32() }
M client.go +175 -224
@@ -13,6 +13,7 @@ import (
1313 "net"
1414 "os"
1515 "path/filepath"
16+ "strings"
1617 "sync"
1718 "sync/atomic"
1819 )
@@ -44,13 +45,15 @@ type Object interface {
4445
4546 // Display represents a connection to the Wayland display
4647 type Display struct {
47- conn net.Conn
48- unix *net.UnixConn // set when conn is a Unix socket, nil otherwise
49- objects sync.Map // map[uint32]Object
50- nextID uint32
51- sendMu sync.Mutex
52- recvMu sync.Mutex
53- listeners sync.Map // map[uint32]map[uint16][]func([]byte)
48+ conn net.Conn
49+ unix *net.UnixConn // set when conn is a Unix socket, nil otherwise
50+ objects sync.Map // map[uint32]Object
51+ nextID uint32
52+ sendMu sync.Mutex
53+ recvMu sync.Mutex
54+ signatures sync.Map
55+ listenerMu sync.Mutex
56+ listeners sync.Map // map[uint32]map[uint16][]func([]byte)
5457
5558 // High-performance event dispatcher
5659 dispatcher *EventDispatcher
@@ -73,7 +76,6 @@ type Display struct {
7376 readErr error
7477 maxMsgLen uint32
7578 closed atomic.Bool
76- fdMu sync.Mutex
7779 pendingFDs []int
7880 }
7981
@@ -103,11 +105,12 @@ func newDisplay(conn net.Conn) *Display {
103105
104106 // Registry represents the global registry
105107 type Registry struct {
106- id uint32
107- display *Display
108- globals map[uint32]Global
109- mu sync.RWMutex
110- handlers map[string]GlobalHandler
108+ id uint32
109+ display *Display
110+ globals map[uint32]Global
111+ mu sync.RWMutex
112+ handlers map[string]GlobalHandler
113+ removeHandlers []RegistryGlobalRemoveHandler
111114 }
112115
113116 // callbackObject represents a wl_callback object
@@ -119,6 +122,12 @@ type callbackObject struct {
119122 func (c *callbackObject) ID() uint32 {
120123 return c.id
121124 }
125+func (c *callbackObject) EventSignature(op uint16) (string, bool) {
126+ if op == 0 {
127+ return "uint,", true
128+ }
129+ return "", false
130+}
122131
123132 // Dispatch handles callback events (opcode 0 = done)
124133 func (c *callbackObject) Dispatch(event *Event) {
@@ -126,6 +135,7 @@ func (c *callbackObject) Dispatch(event *Event) {
126135 return
127136 }
128137 c.display.notifyListeners(c.id, 0, event.data)
138+ c.display.context.Unregister(c)
129139 }
130140
131141 // Global represents a global object
@@ -138,6 +148,16 @@ type Global struct {
138148 // GlobalHandler is called when a global is announced
139149 type GlobalHandler func(registry *Registry, name uint32, version uint32)
140150
151+// ConnectFromConn attaches to an established Wayland socket and requests its registry.
152+func ConnectFromConn(conn net.Conn) (*Display, error) {
153+ d := newDisplay(conn)
154+ if err := d.getRegistry(); err != nil {
155+ _ = d.Close()
156+ return nil, fmt.Errorf("get registry: %w", err)
157+ }
158+ return d, nil
159+}
160+
141161 // Connect connects to the Wayland display and requests the registry.
142162 func Connect(socketPath string) (*Display, error) {
143163 if socketPath == "" {
@@ -161,16 +181,7 @@ func Connect(socketPath string) (*Display, error) {
161181 return nil, fmt.Errorf("failed to connect to Wayland: %w", err)
162182 }
163183
164- d := newDisplay(conn)
165-
166- // Get registry
167- if err := d.getRegistry(); err != nil {
168- _ = d.Close()
169- return nil, fmt.Errorf("failed to get registry: %w", err)
170- }
171-
172- // Don't do initial roundtrip here - let the caller do it after setting up handlers
173- return d, nil
184+ return ConnectFromConn(conn)
174185 }
175186
176187 // Close closes the display connection. It is safe to call more than once;
@@ -179,8 +190,14 @@ func (d *Display) Close() error {
179190 if !d.closed.CompareAndSwap(false, true) {
180191 return nil
181192 }
193+ d.context.closed.Store(true)
194+ err := d.conn.Close()
195+ d.sendMu.Lock()
196+ d.sendMu.Unlock()
197+ d.recvMu.Lock()
182198 d.closePendingFDs()
183- return d.conn.Close()
199+ d.recvMu.Unlock()
200+ return err
184201 }
185202
186203 // Closed reports whether the connection has been closed.
@@ -235,8 +252,8 @@ func (d *Display) SendRequestWithFDs(objectID uint32, opcode uint16, fds []int,
235252
236253 // Update header with actual size in bytes
237254 bufLen := buf.Len()
238- if bufLen > 0xFFFF {
239- return fmt.Errorf("message too large: %d bytes", bufLen)
255+ if bufLen > 0xFFFF || bufLen%4 != 0 {
256+ return fmt.Errorf("invalid message size: %d bytes", bufLen)
240257 }
241258 size := uint32(bufLen) // Safe: checked above
242259 binary.LittleEndian.PutUint32(header[0:4], objectID)
@@ -263,7 +280,7 @@ func (d *Display) marshalArg(buf *bytes.Buffer, arg interface{}) error {
263280 case string:
264281 // String format: length (including null) + string + null + padding
265282 strlen := len(v) + 1
266- if strlen > 0xFFFFFFFF {
283+ if strlen > 0xffff-HeaderSize {
267284 return fmt.Errorf("string too long: %d bytes", strlen)
268285 }
269286 if err := binary.Write(buf, binary.LittleEndian, uint32(strlen)); err != nil { // Safe: checked above
@@ -279,7 +296,7 @@ func (d *Display) marshalArg(buf *bytes.Buffer, arg interface{}) error {
279296 case []byte:
280297 // Array format: length + data + padding
281298 arrlen := len(v)
282- if arrlen > 0xFFFFFFFF {
299+ if arrlen > 0xffff-HeaderSize {
283300 return fmt.Errorf("array too long: %d bytes", arrlen)
284301 }
285302 if err := binary.Write(buf, binary.LittleEndian, uint32(arrlen)); err != nil {
@@ -329,6 +346,9 @@ func (d *Display) Dispatch() error {
329346 }
330347
331348 frame, err := d.nextFrame()
349+ if d.closed.Load() {
350+ return net.ErrClosed
351+ }
332352 if err != nil {
333353 return d.fail(err)
334354 }
@@ -346,6 +366,9 @@ func (d *Display) fail(err error) error {
346366 if errors.As(err, &perr) {
347367 d.closePendingFDs()
348368 }
369+ if errors.Is(err, io.ErrUnexpectedEOF) {
370+ d.closePendingFDs()
371+ }
349372 return err
350373 }
351374
@@ -376,6 +399,9 @@ func (d *Display) nextFrame() (receivedFrame, error) {
376399 }
377400 }
378401 if err := d.fill(); err != nil {
402+ if d.closed.Load() {
403+ return receivedFrame{}, net.ErrClosed
404+ }
379405 return receivedFrame{}, err
380406 }
381407 }
@@ -416,40 +442,85 @@ func (d *Display) fill() error {
416442 return nil
417443 }
418444
419-// dispatchFrame delivers one complete frame to the object that owns it.
445+// signatureProvider is implemented by generated objects; every opcode must
446+// have a known signature before any descriptor can be assigned or dispatched.
447+type signatureProvider interface{ EventSignature(uint16) (string, bool) }
448+
449+// dispatchFrame delivers one complete frame with precisely its signature's FDs.
420450 func (d *Display) dispatchFrame(f receivedFrame) error {
421451 if f.object == displayObjectID {
452+ if len(d.pendingFDs) != 0 && len(d.rbuf) == 0 {
453+ return &ProtocolError{Kind: "extra_fd", Err: ErrMalformedFrame}
454+ }
422455 return d.handleDisplayEvent(f.opcode, f.body)
423456 }
424-
425457 obj, ok := d.objects.Load(f.object)
426458 if !ok {
427- return &ProtocolError{
428- Kind: "unknown_object",
429- Object: f.object,
430- Opcode: f.opcode,
431- Size: uint32(len(f.body)) + HeaderSize,
432- Err: ErrUnknownObject,
459+ return &ProtocolError{Kind: "unknown_object", Object: f.object, Opcode: f.opcode, Err: ErrUnknownObject}
460+ }
461+ sig, valid := "", false
462+ p, isGenerated := obj.(signatureProvider)
463+ if isGenerated {
464+ sig, valid = p.EventSignature(f.opcode)
465+ }
466+ // Legacy custom proxies may declare their signatures with RegisterEventSignature.
467+ if !valid && !isGenerated {
468+ if v, ok := d.signatures.Load(signatureKey{f.object, f.opcode}); ok {
469+ sig, valid = v.(string), true
433470 }
434471 }
472+ if !valid {
473+ return &ProtocolError{Kind: "unknown_opcode", Object: f.object, Opcode: f.opcode, Err: ErrUnknownOpcode}
474+ }
475+ if err := validateEventBody(sig, f.body); err != nil {
476+ return &ProtocolError{Kind: "malformed_payload", Object: f.object, Opcode: f.opcode, Err: err}
477+ }
478+ count := strings.Count(sig, "fd,")
479+ if len(d.pendingFDs) < count {
480+ return &ProtocolError{Kind: "missing_fd", Object: f.object, Opcode: f.opcode, Err: ErrMalformedFrame}
481+ }
482+ ev := eventPool.Get().(*Event)
483+ *ev = Event{ProxyID: f.object, Opcode: f.opcode, data: f.body, display: d}
484+ if count != 0 {
485+ ev.fds = make([]*OwnedFD, count)
486+ for i := range ev.fds {
487+ ev.fds[i] = &OwnedFD{fd: d.pendingFDs[i]}
488+ }
489+ d.pendingFDs = d.pendingFDs[count:]
490+ }
491+ defer func() {
492+ for _, fd := range ev.fds {
493+ _ = fd.Close()
494+ }
495+ *ev = Event{}
496+ eventPool.Put(ev)
497+ }()
498+ // FDs from a single recvmsg can accompany multiple coalesced frames. Once
499+ // all buffered bytes have been framed, surplus descriptors are not legal.
500+ if len(d.rbuf) == 0 && len(d.pendingFDs) != 0 {
501+ return &ProtocolError{Kind: "extra_fd", Object: f.object, Opcode: f.opcode, Err: ErrMalformedFrame}
502+ }
503+ if proxy, ok := obj.(Proxy); ok {
504+ proxy.Dispatch(ev)
505+ } else {
506+ d.dispatcher.Dispatch(f.object, f.opcode, f.body)
507+ d.notifyListeners(f.object, f.opcode, f.body)
508+ }
509+ return nil
510+}
435511
436- // Server-created objects are announced by an event on a known object.
437- d.handleServerObject(f.object, f.opcode, f.body)
512+type signatureKey struct {
513+ object uint32
514+ opcode uint16
515+}
438516
439- if proxy, ok := obj.(Proxy); ok && proxy != nil {
440- proxy.Dispatch(&Event{
441- ProxyID: f.object,
442- Opcode: f.opcode,
443- data: f.body,
444- display: d,
445- })
446- return nil
517+// RegisterEventSignature defines a signature for a legacy proxy. Generated
518+// proxies supply it themselves and cannot be overridden.
519+func (d *Display) RegisterEventSignature(object uint32, opcode uint16, signature string) {
520+ if object == 0 || object == displayObjectID {
521+ return
447522 }
448-
449- // High-performance dispatcher, then compatibility listeners.
450- d.dispatcher.Dispatch(f.object, f.opcode, f.body)
451- d.notifyListeners(f.object, f.opcode, f.body)
452- return nil
523+ d.signatures.Store(signatureKey{object, opcode}, signature)
453524 }
454525
455526 // notifyListeners runs the listeners registered for an object and opcode.
@@ -466,11 +537,7 @@ func (d *Display) notifyListeners(objectID uint32, opcode uint16, body []byte) {
466537 if !ok {
467538 return
468539 }
469- handlerSlice, ok := handlers.(*[]func([]byte))
470- if !ok || handlerSlice == nil {
471- return
472- }
473- for _, handler := range *handlerSlice {
540+ for _, handler := range handlers.([]func([]byte)) {
474541 if handler != nil {
475542 handler(body)
476543 }
@@ -481,8 +548,8 @@ func (d *Display) notifyListeners(objectID uint32, opcode uint16, body []byte) {
481548 func (d *Display) handleDisplayEvent(opcode uint16, data []byte) error {
482549 switch opcode {
483550 case 0: // error
484- if len(data) < 8 {
485- return &ProtocolError{Kind: "short_display_error", Object: displayObjectID, Opcode: opcode, Size: uint32(len(data)) + HeaderSize, Err: ErrMalformedFrame}
551+ if err := validateEventBody("object,uint,string,", data); err != nil {
552+ return &ProtocolError{Kind: "malformed_display_error", Err: err}
486553 }
487554 event := &Event{ProxyID: displayObjectID, Opcode: opcode, data: data, display: d}
488555 objectID := event.Uint32()
@@ -495,11 +562,12 @@ func (d *Display) handleDisplayEvent(opcode uint16, data []byte) error {
495562 return d.lastError
496563
497564 case 1: // delete_id
498- if len(data) < 4 {
565+ if len(data) != 4 {
499566 return &ProtocolError{Kind: "short_delete_id", Object: displayObjectID, Opcode: opcode, Size: uint32(len(data)) + HeaderSize, Err: ErrMalformedFrame}
500567 }
501568 id := binary.LittleEndian.Uint32(data[0:4])
502569 d.objects.Delete(id)
570+ d.context.proxies.Delete(id)
503571 return nil
504572
505573 default:
@@ -507,55 +575,42 @@ func (d *Display) handleDisplayEvent(opcode uint16, data []byte) error {
507575 }
508576 }
509577
510-// Roundtrip performs a synchronous roundtrip to the compositor
578+// Roundtrip waits for one wl_display.sync callback. Concurrent event loops
579+// must not call Roundtrip while another goroutine dispatches this connection.
511580 func (d *Display) Roundtrip() error {
512- callbackID := d.allocateID()
513- done := make(chan error, 1)
514-
515- d.AddListener(callbackID, 0, func(_ []byte) {
516- d.objects.Delete(callbackID)
517- done <- nil
518- })
519-
520- // Send sync request (opcode 0)
521- if err := d.SendRequest(displayObjectID, 0, callbackID); err != nil {
581+ callback, err := d.Sync()
582+ if err != nil {
522583 return err
523584 }
524-
525- d.objects.Store(callbackID, &callbackObject{
526- BaseProxy: BaseProxy{
527- context: d.Context(),
528- id: callbackID,
529- },
530- display: d,
531- })
532-
533- for i := 0; i < 1000; i++ {
534- if err := d.Dispatch(); err != nil {
585+ for {
586+ if err = d.Dispatch(); err != nil {
535587 return err
536588 }
537- select {
538- case err := <-done:
539- return err
540- default:
589+ if _, exists := d.objects.Load(callback.ID()); !exists {
590+ return nil
541591 }
542592 }
543-
544- return fmt.Errorf("roundtrip failed: max iterations reached")
545593 }
546594
547595 // AddListener adds an event listener for an object
548596 func (d *Display) AddListener(objectID uint32, opcode uint16, handler func([]byte)) {
597+ if handler == nil {
598+ return
599+ }
549600 // Load or create listener map for object
550601 listeners, _ := d.listeners.LoadOrStore(objectID, &sync.Map{})
551602 opcodeMap := listeners.(*sync.Map)
552603
553- // Load or create handlers slice for opcode
554- handlers, _ := opcodeMap.LoadOrStore(opcode, &[]func([]byte){})
555- handlerSlice := handlers.(*[]func([]byte))
556-
557- // Add handler (thread-safe)
558- *handlerSlice = append(*handlerSlice, handler)
604+ d.listenerMu.Lock()
605+ defer d.listenerMu.Unlock()
606+ var handlers []func([]byte)
607+ if old, ok := opcodeMap.Load(opcode); ok {
608+ handlers = old.([]func([]byte))
609+ }
610+ next := make([]func([]byte), len(handlers)+1)
611+ copy(next, handlers)
612+ next[len(handlers)] = handler
613+ opcodeMap.Store(opcode, next)
559614 }
560615
561616 // getRegistry gets the global registry
@@ -581,15 +636,13 @@ func (r *Registry) ID() uint32 {
581636 // handleGlobal handles global announcements
582637 func (r *Registry) handleGlobal(data []byte) {
583638 if len(data) < 8 {
584- // log.Printf("wlclient: handleGlobal: data too short (%d bytes)", len(data))
585639 return
586640 }
587641
588642 name := binary.LittleEndian.Uint32(data[0:4])
589643 ifaceLen := binary.LittleEndian.Uint32(data[4:8])
590644
591- if len(data) < 8+int(ifaceLen)+4 {
592- // log.Printf("wlclient: handleGlobal: insufficient data for interface string (need %d, have %d)", 8+int(ifaceLen)+4, len(data))
645+ if ifaceLen == 0 || uint64(ifaceLen)+12 > uint64(len(data)) || data[8+ifaceLen-1] != 0 {
593646 return
594647 }
595648
@@ -600,15 +653,12 @@ func (r *Registry) handleGlobal(data []byte) {
600653 padding := (4 - (ifaceLen % 4)) % 4
601654 versionOffset := 8 + int(ifaceLen) + int(padding)
602655
603- if len(data) < versionOffset+4 {
604- // log.Printf("wlclient: handleGlobal: insufficient data for version (need %d, have %d)", versionOffset+4, len(data))
656+ if len(data) != versionOffset+4 {
605657 return
606658 }
607659
608660 version := binary.LittleEndian.Uint32(data[versionOffset:])
609661
610- // log.Printf("wlclient: global announced: %s v%d (name=%d)", iface, version, name)
611-
612662 // Store global
613663 r.mu.Lock()
614664 r.globals[name] = Global{
@@ -619,15 +669,19 @@ func (r *Registry) handleGlobal(data []byte) {
619669 r.mu.Unlock()
620670
621671 // Call specific handler if registered
622- if handler, ok := r.handlers[iface]; ok {
623- // log.Printf("wlclient: calling handler for interface %s", iface)
672+ r.mu.RLock()
673+ handler, specific := r.handlers[iface]
674+ wildcard, all := r.handlers["*"]
675+ r.mu.RUnlock()
676+ if specific {
677+
624678 handler(r, name, version)
625679 }
626680
627681 // Call wildcard handler if registered
628- if handler, ok := r.handlers["*"]; ok {
629- // log.Printf("wlclient: calling wildcard handler for interface %s", iface)
630- handler(r, name, version)
682+ if all {
683+
684+ wildcard(r, name, version)
631685 }
632686 }
633687
@@ -641,11 +695,17 @@ func (r *Registry) handleGlobalRemove(data []byte) {
641695
642696 r.mu.Lock()
643697 delete(r.globals, name)
698+ handlers := append([]RegistryGlobalRemoveHandler(nil), r.removeHandlers...)
644699 r.mu.Unlock()
700+ for _, handler := range handlers {
701+ handler.HandleRegistryGlobalRemove(RegistryGlobalRemoveEvent{Registry: r, Name: name})
702+ }
645703 }
646704
647705 // AddHandler adds a handler for a specific interface
648706 func (r *Registry) AddHandler(iface string, handler GlobalHandler) {
707+ r.mu.Lock()
708+ defer r.mu.Unlock()
649709 r.handlers[iface] = handler
650710 }
651711
@@ -656,7 +716,7 @@ func (r *Registry) Bind(name uint32, iface string, version uint32, proxy Proxy)
656716 proxy.SetID(r.display.allocateID())
657717 }
658718
659- // Ensure proxy has a context set - CRITICAL FIX
719+ // Bootstrap a generated proxy with this display's context.
660720 if proxy.Context() == nil {
661721 if baseProxy, ok := proxy.(*BaseProxy); ok {
662722 baseProxy.SetContext(r.display.Context())
@@ -667,12 +727,18 @@ func (r *Registry) Bind(name uint32, iface string, version uint32, proxy Proxy)
667727 }
668728 }
669729
730+ if proxy.Context() != r.display.Context() {
731+ return fmt.Errorf("proxy belongs to another display")
732+ }
733+ if proxy.ID() == displayObjectID || proxy.ID() == r.id {
734+ return fmt.Errorf("reserved object ID")
735+ }
736+ if old, exists := r.display.objects.Load(proxy.ID()); exists && old != proxy {
737+ return fmt.Errorf("object ID %d already registered", proxy.ID())
738+ }
670739 // Register the proxy
671740 proxy.Context().Register(proxy)
672741
673- // Also register directly in display objects map
674- r.display.objects.Store(proxy.ID(), proxy)
675-
676742 // Send bind request (opcode 0) with proper arguments
677743 if err := r.display.SendRequest(r.id, 0, name, iface, version, proxy.ID()); err != nil {
678744 proxy.Context().Unregister(proxy)
@@ -718,118 +784,3 @@ func (r *Registry) FindGlobal(iface string) (Global, bool) {
718784 }
719785 return Global{}, false
720786 }
721-
722-// handleServerObject creates and registers server-allocated objects from events
723-func (d *Display) handleServerObject(objectID uint32, opcode uint16, body []byte) bool {
724- // Handle specific known protocols that create server objects
725- obj, ok := d.objects.Load(objectID)
726- if !ok {
727- return false
728- }
729-
730- // Check if this is a known object type that creates server objects
731- switch obj.(type) {
732- case *Registry:
733- // Registry doesn't create server objects directly
734- return false
735-
736- default:
737- // Check if this might be an output manager (interface zwlr_output_manager_v1)
738- if objectID == 5 { // This is likely the output manager based on your logs
739- return d.handleOutputManagerEvent(objectID, opcode, body)
740- }
741- }
742-
743- return false
744-}
745-
746-// handleOutputManagerEvent handles events from zwlr_output_manager_v1
747-func (d *Display) handleOutputManagerEvent(objectID uint32, opcode uint16, body []byte) bool {
748- switch opcode {
749- case 0: // head event - creates new zwlr_output_head_v1 object
750- if len(body) < 4 {
751- return false
752- }
753-
754- // Parse the new_id for the head object
755- headID := binary.LittleEndian.Uint32(body[0:4])
756-
757- // Create a proper OutputHead object
758- headProxy := &OutputHead{
759- BaseProxy: BaseProxy{
760- id: headID,
761- context: d.Context(),
762- },
763- }
764-
765- // Register the new head object
766- d.objects.Store(headID, headProxy)
767- return true
768-
769- case 1: // done event
770- return false
771-
772- case 2: // finished event
773- return false
774- }
775-
776- return false
777-}
778-
779-// OutputHead represents a zwlr_output_head_v1 object
780-type OutputHead struct {
781- BaseProxy
782- name string
783- description string
784- width int32
785- height int32
786-}
787-
788-// Dispatch handles head events
789-func (h *OutputHead) Dispatch(event *Event) {
790- switch event.Opcode {
791- case 0: // name
792- h.name = event.String()
793- case 1: // description
794- h.description = event.String()
795- case 2: // physical_size
796- h.width = event.Int32()
797- h.height = event.Int32()
798- case 3: // mode (creates new mode object)
799- modeID := event.Uint32()
800- // Create mode object
801- mode := &OutputMode{
802- BaseProxy: BaseProxy{
803- id: modeID,
804- context: h.context,
805- },
806- }
807- h.context.display.objects.Store(modeID, mode)
808- case 9: // finished
809- h.context.Unregister(h)
810- default:
811- }
812-}
813-
814-// OutputMode represents a zwlr_output_mode_v1 object
815-type OutputMode struct {
816- BaseProxy
817- width int32
818- height int32
819- refresh int32
820-}
821-
822-// Dispatch handles mode events
823-func (m *OutputMode) Dispatch(event *Event) {
824- switch event.Opcode {
825- case 0: // size
826- m.width = event.Int32()
827- m.height = event.Int32()
828- case 1: // refresh
829- m.refresh = event.Int32()
830- case 2: // preferred
831- case 3: // finished
832- m.context.Unregister(m)
833- default:
834- }
835-}
M core.go +75 -372
@@ -3,10 +3,10 @@ package wlturbo
33 import (
44 "encoding/binary"
55 "errors"
6-
7- // "log"
86 "sync"
97 "sync/atomic"
8+
9+ "golang.org/x/sys/unix"
1010 )
1111
1212 // Context provides a compatibility layer for wl.Context
@@ -37,6 +37,8 @@ type Event struct {
3737 data []byte
3838 offset int
3939 display *Display
40+ fds []*OwnedFD
41+ fdIndex int
4042 }
4143
4244 // Data returns the raw event data
@@ -74,15 +76,12 @@ func (c *Context) SendRequestWithFDs(proxy Proxy, opcode uint32, fds []int, args
7476
7577 // Register registers a proxy object
7678 func (c *Context) Register(proxy Proxy) {
77- if proxy != nil && proxy.ID() != 0 {
79+ if proxy != nil && proxy.ID() != 0 && !c.closed.Load() {
80+ if proxy.Context() != c {
81+ return
82+ }
7883 c.proxies.Store(proxy.ID(), proxy)
7984 c.display.objects.Store(proxy.ID(), proxy)
80- // Debug large IDs
81- // if proxy.ID() > 1000000 {
82- // log.Printf("wlclient: WARNING: Registering proxy with suspicious ID %d (0x%x)", proxy.ID(), proxy.ID())
83- // } else if proxy.ID() == 5 {
84- // log.Printf("wlclient: Registered output manager proxy with ID 5")
85- // }
8685 }
8786 }
8887
@@ -221,19 +220,61 @@ func (e *Event) Array() []byte {
221220 return arr
222221 }
223222
224-// Fd reads a file descriptor that was delivered out-of-band for this event.
225-// Descriptors are queued on the connection in arrival order, as the Wayland
226-// wire protocol requires. The returned descriptor is owned by the caller,
227-// which must close it. It returns 0 when the event carried no descriptor.
223+// OwnedFD owns one received descriptor. Close is idempotent; Take transfers
224+// ownership to the caller (who must close it). Descriptor zero is valid.
225+type OwnedFD struct {
226+ mu sync.Mutex
227+ fd int
228+}
229+
230+func (f *OwnedFD) Take() (int, error) {
231+ if f == nil {
232+ return -1, errors.New("missing descriptor")
233+ }
234+ f.mu.Lock()
235+ defer f.mu.Unlock()
236+ if f.fd < 0 {
237+ return -1, errors.New("descriptor already taken or closed")
238+ }
239+ n := f.fd
240+ f.fd = -1
241+ return n, nil
242+}
243+func (f *OwnedFD) Close() error {
244+ if f == nil {
245+ return nil
246+ }
247+ f.mu.Lock()
248+ defer f.mu.Unlock()
249+ if f.fd < 0 {
250+ return nil
251+ }
252+ n := f.fd
253+ f.fd = -1
254+ return unix.Close(n)
255+}
256+
257+// FD transfers ownership of the next descriptor assigned to this event.
258+// An unclaimed descriptor is closed when dispatch completes.
259+func (e *Event) FD() *OwnedFD {
260+ if e.fdIndex >= len(e.fds) {
261+ return nil
262+ }
263+ fd := e.fds[e.fdIndex]
264+ e.fds[e.fdIndex] = nil
265+ e.fdIndex++
266+ return fd
267+}
268+
269+// Fd is the legacy raw descriptor API; prefer FD for explicit ownership.
228270 func (e *Event) Fd() uintptr {
229- if e.display != nil {
230- if fd, ok := e.display.nextFD(); ok {
231- return uintptr(fd)
232- }
271+ fd := e.FD()
272+ if fd == nil {
273+ _ = e.Uint32()
274+ return 0
233275 }
234- // No descriptor was delivered: consume the placeholder argument.
235- _ = e.Uint32()
236- return 0
276+ n, _ := fd.Take()
277+ return uintptr(n)
237278 }
238279
239280 // NewId reads a new object ID from the event
@@ -278,32 +319,24 @@ type RegistryGlobalRemoveEvent struct {
278319
279320 // AddGlobalHandler adds a global handler to the registry
280321 func (r *Registry) AddGlobalHandler(handler RegistryGlobalHandler) {
281- // Store the handler to be called for ALL globals
282- r.mu.Lock()
283- defer r.mu.Unlock()
284-
285- // Initialize handlers map if needed
286- if r.handlers == nil {
287- r.handlers = make(map[string]GlobalHandler)
322+ if handler == nil {
323+ return
288324 }
289-
290325 r.AddHandler("*", func(registry *Registry, name uint32, version uint32) {
291- global, ok := r.FindGlobalByName(name)
292- if ok {
293- event := RegistryGlobalEvent{
294- Registry: r,
295- Name: name,
296- Interface: global.Interface,
297- Version: version,
298- }
299- handler.HandleRegistryGlobal(event)
326+ if global, ok := r.FindGlobalByName(name); ok {
327+ handler.HandleRegistryGlobal(RegistryGlobalEvent{Registry: r, Name: name, Interface: global.Interface, Version: version})
300328 }
301329 })
302330 }
303331
304-// AddGlobalRemoveHandler adds a global remove handler (placeholder)
332+// AddGlobalRemoveHandler registers a handler for registry removals.
305333 func (r *Registry) AddGlobalRemoveHandler(handler RegistryGlobalRemoveHandler) {
306- // Would need to implement removal handling
334+ if handler == nil {
335+ return
336+ }
337+ r.mu.Lock()
338+ r.removeHandlers = append(r.removeHandlers, handler)
339+ r.mu.Unlock()
307340 }
308341
309342 // FindGlobalByName finds a global by its name ID
@@ -340,342 +373,12 @@ func (d *Display) Sync() (Object, error) {
340373 display: d,
341374 }
342375
343- // Send sync request (opcode 0)
376+ // Store before sending: the compositor may reply immediately.
377+ d.context.Register(callback)
344378 if err := d.SendRequest(1, 0, callbackID); err != nil {
379+ d.context.Unregister(callback)
345380 return nil, err
346381 }
347382
348- // Store the callback object
349- d.objects.Store(callbackID, callback)
350-
351383 return callback, nil
352384 }
353-
354-// Additional protocol object types needed for compatibility
355-
356-// Seat capability constants
357-const (
358- SeatCapabilityPointer = 1
359- SeatCapabilityKeyboard = 2
360- SeatCapabilityTouch = 4
361-)
362-
363-// Seat represents a wl_seat
364-type Seat struct {
365- BaseProxy
366- capabilities uint32
367- name string
368-}
369-
370-// SeatCapabilitiesHandler handles seat capabilities events
371-type SeatCapabilitiesHandler interface {
372- HandleSeatCapabilities(seat *Seat, capabilities uint32)
373-}
374-
375-// SeatNameHandler handles seat name events
376-type SeatNameHandler interface {
377- HandleSeatName(seat *Seat, name string)
378-}
379-
380-// NewSeat creates a new seat proxy
381-func NewSeat(ctx *Context) *Seat {
382- return &Seat{
383- BaseProxy: BaseProxy{
384- context: ctx,
385- },
386- }
387-}
388-
389-// GetPointer gets the pointer device
390-func (s *Seat) GetPointer() (*Pointer, error) {
391- pointer := &Pointer{
392- BaseProxy: BaseProxy{
393- context: s.context,
394- id: s.context.display.allocateID(),
395- },
396- }
397-
398- // Register pointer before sending request
399- s.context.Register(pointer)
400-
401- // Send get_pointer request (opcode 0)
402- err := s.context.SendRequest(s, 0, pointer.id)
403- if err != nil {
404- s.context.Unregister(pointer)
405- return nil, err
406- }
407-
408- return pointer, nil
409-}
410-
411-// GetKeyboard gets the keyboard device
412-func (s *Seat) GetKeyboard() (*Keyboard, error) {
413- keyboard := &Keyboard{
414- BaseProxy: BaseProxy{
415- context: s.context,
416- id: s.context.display.allocateID(),
417- },
418- }
419-
420- // Register keyboard before sending request
421- s.context.Register(keyboard)
422-
423- // Send get_keyboard request (opcode 1)
424- err := s.context.SendRequest(s, 1, keyboard.id)
425- if err != nil {
426- s.context.Unregister(keyboard)
427- return nil, err
428- }
429-
430- return keyboard, nil
431-}
432-
433-// GetTouch gets the touch device
434-func (s *Seat) GetTouch() (*Touch, error) {
435- touch := &Touch{
436- BaseProxy: BaseProxy{
437- context: s.context,
438- id: s.context.display.allocateID(),
439- },
440- }
441-
442- // Register touch before sending request
443- s.context.Register(touch)
444-
445- // Send get_touch request (opcode 2)
446- err := s.context.SendRequest(s, 2, touch.id)
447- if err != nil {
448- s.context.Unregister(touch)
449- return nil, err
450- }
451-
452- return touch, nil
453-}
454-
455-// Release releases the seat
456-func (s *Seat) Release() error {
457- err := s.context.SendRequest(s, 3) // opcode 3
458- if err == nil {
459- s.context.Unregister(s)
460- }
461- return err
462-}
463-
464-// Capabilities returns the seat capabilities
465-func (s *Seat) Capabilities() uint32 {
466- return s.capabilities
467-}
468-
469-// Name returns the seat name
470-func (s *Seat) Name() string {
471- return s.name
472-}
473-
474-// Dispatch handles events for the seat
475-func (s *Seat) Dispatch(event *Event) {
476- // Handle seat events
477- switch event.Opcode {
478- case 0: // capabilities
479- s.capabilities = event.Uint32()
480- // TODO: Call registered handlers
481- case 1: // name
482- s.name = event.String()
483- // TODO: Call registered handlers
484- }
485-}
486-
487-// Surface represents a wl_surface
488-type Surface struct {
489- BaseProxy
490-}
491-
492-// NewSurface creates a new surface proxy
493-func NewSurface(ctx *Context) *Surface {
494- return &Surface{
495- BaseProxy: BaseProxy{
496- context: ctx,
497- },
498- }
499-}
500-
501-// Destroy destroys the surface
502-func (s *Surface) Destroy() error {
503- err := s.context.SendRequest(s, 0) // opcode 0
504- if err == nil {
505- s.context.Unregister(s)
506- }
507- return err
508-}
509-
510-// Attach attaches a buffer to the surface
511-func (s *Surface) Attach(buffer Object, x, y int32) error {
512- return s.context.SendRequest(s, 1, buffer, x, y) // opcode 1
513-}
514-
515-// Damage marks a region of the surface as damaged
516-func (s *Surface) Damage(x, y, width, height int32) error {
517- return s.context.SendRequest(s, 2, x, y, width, height) // opcode 2
518-}
519-
520-// Frame requests a frame callback
521-func (s *Surface) Frame() (Object, error) {
522- callback := &callbackObject{
523- BaseProxy: BaseProxy{
524- context: s.context,
525- id: s.context.display.allocateID(),
526- },
527- display: s.context.display,
528- }
529- s.context.Register(callback)
530-
531- err := s.context.SendRequest(s, 3, callback.id) // opcode 3
532- if err != nil {
533- s.context.Unregister(callback)
534- return nil, err
535- }
536-
537- return callback, nil
538-}
539-
540-// SetOpaqueRegion sets the opaque region
541-func (s *Surface) SetOpaqueRegion(region *Region) error {
542- return s.context.SendRequest(s, 4, region) // opcode 4
543-}
544-
545-// SetInputRegion sets the input region
546-func (s *Surface) SetInputRegion(region *Region) error {
547- return s.context.SendRequest(s, 5, region) // opcode 5
548-}
549-
550-// Commit commits pending surface state
551-func (s *Surface) Commit() error {
552- return s.context.SendRequest(s, 6) // opcode 6
553-}
554-
555-// SetBufferTransform sets the buffer transform
556-func (s *Surface) SetBufferTransform(transform int32) error {
557- return s.context.SendRequest(s, 7, transform) // opcode 7
558-}
559-
560-// SetBufferScale sets the buffer scale
561-func (s *Surface) SetBufferScale(scale int32) error {
562- return s.context.SendRequest(s, 8, scale) // opcode 8
563-}
564-
565-// DamageBuffer marks a region of the buffer as damaged
566-func (s *Surface) DamageBuffer(x, y, width, height int32) error {
567- return s.context.SendRequest(s, 9, x, y, width, height) // opcode 9
568-}
569-
570-// Offset sets the buffer offset
571-func (s *Surface) Offset(x, y int32) error {
572- return s.context.SendRequest(s, 10, x, y) // opcode 10
573-}
574-
575-// Dispatch handles surface events
576-func (s *Surface) Dispatch(event *Event) {
577- // Surface can receive enter/leave/preferred_buffer_scale/preferred_buffer_transform events
578- // But for now we don't handle them
579-}
580-
581-// Pointer represents a wl_pointer
582-type Pointer struct {
583- BaseProxy
584-}
585-
586-// Keyboard represents a wl_keyboard
587-type Keyboard struct {
588- BaseProxy
589-}
590-
591-// Touch represents a wl_touch
592-type Touch struct {
593- BaseProxy
594-}
595-
596-// Output represents a wl_output
597-type Output struct {
598- BaseProxy
599-}
600-
601-// Region represents a wl_region
602-type Region struct {
603- BaseProxy
604-}
605-
606-// Add adds a rectangle to the region
607-func (r *Region) Add(x, y, width, height int32) error {
608- return r.context.SendRequest(r, 0, x, y, width, height) // opcode 0
609-}
610-
611-// Subtract subtracts a rectangle from the region
612-func (r *Region) Subtract(x, y, width, height int32) error {
613- return r.context.SendRequest(r, 1, x, y, width, height) // opcode 1
614-}
615-
616-// Destroy destroys the region
617-func (r *Region) Destroy() error {
618- err := r.context.SendRequest(r, 2) // opcode 2
619- if err == nil {
620- r.context.Unregister(r)
621- }
622- return err
623-}
624-
625-// Compositor represents a wl_compositor
626-type Compositor struct {
627- BaseProxy
628-}
629-
630-// NewCompositor creates a new compositor proxy
631-func NewCompositor(ctx *Context) *Compositor {
632- return &Compositor{
633- BaseProxy: BaseProxy{
634- context: ctx,
635- },
636- }
637-}
638-
639-// CreateSurface creates a new surface
640-func (c *Compositor) CreateSurface() (*Surface, error) {
641- surface := &Surface{
642- BaseProxy: BaseProxy{
643- context: c.context,
644- id: c.context.display.allocateID(),
645- },
646- }
647-
648- // Register surface before sending request
649- c.context.Register(surface)
650-
651- // Send create_surface request (opcode 0)
652- err := c.context.SendRequest(c, 0, surface.id)
653- if err != nil {
654- c.context.Unregister(surface)
655- return nil, err
656- }
657-
658- return surface, nil
659-}
660-
661-// CreateRegion creates a new region
662-func (c *Compositor) CreateRegion() (*Region, error) {
663- region := &Region{
664- BaseProxy: BaseProxy{
665- context: c.context,
666- id: c.context.display.allocateID(),
667- },
668- }
669-
670- // Register region before sending request
671- c.context.Register(region)
672-
673- // Send create_region request (opcode 1)
674- err := c.context.SendRequest(c, 1, region.id)
675- if err != nil {
676- c.context.Unregister(region)
677- return nil, err
678- }
679-
680- return region, nil
681-}
A docs/protocol-migration.md +29 -0
@@ -0,0 +1,29 @@
1+# Canonical core / migration (v0.x)
2+
3+`protocol/core` replaces root-package and `wl` shim core object types. Bootstrap
4+`Display`, `Registry`, `Context`, and `BaseProxy` remain in the root/`wl`
5+transport. Bind globals using `core.NewCompositor(display.Context())`,
6+`core.NewSeat(display.Context())`, etc. and `display.Registry().Bind(name,
7+core.CompositorInterface, version, compositor)`. Requests create typed registered
8+children (`seat.GetKeyboard()`, `surface.Frame()`, `shm.CreatePool()`) and
9+server-side `new_id` events register concrete objects before invoking handlers.
10+Do not overwrite registered objects with a second wrapper.
11+
12+Breaking changes: `wlturbo`/`wl` `Seat`, `Surface`, `Pointer`, `Keyboard`,
13+`Touch`, `Output`, `Region`, `Compositor`, their constructors, and seat
14+capability aliases have moved to `protocol/core`. Generated methods accept
15+concrete core objects and return concrete children, not `wl.Object`. Legacy
16+raw `Event.Fd()` is not for generated events; generated FD handlers receive
17+`*wlturbo.OwnedFD` with `Take() (int,error)` or `Close()`; second and later
18+handlers receive nil FD. On a successful full send a generated FD request
19+closes the local descriptor; on error the caller keeps it. `Registry.BindID`
20+remains for legacy callers but cannot register typed event dispatch: prefer
21+`Bind` and generated constructors. Unrecognized custom-proxy event opcodes
22+now fail unless declared via `Display.RegisterEventSignature`.
23+
24+The scanner accepts `-import wl_surface=github.com/bnema/wlturbo/protocol/core`
25+(repeat for each external type); local XML definitions take precedence, then
26+explicit external mapping, then only bootstrap display/registry. Generate with
27+`GOWORK=off go generate ./...`; metadata and XML license are in
28+`protocol/SOURCE.md`. P3 extensions will use the same scanner and public core
29+mappings; no generator-owned compositor policy is introduced here.
M fd_test.go +23 -48
@@ -90,6 +90,8 @@ func newFDDisplay(t *testing.T, client *net.UnixConn) (*Display, *[]int) {
9090
9191 d := newDisplay(client)
9292 fds := []int{}
93+ d.RegisterEventSignature(7, 3, "uint,fd,")
94+ d.RegisterEventSignature(7, 4, "uint,")
9395 d.objects.Store(uint32(7), &fdRecordingProxy{
9496 BaseProxy: BaseProxy{id: 7, context: d.context},
9597 fds: &fds,
@@ -146,49 +148,19 @@ func TestDisplayFD_Single(t *testing.T) {
146148 readSentinel(t, r, "single-fd-sentinel")
147149 }
148150
149-func TestDisplayFD_MultipleInOneControlMessage(t *testing.T) {
151+func TestDisplayFD_ExtraDescriptorRejected(t *testing.T) {
150152 client, peer := unixSocketPair(t)
151- d, received := newFDDisplay(t, client)
152-
153- firstR, firstW, err := os.Pipe()
154- if err != nil {
155- t.Fatalf("pipe: %v", err)
156- }
157- defer firstR.Close()
158- secondR, secondW, err := os.Pipe()
153+ d, _ := newFDDisplay(t, client)
154+ r, w, err := os.Pipe()
159155 if err != nil {
160- t.Fatalf("pipe: %v", err)
156+ t.Fatal(err)
161157 }
162- defer secondR.Close()
163-
164- sendMessageWithFDs(t, peer, message(7, 3, []byte{0, 0, 0, 0}),
165- []int{int(firstW.Fd()), int(secondW.Fd())})
166- firstW.Close()
167- secondW.Close()
168-
169- if err := d.Dispatch(); err != nil {
170- t.Fatalf("Dispatch: %v", err)
171- }
172-
173- // A handler consumes one descriptor per fd argument, so the test drains
174- // whatever the connection still holds, in arrival order.
175- for {
176- fd, ok := d.nextFD()
177- if !ok {
178- break
179- }
180- *received = append(*received, fd)
181- }
182-
183- if len(*received) != 2 {
184- t.Fatalf("received %d descriptors, want 2", len(*received))
158+ defer r.Close()
159+ defer w.Close()
160+ sendMessageWithFDs(t, peer, message(7, 3, nil), []int{int(w.Fd()), int(w.Fd())})
161+ if err := d.Dispatch(); !errors.Is(err, ErrMalformedFrame) {
162+ t.Fatalf("extra FD: %v", err)
185163 }
186-
187- writeSentinel(t, uintptr((*received)[0]), "first-pipe")
188- writeSentinel(t, uintptr((*received)[1]), "second-pipe")
189-
190- readSentinel(t, firstR, "first-pipe")
191- readSentinel(t, secondR, "second-pipe")
192164 }
193165
194166 func TestDisplayFD_EventWithoutFDsAfterOneWithFDs(t *testing.T) {
@@ -304,9 +276,9 @@ func TestDisplayFD_TruncatedControlData(t *testing.T) {
304276 }
305277
306278 // A truncated control message must not leave descriptors queued.
307- d.fdMu.Lock()
279+ d.recvMu.Lock()
308280 pending := len(d.pendingFDs)
309- d.fdMu.Unlock()
281+ d.recvMu.Unlock()
310282 if pending != 0 {
311283 t.Fatalf("%d descriptors still queued after a truncated control message", pending)
312284 }
@@ -315,6 +287,7 @@ func TestDisplayFD_TruncatedControlData(t *testing.T) {
315287 func TestDisplayFD_UnconsumedDescriptorClosedOnShutdown(t *testing.T) {
316288 client, peer := unixSocketPair(t)
317289 d := newDisplay(client)
290+ d.RegisterEventSignature(7, 3, "uint,fd,")
318291 d.objects.Store(uint32(7), &fdIgnoringProxy{
319292 BaseProxy: BaseProxy{id: 7, context: d.context},
320293 })
@@ -333,12 +306,12 @@ func TestDisplayFD_UnconsumedDescriptorClosedOnShutdown(t *testing.T) {
333306 t.Fatalf("Dispatch: %v", err)
334307 }
335308
336- // While the display still holds the descriptor the pipe stays open.
337- if err := r.SetReadDeadline(time.Now().Add(200 * time.Millisecond)); err != nil {
338- t.Fatalf("SetReadDeadline: %v", err)
309+ // An ignored FD is closed at the end of the event, not at shutdown.
310+ if err := r.SetReadDeadline(time.Now().Add(2 * time.Second)); err != nil {
311+ t.Fatal(err)
339312 }
340- if _, err := r.Read(make([]byte, 1)); !errors.Is(err, os.ErrDeadlineExceeded) {
341- t.Fatalf("read with the display holding the descriptor = %v, want %v", err, os.ErrDeadlineExceeded)
313+ if _, err := r.Read(make([]byte, 1)); !errors.Is(err, io.EOF) {
314+ t.Fatalf("ignored FD: %v", err)
342315 }
343316
344317 // Closing the display must release it, so the read end sees EOF.
@@ -421,6 +394,7 @@ func runFDLeakIteration(t *testing.T, devNull *os.File) {
421394
422395 client, peer := rawSocketPair(t)
423396 d := newDisplay(client)
397+ d.RegisterEventSignature(7, 3, "uint,fd,")
424398 d.objects.Store(uint32(7), &fdIgnoringProxy{
425399 BaseProxy: BaseProxy{id: 7, context: d.context},
426400 })
@@ -448,6 +422,7 @@ func runFDLeakIteration(t *testing.T, devNull *os.File) {
448422 func TestDisplayFD_ParseFailureClosesQueuedDescriptor(t *testing.T) {
449423 client, peer := unixSocketPair(t)
450424 d := newDisplay(client)
425+ d.RegisterEventSignature(7, 3, "uint,fd,")
451426 d.objects.Store(uint32(7), &fdIgnoringProxy{
452427 BaseProxy: BaseProxy{id: 7, context: d.context},
453428 })
@@ -467,9 +442,9 @@ func TestDisplayFD_ParseFailureClosesQueuedDescriptor(t *testing.T) {
467442 t.Fatalf("Dispatch error = %v, want %v", err, ErrMalformedFrame)
468443 }
469444
470- d.fdMu.Lock()
445+ d.recvMu.Lock()
471446 pending := len(d.pendingFDs)
472- d.fdMu.Unlock()
447+ d.recvMu.Unlock()
473448 if pending != 0 {
474449 t.Fatalf("%d descriptors still queued after a malformed frame", pending)
475450 }
A fd_zero_test.go +14 -0
@@ -0,0 +1,14 @@
1+package wlturbo
2+
3+import "testing"
4+
5+func TestOwnedFDZero(t *testing.T) {
6+ fd := &OwnedFD{fd: 0}
7+ n, e := fd.Take()
8+ if e != nil || n != 0 {
9+ t.Fatalf("Take fd zero = %d %v", n, e)
10+ }
11+ if e := fd.Close(); e != nil {
12+ t.Fatal(e)
13+ }
14+}
A protocol/core/core_test.go +324 -0
@@ -0,0 +1,324 @@
1+//go:build linux
2+
3+package core_test
4+
5+import (
6+ "encoding/binary"
7+ "errors"
8+ "io"
9+ "net"
10+ "os"
11+ "testing"
12+ "time"
13+
14+ "github.com/bnema/wlturbo"
15+ "github.com/bnema/wlturbo/protocol/core"
16+ "golang.org/x/sys/unix"
17+)
18+
19+func pair(t *testing.T) (*net.UnixConn, *net.UnixConn) {
20+ t.Helper()
21+ f, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM|unix.SOCK_CLOEXEC, 0)
22+ if err != nil {
23+ t.Fatal(err)
24+ }
25+ a := os.NewFile(uintptr(f[0]), "a")
26+ b := os.NewFile(uintptr(f[1]), "b")
27+ ca, e := net.FileConn(a)
28+ a.Close()
29+ if e != nil {
30+ t.Fatal(e)
31+ }
32+ cb, e := net.FileConn(b)
33+ b.Close()
34+ if e != nil {
35+ t.Fatal(e)
36+ }
37+ t.Cleanup(func() { ca.Close(); cb.Close() })
38+ return ca.(*net.UnixConn), cb.(*net.UnixConn)
39+}
40+func frame(id uint32, op uint16, body ...uint32) []byte {
41+ p := make([]byte, 8+4*len(body))
42+ binary.LittleEndian.PutUint32(p, id)
43+ binary.LittleEndian.PutUint32(p[4:], uint32(len(p))<<16|uint32(op))
44+ for i, v := range body {
45+ binary.LittleEndian.PutUint32(p[8+i*4:], v)
46+ }
47+ return p
48+}
49+func receiveRequest(t *testing.T, p *net.UnixConn) {
50+ t.Helper()
51+ p.SetReadDeadline(testDeadline())
52+ b := make([]byte, 256)
53+ if _, e := p.Read(b); e != nil {
54+ t.Fatal(e)
55+ }
56+}
57+func testDeadline() (d time.Time) { return time.Now().Add(2 * time.Second) }
58+func send(t *testing.T, p *net.UnixConn, msg []byte, fd ...int) {
59+ t.Helper()
60+ var oob []byte
61+ if len(fd) > 0 {
62+ oob = unix.UnixRights(fd...)
63+ }
64+ if _, _, e := p.WriteMsgUnix(msg, oob, nil); e != nil {
65+ t.Fatal(e)
66+ }
67+}
68+func TestGeneratedCoreOverSocketpair(t *testing.T) {
69+ c, p := pair(t)
70+ d, err := wlturbo.ConnectFromConn(c)
71+ if err != nil {
72+ t.Fatal(err)
73+ }
74+ defer d.Close()
75+ receiveRequest(t, p) // get_registry
76+ seat := core.NewSeat(d.Context())
77+ if err := d.Registry().Bind(1, core.SeatInterface, 1, seat); err != nil {
78+ t.Fatal(err)
79+ }
80+ receiveRequest(t, p)
81+ kb, err := seat.GetKeyboard()
82+ if err != nil {
83+ t.Fatal(err)
84+ }
85+ receiveRequest(t, p)
86+ var key uint32
87+ kb.OnKey(func(_, _, k, _ uint32) { key = k })
88+ send(t, p, frame(kb.ID(), 3, 1, 2, 42, 1))
89+ if err := d.Dispatch(); err != nil {
90+ t.Fatal(err)
91+ }
92+ if key != 42 {
93+ t.Fatalf("key=%d", key)
94+ }
95+ compositor := core.NewCompositor(d.Context())
96+ if err := d.Registry().Bind(2, core.CompositorInterface, 1, compositor); err != nil {
97+ t.Fatal(err)
98+ }
99+ receiveRequest(t, p)
100+ surface, err := compositor.CreateSurface()
101+ if err != nil {
102+ t.Fatal(err)
103+ }
104+ receiveRequest(t, p)
105+ callback, err := surface.Frame()
106+ if err != nil {
107+ t.Fatal(err)
108+ }
109+ receiveRequest(t, p)
110+ var done uint32
111+ callback.OnDone(func(ms uint32) { done = ms })
112+ send(t, p, frame(callback.ID(), 0, 123))
113+ if err := d.Dispatch(); err != nil {
114+ t.Fatal(err)
115+ }
116+ if done != 123 {
117+ t.Fatalf("done=%d", done)
118+ }
119+ send(t, p, frame(callback.ID(), 0, 124))
120+ if err := d.Dispatch(); !errors.Is(err, wlturbo.ErrUnknownObject) {
121+ t.Fatalf("destroyed callback: %v", err)
122+ }
123+}
124+func TestKeymapFDNoHandlerAndMultipleHandlers(t *testing.T) {
125+ c, p := pair(t)
126+ d, e := wlturbo.ConnectFromConn(c)
127+ if e != nil {
128+ t.Fatal(e)
129+ }
130+ defer d.Close()
131+ receiveRequest(t, p)
132+ kb := core.NewKeyboard(d.Context())
133+ kb.SetID(d.AllocateID())
134+ d.Context().Register(kb)
135+ r, w, e := os.Pipe()
136+ if e != nil {
137+ t.Fatal(e)
138+ }
139+ defer r.Close()
140+ send(t, p, frame(kb.ID(), 0, 1, 8), int(w.Fd()))
141+ w.Close()
142+ if e := d.Dispatch(); e != nil {
143+ t.Fatal(e)
144+ }
145+ buf := make([]byte, 1)
146+ if n, e := r.Read(buf); n != 0 || e != io.EOF {
147+ t.Fatalf("unclaimed FD n=%d err=%v", n, e)
148+ }
149+ r2, w2, e := os.Pipe()
150+ if e != nil {
151+ t.Fatal(e)
152+ }
153+ defer r2.Close()
154+ received := 0
155+ kb.OnKeymap(func(_ uint32, fd *wlturbo.OwnedFD, _ uint32) {
156+ if fd == nil {
157+ t.Fatal("first FD missing")
158+ }
159+ n, e := fd.Take()
160+ if e != nil {
161+ t.Fatal(e)
162+ }
163+ received++
164+ unix.Close(n)
165+ })
166+ kb.OnKeymap(func(_ uint32, fd *wlturbo.OwnedFD, _ uint32) {
167+ if fd != nil {
168+ t.Fatal("duplicated owner")
169+ }
170+ received++
171+ })
172+ send(t, p, frame(kb.ID(), 0, 1, 8), int(w2.Fd()))
173+ w2.Close()
174+ if e := d.Dispatch(); e != nil {
175+ t.Fatal(e)
176+ }
177+ if received != 2 {
178+ t.Fatalf("handlers=%d", received)
179+ }
180+}
181+func TestBufferReleaseAndOfferChild(t *testing.T) {
182+ c, p := pair(t)
183+ d, e := wlturbo.ConnectFromConn(c)
184+ if e != nil {
185+ t.Fatal(e)
186+ }
187+ defer d.Close()
188+ receiveRequest(t, p)
189+ b := core.NewBuffer(d.Context())
190+ b.SetID(d.AllocateID())
191+ d.Context().Register(b)
192+ releases := 0
193+ b.OnRelease(func() { releases++ })
194+ send(t, p, frame(b.ID(), 0))
195+ if e := d.Dispatch(); e != nil {
196+ t.Fatal(e)
197+ }
198+ if releases != 1 {
199+ t.Fatal("release not dispatched")
200+ }
201+ device := core.NewDataDevice(d.Context())
202+ device.SetID(d.AllocateID())
203+ d.Context().Register(device)
204+ var offer *core.DataOffer
205+ device.OnDataOffer(func(o *core.DataOffer) { offer = o })
206+ send(t, p, frame(device.ID(), 0, 0xff000001))
207+ if e := d.Dispatch(); e != nil {
208+ t.Fatal(e)
209+ }
210+ if offer == nil || offer.ID() != 0xff000001 {
211+ t.Fatalf("offer=%v", offer)
212+ }
213+}
214+
215+func TestMissingKeymapDescriptor(t *testing.T) {
216+ c, p := pair(t)
217+ d, e := wlturbo.ConnectFromConn(c)
218+ if e != nil {
219+ t.Fatal(e)
220+ }
221+ defer d.Close()
222+ receiveRequest(t, p)
223+ kb := core.NewKeyboard(d.Context())
224+ kb.SetID(d.AllocateID())
225+ d.Context().Register(kb)
226+ send(t, p, frame(kb.ID(), 0, 1, 8))
227+ if e := d.Dispatch(); !errors.Is(e, wlturbo.ErrMalformedFrame) {
228+ t.Fatalf("missing FD: %v", e)
229+ }
230+}
231+
232+func TestInterleavedFDAndPlainMessages(t *testing.T) {
233+ c, p := pair(t)
234+ d, e := wlturbo.ConnectFromConn(c)
235+ if e != nil {
236+ t.Fatal(e)
237+ }
238+ defer d.Close()
239+ receiveRequest(t, p)
240+ kb := core.NewKeyboard(d.Context())
241+ kb.SetID(d.AllocateID())
242+ d.Context().Register(kb)
243+ calls := 0
244+ kb.OnKeymap(func(_ uint32, fd *wlturbo.OwnedFD, _ uint32) {
245+ if fd == nil {
246+ t.Fatal("FD not assigned")
247+ }
248+ _ = fd.Close()
249+ calls++
250+ })
251+ kb.OnKey(func(_, _, key, _ uint32) {
252+ if key != 33 {
253+ t.Errorf("key=%d", key)
254+ }
255+ calls++
256+ })
257+ r, w, e := os.Pipe()
258+ if e != nil {
259+ t.Fatal(e)
260+ }
261+ defer r.Close()
262+ send(t, p, frame(kb.ID(), 0, 1, 8), int(w.Fd()))
263+ w.Close()
264+ send(t, p, frame(kb.ID(), 3, 1, 2, 33, 1))
265+ if e := d.Dispatch(); e != nil {
266+ t.Fatal(e)
267+ }
268+ if e := d.Dispatch(); e != nil {
269+ t.Fatal(e)
270+ }
271+ if calls != 2 {
272+ t.Fatalf("calls=%d", calls)
273+ }
274+}
275+func TestMalformedGeneratedPayload(t *testing.T) {
276+ c, p := pair(t)
277+ d, e := wlturbo.ConnectFromConn(c)
278+ if e != nil {
279+ t.Fatal(e)
280+ }
281+ defer d.Close()
282+ receiveRequest(t, p)
283+ kb := core.NewKeyboard(d.Context())
284+ kb.SetID(d.AllocateID())
285+ d.Context().Register(kb)
286+ send(t, p, frame(kb.ID(), 3, 1, 2))
287+ if e := d.Dispatch(); !errors.Is(e, wlturbo.ErrMalformedFrame) {
288+ t.Fatalf("truncated key: %v", e)
289+ }
290+}
291+
292+func TestServerChildEventsAfterOffer(t *testing.T) {
293+ c, p := pair(t)
294+ d, e := wlturbo.ConnectFromConn(c)
295+ if e != nil {
296+ t.Fatal(e)
297+ }
298+ defer d.Close()
299+ receiveRequest(t, p)
300+ device := core.NewDataDevice(d.Context())
301+ device.SetID(d.AllocateID())
302+ d.Context().Register(device)
303+ const offerID = 0xff000011
304+ var offer *core.DataOffer
305+ device.OnDataOffer(func(o *core.DataOffer) { offer = o })
306+ send(t, p, frame(device.ID(), 0, offerID))
307+ if e := d.Dispatch(); e != nil {
308+ t.Fatal(e)
309+ }
310+ if offer == nil {
311+ t.Fatal("missing concrete child")
312+ }
313+ got := ""
314+ offer.OnOffer(func(mime string) { got = mime })
315+ payload := append(frame(offerID, 0), 4, 0, 0, 0, 'a', 'b', 'c', 0)
316+ binary.LittleEndian.PutUint32(payload[4:], uint32(len(payload))<<16)
317+ send(t, p, payload)
318+ if e := d.Dispatch(); e != nil {
319+ t.Fatal(e)
320+ }
321+ if got != "abc" {
322+ t.Fatalf("typed child event: %q", got)
323+ }
324+}
A protocol/core/doc.go +8 -0
@@ -0,0 +1,8 @@
1+// Package core contains canonical Wayland core protocol bindings generated from
2+// pinned wayland.xml. Bind globals with display.Registry().Bind and the
3+// corresponding New* constructor. Client-created and server-created children
4+// are registered with their concrete generated types; never replace them with
5+// transport wrappers. On* handlers receive typed values. Received OwnedFDs
6+// are closed after the event unless a handler calls Take; request FDs are
7+// transferred (and closed locally) only after a complete successful send.
8+package core
A protocol/core/wayland_generated.go +4023 -0
@@ -0,0 +1,4023 @@
1+// Code generated by wlturbo-scanner. DO NOT EDIT.
2+// Protocol: wayland
3+// Source: wayland.xml
4+
5+package core
6+
7+import (
8+ "sync"
9+
10+ "github.com/bnema/wlturbo/wl"
11+)
12+
13+// WL_SHM_POOL_ERROR_INVALID_FORMAT is the error invalid_format value.
14+const WL_SHM_POOL_ERROR_INVALID_FORMAT = 0
15+
16+// WL_SHM_POOL_ERROR_INVALID_STRIDE is the error invalid_stride value.
17+const WL_SHM_POOL_ERROR_INVALID_STRIDE = 1
18+
19+// WL_SHM_ERROR_INVALID_FORMAT is the error invalid_format value.
20+const WL_SHM_ERROR_INVALID_FORMAT = 0
21+
22+// WL_SHM_ERROR_INVALID_STRIDE is the error invalid_stride value.
23+const WL_SHM_ERROR_INVALID_STRIDE = 1
24+
25+// ERROR_INVALID_FD is the error invalid_fd value.
26+const ERROR_INVALID_FD = 2
27+
28+// FORMAT_ARGB8888 is the format argb8888 value.
29+const FORMAT_ARGB8888 = 0
30+
31+// FORMAT_XRGB8888 is the format xrgb8888 value.
32+const FORMAT_XRGB8888 = 1
33+
34+// FORMAT_C8 is the format c8 value.
35+const FORMAT_C8 = 0x20203843
36+
37+// FORMAT_RGB332 is the format rgb332 value.
38+const FORMAT_RGB332 = 0x38424752
39+
40+// FORMAT_BGR233 is the format bgr233 value.
41+const FORMAT_BGR233 = 0x38524742
42+
43+// FORMAT_XRGB4444 is the format xrgb4444 value.
44+const FORMAT_XRGB4444 = 0x32315258
45+
46+// FORMAT_XBGR4444 is the format xbgr4444 value.
47+const FORMAT_XBGR4444 = 0x32314258
48+
49+// FORMAT_RGBX4444 is the format rgbx4444 value.
50+const FORMAT_RGBX4444 = 0x32315852
51+
52+// FORMAT_BGRX4444 is the format bgrx4444 value.
53+const FORMAT_BGRX4444 = 0x32315842
54+
55+// FORMAT_ARGB4444 is the format argb4444 value.
56+const FORMAT_ARGB4444 = 0x32315241
57+
58+// FORMAT_ABGR4444 is the format abgr4444 value.
59+const FORMAT_ABGR4444 = 0x32314241
60+
61+// FORMAT_RGBA4444 is the format rgba4444 value.
62+const FORMAT_RGBA4444 = 0x32314152
63+
64+// FORMAT_BGRA4444 is the format bgra4444 value.
65+const FORMAT_BGRA4444 = 0x32314142
66+
67+// FORMAT_XRGB1555 is the format xrgb1555 value.
68+const FORMAT_XRGB1555 = 0x35315258
69+
70+// FORMAT_XBGR1555 is the format xbgr1555 value.
71+const FORMAT_XBGR1555 = 0x35314258
72+
73+// FORMAT_RGBX5551 is the format rgbx5551 value.
74+const FORMAT_RGBX5551 = 0x35315852
75+
76+// FORMAT_BGRX5551 is the format bgrx5551 value.
77+const FORMAT_BGRX5551 = 0x35315842
78+
79+// FORMAT_ARGB1555 is the format argb1555 value.
80+const FORMAT_ARGB1555 = 0x35315241
81+
82+// FORMAT_ABGR1555 is the format abgr1555 value.
83+const FORMAT_ABGR1555 = 0x35314241
84+
85+// FORMAT_RGBA5551 is the format rgba5551 value.
86+const FORMAT_RGBA5551 = 0x35314152
87+
88+// FORMAT_BGRA5551 is the format bgra5551 value.
89+const FORMAT_BGRA5551 = 0x35314142
90+
91+// FORMAT_RGB565 is the format rgb565 value.
92+const FORMAT_RGB565 = 0x36314752
93+
94+// FORMAT_BGR565 is the format bgr565 value.
95+const FORMAT_BGR565 = 0x36314742
96+
97+// FORMAT_RGB888 is the format rgb888 value.
98+const FORMAT_RGB888 = 0x34324752
99+
100+// FORMAT_BGR888 is the format bgr888 value.
101+const FORMAT_BGR888 = 0x34324742
102+
103+// FORMAT_XBGR8888 is the format xbgr8888 value.
104+const FORMAT_XBGR8888 = 0x34324258
105+
106+// FORMAT_RGBX8888 is the format rgbx8888 value.
107+const FORMAT_RGBX8888 = 0x34325852
108+
109+// FORMAT_BGRX8888 is the format bgrx8888 value.
110+const FORMAT_BGRX8888 = 0x34325842
111+
112+// FORMAT_ABGR8888 is the format abgr8888 value.
113+const FORMAT_ABGR8888 = 0x34324241
114+
115+// FORMAT_RGBA8888 is the format rgba8888 value.
116+const FORMAT_RGBA8888 = 0x34324152
117+
118+// FORMAT_BGRA8888 is the format bgra8888 value.
119+const FORMAT_BGRA8888 = 0x34324142
120+
121+// FORMAT_XRGB2101010 is the format xrgb2101010 value.
122+const FORMAT_XRGB2101010 = 0x30335258
123+
124+// FORMAT_XBGR2101010 is the format xbgr2101010 value.
125+const FORMAT_XBGR2101010 = 0x30334258
126+
127+// FORMAT_RGBX1010102 is the format rgbx1010102 value.
128+const FORMAT_RGBX1010102 = 0x30335852
129+
130+// FORMAT_BGRX1010102 is the format bgrx1010102 value.
131+const FORMAT_BGRX1010102 = 0x30335842
132+
133+// FORMAT_ARGB2101010 is the format argb2101010 value.
134+const FORMAT_ARGB2101010 = 0x30335241
135+
136+// FORMAT_ABGR2101010 is the format abgr2101010 value.
137+const FORMAT_ABGR2101010 = 0x30334241
138+
139+// FORMAT_RGBA1010102 is the format rgba1010102 value.
140+const FORMAT_RGBA1010102 = 0x30334152
141+
142+// FORMAT_BGRA1010102 is the format bgra1010102 value.
143+const FORMAT_BGRA1010102 = 0x30334142
144+
145+// FORMAT_YUYV is the format yuyv value.
146+const FORMAT_YUYV = 0x56595559
147+
148+// FORMAT_YVYU is the format yvyu value.
149+const FORMAT_YVYU = 0x55595659
150+
151+// FORMAT_UYVY is the format uyvy value.
152+const FORMAT_UYVY = 0x59565955
153+
154+// FORMAT_VYUY is the format vyuy value.
155+const FORMAT_VYUY = 0x59555956
156+
157+// FORMAT_AYUV is the format ayuv value.
158+const FORMAT_AYUV = 0x56555941
159+
160+// FORMAT_NV12 is the format nv12 value.
161+const FORMAT_NV12 = 0x3231564e
162+
163+// FORMAT_NV21 is the format nv21 value.
164+const FORMAT_NV21 = 0x3132564e
165+
166+// FORMAT_NV16 is the format nv16 value.
167+const FORMAT_NV16 = 0x3631564e
168+
169+// FORMAT_NV61 is the format nv61 value.
170+const FORMAT_NV61 = 0x3136564e
171+
172+// FORMAT_YUV410 is the format yuv410 value.
173+const FORMAT_YUV410 = 0x39565559
174+
175+// FORMAT_YVU410 is the format yvu410 value.
176+const FORMAT_YVU410 = 0x39555659
177+
178+// FORMAT_YUV411 is the format yuv411 value.
179+const FORMAT_YUV411 = 0x31315559
180+
181+// FORMAT_YVU411 is the format yvu411 value.
182+const FORMAT_YVU411 = 0x31315659
183+
184+// FORMAT_YUV420 is the format yuv420 value.
185+const FORMAT_YUV420 = 0x32315559
186+
187+// FORMAT_YVU420 is the format yvu420 value.
188+const FORMAT_YVU420 = 0x32315659
189+
190+// FORMAT_YUV422 is the format yuv422 value.
191+const FORMAT_YUV422 = 0x36315559
192+
193+// FORMAT_YVU422 is the format yvu422 value.
194+const FORMAT_YVU422 = 0x36315659
195+
196+// FORMAT_YUV444 is the format yuv444 value.
197+const FORMAT_YUV444 = 0x34325559
198+
199+// FORMAT_YVU444 is the format yvu444 value.
200+const FORMAT_YVU444 = 0x34325659
201+
202+// FORMAT_R8 is the format r8 value.
203+const FORMAT_R8 = 0x20203852
204+
205+// FORMAT_R16 is the format r16 value.
206+const FORMAT_R16 = 0x20363152
207+
208+// FORMAT_RG88 is the format rg88 value.
209+const FORMAT_RG88 = 0x38384752
210+
211+// FORMAT_GR88 is the format gr88 value.
212+const FORMAT_GR88 = 0x38385247
213+
214+// FORMAT_RG1616 is the format rg1616 value.
215+const FORMAT_RG1616 = 0x32334752
216+
217+// FORMAT_GR1616 is the format gr1616 value.
218+const FORMAT_GR1616 = 0x32335247
219+
220+// FORMAT_XRGB16161616F is the format xrgb16161616f value.
221+const FORMAT_XRGB16161616F = 0x48345258
222+
223+// FORMAT_XBGR16161616F is the format xbgr16161616f value.
224+const FORMAT_XBGR16161616F = 0x48344258
225+
226+// FORMAT_ARGB16161616F is the format argb16161616f value.
227+const FORMAT_ARGB16161616F = 0x48345241
228+
229+// FORMAT_ABGR16161616F is the format abgr16161616f value.
230+const FORMAT_ABGR16161616F = 0x48344241
231+
232+// FORMAT_XYUV8888 is the format xyuv8888 value.
233+const FORMAT_XYUV8888 = 0x56555958
234+
235+// FORMAT_VUY888 is the format vuy888 value.
236+const FORMAT_VUY888 = 0x34325556
237+
238+// FORMAT_VUY101010 is the format vuy101010 value.
239+const FORMAT_VUY101010 = 0x30335556
240+
241+// FORMAT_Y210 is the format y210 value.
242+const FORMAT_Y210 = 0x30313259
243+
244+// FORMAT_Y212 is the format y212 value.
245+const FORMAT_Y212 = 0x32313259
246+
247+// FORMAT_Y216 is the format y216 value.
248+const FORMAT_Y216 = 0x36313259
249+
250+// FORMAT_Y410 is the format y410 value.
251+const FORMAT_Y410 = 0x30313459
252+
253+// FORMAT_Y412 is the format y412 value.
254+const FORMAT_Y412 = 0x32313459
255+
256+// FORMAT_Y416 is the format y416 value.
257+const FORMAT_Y416 = 0x36313459
258+
259+// FORMAT_XVYU2101010 is the format xvyu2101010 value.
260+const FORMAT_XVYU2101010 = 0x30335658
261+
262+// FORMAT_XVYU12_16161616 is the format xvyu12_16161616 value.
263+const FORMAT_XVYU12_16161616 = 0x36335658
264+
265+// FORMAT_XVYU16161616 is the format xvyu16161616 value.
266+const FORMAT_XVYU16161616 = 0x38345658
267+
268+// FORMAT_Y0L0 is the format y0l0 value.
269+const FORMAT_Y0L0 = 0x304c3059
270+
271+// FORMAT_X0L0 is the format x0l0 value.
272+const FORMAT_X0L0 = 0x304c3058
273+
274+// FORMAT_Y0L2 is the format y0l2 value.
275+const FORMAT_Y0L2 = 0x324c3059
276+
277+// FORMAT_X0L2 is the format x0l2 value.
278+const FORMAT_X0L2 = 0x324c3058
279+
280+// FORMAT_YUV420_8BIT is the format yuv420_8bit value.
281+const FORMAT_YUV420_8BIT = 0x38305559
282+
283+// FORMAT_YUV420_10BIT is the format yuv420_10bit value.
284+const FORMAT_YUV420_10BIT = 0x30315559
285+
286+// FORMAT_XRGB8888_A8 is the format xrgb8888_a8 value.
287+const FORMAT_XRGB8888_A8 = 0x38415258
288+
289+// FORMAT_XBGR8888_A8 is the format xbgr8888_a8 value.
290+const FORMAT_XBGR8888_A8 = 0x38414258
291+
292+// FORMAT_RGBX8888_A8 is the format rgbx8888_a8 value.
293+const FORMAT_RGBX8888_A8 = 0x38415852
294+
295+// FORMAT_BGRX8888_A8 is the format bgrx8888_a8 value.
296+const FORMAT_BGRX8888_A8 = 0x38415842
297+
298+// FORMAT_RGB888_A8 is the format rgb888_a8 value.
299+const FORMAT_RGB888_A8 = 0x38413852
300+
301+// FORMAT_BGR888_A8 is the format bgr888_a8 value.
302+const FORMAT_BGR888_A8 = 0x38413842
303+
304+// FORMAT_RGB565_A8 is the format rgb565_a8 value.
305+const FORMAT_RGB565_A8 = 0x38413552
306+
307+// FORMAT_BGR565_A8 is the format bgr565_a8 value.
308+const FORMAT_BGR565_A8 = 0x38413542
309+
310+// FORMAT_NV24 is the format nv24 value.
311+const FORMAT_NV24 = 0x3432564e
312+
313+// FORMAT_NV42 is the format nv42 value.
314+const FORMAT_NV42 = 0x3234564e
315+
316+// FORMAT_P210 is the format p210 value.
317+const FORMAT_P210 = 0x30313250
318+
319+// FORMAT_P010 is the format p010 value.
320+const FORMAT_P010 = 0x30313050
321+
322+// FORMAT_P012 is the format p012 value.
323+const FORMAT_P012 = 0x32313050
324+
325+// FORMAT_P016 is the format p016 value.
326+const FORMAT_P016 = 0x36313050
327+
328+// FORMAT_AXBXGXRX106106106106 is the format axbxgxrx106106106106 value.
329+const FORMAT_AXBXGXRX106106106106 = 0x30314241
330+
331+// FORMAT_NV15 is the format nv15 value.
332+const FORMAT_NV15 = 0x3531564e
333+
334+// FORMAT_Q410 is the format q410 value.
335+const FORMAT_Q410 = 0x30313451
336+
337+// FORMAT_Q401 is the format q401 value.
338+const FORMAT_Q401 = 0x31303451
339+
340+// FORMAT_XRGB16161616 is the format xrgb16161616 value.
341+const FORMAT_XRGB16161616 = 0x38345258
342+
343+// FORMAT_XBGR16161616 is the format xbgr16161616 value.
344+const FORMAT_XBGR16161616 = 0x38344258
345+
346+// FORMAT_ARGB16161616 is the format argb16161616 value.
347+const FORMAT_ARGB16161616 = 0x38345241
348+
349+// FORMAT_ABGR16161616 is the format abgr16161616 value.
350+const FORMAT_ABGR16161616 = 0x38344241
351+
352+// FORMAT_C1 is the format c1 value.
353+const FORMAT_C1 = 0x20203143
354+
355+// FORMAT_C2 is the format c2 value.
356+const FORMAT_C2 = 0x20203243
357+
358+// FORMAT_C4 is the format c4 value.
359+const FORMAT_C4 = 0x20203443
360+
361+// FORMAT_D1 is the format d1 value.
362+const FORMAT_D1 = 0x20203144
363+
364+// FORMAT_D2 is the format d2 value.
365+const FORMAT_D2 = 0x20203244
366+
367+// FORMAT_D4 is the format d4 value.
368+const FORMAT_D4 = 0x20203444
369+
370+// FORMAT_D8 is the format d8 value.
371+const FORMAT_D8 = 0x20203844
372+
373+// FORMAT_R1 is the format r1 value.
374+const FORMAT_R1 = 0x20203152
375+
376+// FORMAT_R2 is the format r2 value.
377+const FORMAT_R2 = 0x20203252
378+
379+// FORMAT_R4 is the format r4 value.
380+const FORMAT_R4 = 0x20203452
381+
382+// FORMAT_R10 is the format r10 value.
383+const FORMAT_R10 = 0x20303152
384+
385+// FORMAT_R12 is the format r12 value.
386+const FORMAT_R12 = 0x20323152
387+
388+// FORMAT_AVUY8888 is the format avuy8888 value.
389+const FORMAT_AVUY8888 = 0x59555641
390+
391+// FORMAT_XVUY8888 is the format xvuy8888 value.
392+const FORMAT_XVUY8888 = 0x59555658
393+
394+// FORMAT_P030 is the format p030 value.
395+const FORMAT_P030 = 0x30333050
396+
397+// FORMAT_RGB161616 is the format rgb161616 value.
398+const FORMAT_RGB161616 = 0x38344752
399+
400+// FORMAT_BGR161616 is the format bgr161616 value.
401+const FORMAT_BGR161616 = 0x38344742
402+
403+// FORMAT_R16F is the format r16f value.
404+const FORMAT_R16F = 0x48202052
405+
406+// FORMAT_GR1616F is the format gr1616f value.
407+const FORMAT_GR1616F = 0x48205247
408+
409+// FORMAT_BGR161616F is the format bgr161616f value.
410+const FORMAT_BGR161616F = 0x48524742
411+
412+// FORMAT_R32F is the format r32f value.
413+const FORMAT_R32F = 0x46202052
414+
415+// FORMAT_GR3232F is the format gr3232f value.
416+const FORMAT_GR3232F = 0x46205247
417+
418+// FORMAT_BGR323232F is the format bgr323232f value.
419+const FORMAT_BGR323232F = 0x46524742
420+
421+// FORMAT_ABGR32323232F is the format abgr32323232f value.
422+const FORMAT_ABGR32323232F = 0x46384241
423+
424+// FORMAT_NV20 is the format nv20 value.
425+const FORMAT_NV20 = 0x3032564e
426+
427+// FORMAT_NV30 is the format nv30 value.
428+const FORMAT_NV30 = 0x3033564e
429+
430+// FORMAT_S010 is the format s010 value.
431+const FORMAT_S010 = 0x30313053
432+
433+// FORMAT_S210 is the format s210 value.
434+const FORMAT_S210 = 0x30313253
435+
436+// FORMAT_S410 is the format s410 value.
437+const FORMAT_S410 = 0x30313453
438+
439+// FORMAT_S012 is the format s012 value.
440+const FORMAT_S012 = 0x32313053
441+
442+// FORMAT_S212 is the format s212 value.
443+const FORMAT_S212 = 0x32313253
444+
445+// FORMAT_S412 is the format s412 value.
446+const FORMAT_S412 = 0x32313453
447+
448+// FORMAT_S016 is the format s016 value.
449+const FORMAT_S016 = 0x36313053
450+
451+// FORMAT_S216 is the format s216 value.
452+const FORMAT_S216 = 0x36313253
453+
454+// FORMAT_S416 is the format s416 value.
455+const FORMAT_S416 = 0x36313453
456+
457+// FORMAT_XVUY2101010 is the format xvuy2101010 value.
458+const FORMAT_XVUY2101010 = 0x30335958
459+
460+// FORMAT_P230 is the format p230 value.
461+const FORMAT_P230 = 0x30333250
462+
463+// FORMAT_T430 is the format t430 value.
464+const FORMAT_T430 = 0x30333454
465+
466+// FORMAT_Y8 is the format y8 value.
467+const FORMAT_Y8 = 0x59455247
468+
469+// FORMAT_XYYY2101010 is the format xyyy2101010 value.
470+const FORMAT_XYYY2101010 = 0x34415059
471+
472+// ERROR_INVALID_FINISH is the error invalid_finish value.
473+const ERROR_INVALID_FINISH = 0
474+
475+// WL_DATA_OFFER_ERROR_INVALID_ACTION_MASK is the error invalid_action_mask value.
476+const WL_DATA_OFFER_ERROR_INVALID_ACTION_MASK = 1
477+
478+// ERROR_INVALID_ACTION is the error invalid_action value.
479+const ERROR_INVALID_ACTION = 2
480+
481+// ERROR_INVALID_OFFER is the error invalid_offer value.
482+const ERROR_INVALID_OFFER = 3
483+
484+// WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK is the error invalid_action_mask value.
485+const WL_DATA_SOURCE_ERROR_INVALID_ACTION_MASK = 0
486+
487+// ERROR_INVALID_SOURCE is the error invalid_source value.
488+const ERROR_INVALID_SOURCE = 1
489+
490+// WL_DATA_DEVICE_ERROR_ROLE is the error role value.
491+const WL_DATA_DEVICE_ERROR_ROLE = 0
492+
493+// ERROR_USED_SOURCE is the error used_source value.
494+const ERROR_USED_SOURCE = 1
495+
496+// DND_ACTION_NONE is the dnd_action none value.
497+const DND_ACTION_NONE = 0
498+
499+// DND_ACTION_COPY is the dnd_action copy value.
500+const DND_ACTION_COPY = 1
501+
502+// DND_ACTION_MOVE is the dnd_action move value.
503+const DND_ACTION_MOVE = 2
504+
505+// DND_ACTION_ASK is the dnd_action ask value.
506+const DND_ACTION_ASK = 4
507+
508+// WL_SHELL_ERROR_ROLE is the error role value.
509+const WL_SHELL_ERROR_ROLE = 0
510+
511+// RESIZE_NONE is the resize none value.
512+const RESIZE_NONE = 0
513+
514+// RESIZE_TOP is the resize top value.
515+const RESIZE_TOP = 1
516+
517+// RESIZE_BOTTOM is the resize bottom value.
518+const RESIZE_BOTTOM = 2
519+
520+// RESIZE_LEFT is the resize left value.
521+const RESIZE_LEFT = 4
522+
523+// RESIZE_TOP_LEFT is the resize top_left value.
524+const RESIZE_TOP_LEFT = 5
525+
526+// RESIZE_BOTTOM_LEFT is the resize bottom_left value.
527+const RESIZE_BOTTOM_LEFT = 6
528+
529+// RESIZE_RIGHT is the resize right value.
530+const RESIZE_RIGHT = 8
531+
532+// RESIZE_TOP_RIGHT is the resize top_right value.
533+const RESIZE_TOP_RIGHT = 9
534+
535+// RESIZE_BOTTOM_RIGHT is the resize bottom_right value.
536+const RESIZE_BOTTOM_RIGHT = 10
537+
538+// TRANSIENT_INACTIVE is the transient inactive value.
539+const TRANSIENT_INACTIVE = 0x1
540+
541+// FULLSCREEN_METHOD_DEFAULT is the fullscreen_method default value.
542+const FULLSCREEN_METHOD_DEFAULT = 0
543+
544+// FULLSCREEN_METHOD_SCALE is the fullscreen_method scale value.
545+const FULLSCREEN_METHOD_SCALE = 1
546+
547+// FULLSCREEN_METHOD_DRIVER is the fullscreen_method driver value.
548+const FULLSCREEN_METHOD_DRIVER = 2
549+
550+// FULLSCREEN_METHOD_FILL is the fullscreen_method fill value.
551+const FULLSCREEN_METHOD_FILL = 3
552+
553+// ERROR_INVALID_SCALE is the error invalid_scale value.
554+const ERROR_INVALID_SCALE = 0
555+
556+// ERROR_INVALID_TRANSFORM is the error invalid_transform value.
557+const ERROR_INVALID_TRANSFORM = 1
558+
559+// ERROR_INVALID_SIZE is the error invalid_size value.
560+const ERROR_INVALID_SIZE = 2
561+
562+// ERROR_INVALID_OFFSET is the error invalid_offset value.
563+const ERROR_INVALID_OFFSET = 3
564+
565+// ERROR_DEFUNCT_ROLE_OBJECT is the error defunct_role_object value.
566+const ERROR_DEFUNCT_ROLE_OBJECT = 4
567+
568+// ERROR_NO_BUFFER is the error no_buffer value.
569+const ERROR_NO_BUFFER = 5
570+
571+// CAPABILITY_POINTER is the capability pointer value.
572+const CAPABILITY_POINTER = 1
573+
574+// CAPABILITY_KEYBOARD is the capability keyboard value.
575+const CAPABILITY_KEYBOARD = 2
576+
577+// CAPABILITY_TOUCH is the capability touch value.
578+const CAPABILITY_TOUCH = 4
579+
580+// ERROR_MISSING_CAPABILITY is the error missing_capability value.
581+const ERROR_MISSING_CAPABILITY = 0
582+
583+// WL_POINTER_ERROR_ROLE is the error role value.
584+const WL_POINTER_ERROR_ROLE = 0
585+
586+// BUTTON_STATE_RELEASED is the button_state released value.
587+const BUTTON_STATE_RELEASED = 0
588+
589+// BUTTON_STATE_PRESSED is the button_state pressed value.
590+const BUTTON_STATE_PRESSED = 1
591+
592+// AXIS_VERTICAL_SCROLL is the axis vertical_scroll value.
593+const AXIS_VERTICAL_SCROLL = 0
594+
595+// AXIS_HORIZONTAL_SCROLL is the axis horizontal_scroll value.
596+const AXIS_HORIZONTAL_SCROLL = 1
597+
598+// AXIS_SOURCE_WHEEL is the axis_source wheel value.
599+const AXIS_SOURCE_WHEEL = 0
600+
601+// AXIS_SOURCE_FINGER is the axis_source finger value.
602+const AXIS_SOURCE_FINGER = 1
603+
604+// AXIS_SOURCE_CONTINUOUS is the axis_source continuous value.
605+const AXIS_SOURCE_CONTINUOUS = 2
606+
607+// AXIS_SOURCE_WHEEL_TILT is the axis_source wheel_tilt value.
608+const AXIS_SOURCE_WHEEL_TILT = 3
609+
610+// AXIS_RELATIVE_DIRECTION_IDENTICAL is the axis_relative_direction identical value.
611+const AXIS_RELATIVE_DIRECTION_IDENTICAL = 0
612+
613+// AXIS_RELATIVE_DIRECTION_INVERTED is the axis_relative_direction inverted value.
614+const AXIS_RELATIVE_DIRECTION_INVERTED = 1
615+
616+// KEYMAP_FORMAT_NO_KEYMAP is the keymap_format no_keymap value.
617+const KEYMAP_FORMAT_NO_KEYMAP = 0
618+
619+// KEYMAP_FORMAT_XKB_V1 is the keymap_format xkb_v1 value.
620+const KEYMAP_FORMAT_XKB_V1 = 1
621+
622+// KEY_STATE_RELEASED is the key_state released value.
623+const KEY_STATE_RELEASED = 0
624+
625+// KEY_STATE_PRESSED is the key_state pressed value.
626+const KEY_STATE_PRESSED = 1
627+
628+// KEY_STATE_REPEATED is the key_state repeated value.
629+const KEY_STATE_REPEATED = 2
630+
631+// SUBPIXEL_UNKNOWN is the subpixel unknown value.
632+const SUBPIXEL_UNKNOWN = 0
633+
634+// SUBPIXEL_NONE is the subpixel none value.
635+const SUBPIXEL_NONE = 1
636+
637+// SUBPIXEL_HORIZONTAL_RGB is the subpixel horizontal_rgb value.
638+const SUBPIXEL_HORIZONTAL_RGB = 2
639+
640+// SUBPIXEL_HORIZONTAL_BGR is the subpixel horizontal_bgr value.
641+const SUBPIXEL_HORIZONTAL_BGR = 3
642+
643+// SUBPIXEL_VERTICAL_RGB is the subpixel vertical_rgb value.
644+const SUBPIXEL_VERTICAL_RGB = 4
645+
646+// SUBPIXEL_VERTICAL_BGR is the subpixel vertical_bgr value.
647+const SUBPIXEL_VERTICAL_BGR = 5
648+
649+// TRANSFORM_NORMAL is the transform normal value.
650+const TRANSFORM_NORMAL = 0
651+
652+// TRANSFORM_90 is the transform 90 value.
653+const TRANSFORM_90 = 1
654+
655+// TRANSFORM_180 is the transform 180 value.
656+const TRANSFORM_180 = 2
657+
658+// TRANSFORM_270 is the transform 270 value.
659+const TRANSFORM_270 = 3
660+
661+// TRANSFORM_FLIPPED is the transform flipped value.
662+const TRANSFORM_FLIPPED = 4
663+
664+// TRANSFORM_FLIPPED_90 is the transform flipped_90 value.
665+const TRANSFORM_FLIPPED_90 = 5
666+
667+// TRANSFORM_FLIPPED_180 is the transform flipped_180 value.
668+const TRANSFORM_FLIPPED_180 = 6
669+
670+// TRANSFORM_FLIPPED_270 is the transform flipped_270 value.
671+const TRANSFORM_FLIPPED_270 = 7
672+
673+// MODE_CURRENT is the mode current value.
674+const MODE_CURRENT = 0x1
675+
676+// MODE_PREFERRED is the mode preferred value.
677+const MODE_PREFERRED = 0x2
678+
679+// WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE is the error bad_surface value.
680+const WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE = 0
681+
682+// ERROR_BAD_PARENT is the error bad_parent value.
683+const ERROR_BAD_PARENT = 1
684+
685+// WL_SUBSURFACE_ERROR_BAD_SURFACE is the error bad_surface value.
686+const WL_SUBSURFACE_ERROR_BAD_SURFACE = 0
687+
688+// ERROR_INVALID_ACK_REMOVE is the error invalid_ack_remove value.
689+const ERROR_INVALID_ACK_REMOVE = 0
690+
691+// CallbackInterface is the protocol interface name.
692+const CallbackInterface = "wl_callback"
693+
694+// Callback is the generated binding for wl_callback version 1.
695+type Callback struct {
696+ wl.BaseProxy
697+ // handlersMu guards the handler slices: a client may register or replace
698+ // handlers while another goroutine dispatches events.
699+ handlersMu sync.Mutex
700+ onDone []func(callbackData uint32)
701+}
702+
703+// NewCallback returns an unbound Callback.
704+func NewCallback(ctx *wl.Context) *Callback {
705+ obj := &Callback{}
706+ obj.SetContext(ctx)
707+ ctx.Register(obj)
708+ return obj
709+}
710+
711+// OnDone registers a handler for the done event.
712+//
713+// Handlers are appended, so a second call adds another handler rather than
714+// replacing the first. Registration is safe while another goroutine dispatches.
715+func (o *Callback) OnDone(handler func(callbackData uint32)) {
716+ if handler == nil {
717+ return
718+ }
719+ o.handlersMu.Lock()
720+ defer o.handlersMu.Unlock()
721+ o.onDone = append(o.onDone, handler)
722+}
723+
724+// handlersForDone returns the handlers registered for done, taken
725+// under the lock so a handler may register another handler while events are
726+// being dispatched.
727+func (o *Callback) handlersForDone() []func(callbackData uint32) {
728+ o.handlersMu.Lock()
729+ defer o.handlersMu.Unlock()
730+ return o.onDone
731+}
732+
733+// EventSignature returns the declared event argument types in wire order.
734+func (o *Callback) EventSignature(opcode uint16) (string, bool) {
735+ switch opcode {
736+ case 0:
737+ return "uint,", true
738+ default:
739+ return "", false
740+ }
741+}
742+
743+// Dispatch decodes one event on wl_callback and calls the registered handlers.
744+func (o *Callback) Dispatch(event *wl.Event) {
745+ switch event.Opcode {
746+ case 0: // done
747+ callbackData := event.Uint32()
748+
749+ for i, handler := range o.handlersForDone() {
750+ _ = i
751+ handler(callbackData)
752+ }
753+ o.Context().Unregister(o)
754+ default:
755+ }
756+}
757+
758+// CompositorInterface is the protocol interface name.
759+const CompositorInterface = "wl_compositor"
760+
761+// Compositor is the generated binding for wl_compositor version 7.
762+type Compositor struct {
763+ wl.BaseProxy
764+}
765+
766+// NewCompositor returns an unbound Compositor.
767+func NewCompositor(ctx *wl.Context) *Compositor {
768+ obj := &Compositor{}
769+ obj.SetContext(ctx)
770+ ctx.Register(obj)
771+ return obj
772+}
773+
774+// Ask the compositor to create a new surface.
775+func (o *Compositor) CreateSurface() (*Surface, error) {
776+ child := &Surface{}
777+ child.SetContext(o.Context())
778+ child.SetID(o.Context().AllocateID())
779+ o.Context().Register(child)
780+ if err := o.Context().SendRequest(o, 0, child); err != nil {
781+ o.Context().Unregister(child)
782+ return nil, err
783+ }
784+ return child, nil
785+}
786+
787+// Ask the compositor to create a new region.
788+func (o *Compositor) CreateRegion() (*Region, error) {
789+ child := &Region{}
790+ child.SetContext(o.Context())
791+ child.SetID(o.Context().AllocateID())
792+ o.Context().Register(child)
793+ if err := o.Context().SendRequest(o, 1, child); err != nil {
794+ o.Context().Unregister(child)
795+ return nil, err
796+ }
797+ return child, nil
798+}
799+
800+// This request destroys the wl_compositor. This has no effect on any other objects.
801+func (o *Compositor) Release() error {
802+ if err := o.Context().SendRequest(o, 2); err != nil {
803+ return err
804+ }
805+ o.Context().Unregister(o)
806+ return nil
807+}
808+
809+// EventSignature returns the declared event argument types in wire order.
810+func (o *Compositor) EventSignature(opcode uint16) (string, bool) {
811+ switch opcode {
812+ default:
813+ return "", false
814+ }
815+}
816+
817+// Dispatch decodes one event on wl_compositor and calls the registered handlers.
818+func (o *Compositor) Dispatch(event *wl.Event) {
819+ switch event.Opcode {
820+ default:
821+ }
822+}
823+
824+// ShmPoolInterface is the protocol interface name.
825+const ShmPoolInterface = "wl_shm_pool"
826+
827+// ShmPool is the generated binding for wl_shm_pool version 3.
828+type ShmPool struct {
829+ wl.BaseProxy
830+}
831+
832+// NewShmPool returns an unbound ShmPool.
833+func NewShmPool(ctx *wl.Context) *ShmPool {
834+ obj := &ShmPool{}
835+ obj.SetContext(ctx)
836+ ctx.Register(obj)
837+ return obj
838+}
839+
840+// Create a wl_buffer object from the pool. The buffer is created offset bytes into the pool and has width and height as specified. The stride argument specifies the number of bytes from the beginning of one row to the beginning of the next. The format is the pixel format of the buffer and must be one of those advertised through the wl_shm.format event. A buffer will keep a reference to the pool it was created from so it is valid to destroy the pool immediately after creating a buffer from it.
841+func (o *ShmPool) CreateBuffer(offset int32, width int32, height int32, stride int32, format uint32) (*Buffer, error) {
842+ child := &Buffer{}
843+ child.SetContext(o.Context())
844+ child.SetID(o.Context().AllocateID())
845+ o.Context().Register(child)
846+ if err := o.Context().SendRequest(o, 0, child, offset, width, height, stride, format); err != nil {
847+ o.Context().Unregister(child)
848+ return nil, err
849+ }
850+ return child, nil
851+}
852+
853+// Destroy the shared memory pool. The mmapped memory will be released when all buffers that have been created from this pool are gone.
854+func (o *ShmPool) Destroy() error {
855+ if err := o.Context().SendRequest(o, 1); err != nil {
856+ return err
857+ }
858+ o.Context().Unregister(o)
859+ return nil
860+}
861+
862+// This request will cause the server to remap the backing memory for the pool from the file descriptor passed when the pool was created, but using the new size. This request can only be used to make the pool bigger. This request only changes the amount of bytes that are mmapped by the server and does not touch the file corresponding to the file descriptor passed at creation time. It is the client's responsibility to ensure that the file is at least as big as the new pool size.
863+func (o *ShmPool) Resize(size int32) error {
864+ if err := o.Context().SendRequest(o, 2, size); err != nil {
865+ return err
866+ }
867+ return nil
868+}
869+
870+// EventSignature returns the declared event argument types in wire order.
871+func (o *ShmPool) EventSignature(opcode uint16) (string, bool) {
872+ switch opcode {
873+ default:
874+ return "", false
875+ }
876+}
877+
878+// Dispatch decodes one event on wl_shm_pool and calls the registered handlers.
879+func (o *ShmPool) Dispatch(event *wl.Event) {
880+ switch event.Opcode {
881+ default:
882+ }
883+}
884+
885+// ShmInterface is the protocol interface name.
886+const ShmInterface = "wl_shm"
887+
888+// Shm is the generated binding for wl_shm version 3.
889+type Shm struct {
890+ wl.BaseProxy
891+ // handlersMu guards the handler slices: a client may register or replace
892+ // handlers while another goroutine dispatches events.
893+ handlersMu sync.Mutex
894+ onFormat []func(format uint32)
895+}
896+
897+// NewShm returns an unbound Shm.
898+func NewShm(ctx *wl.Context) *Shm {
899+ obj := &Shm{}
900+ obj.SetContext(ctx)
901+ ctx.Register(obj)
902+ return obj
903+}
904+
905+// Create a new wl_shm_pool object. The pool can be used to create shared memory based buffer objects. The server will mmap size bytes of the passed file descriptor, to use as backing memory for the pool.
906+func (o *Shm) CreatePool(fd int, size int32) (*ShmPool, error) {
907+ child := &ShmPool{}
908+ child.SetContext(o.Context())
909+ child.SetID(o.Context().AllocateID())
910+ o.Context().Register(child)
911+ if err := o.Context().SendRequestWithFDs(o, 0, []int{fd}, child, uintptr(fd), size); err != nil {
912+ o.Context().Unregister(child)
913+ return nil, err
914+ }
915+ _ = wl.CloseSentFD(fd)
916+ return child, nil
917+}
918+
919+// Using this request a client can tell the server that it is not going to use the shm object anymore. Objects created via this interface remain unaffected.
920+func (o *Shm) Release() error {
921+ if err := o.Context().SendRequest(o, 1); err != nil {
922+ return err
923+ }
924+ o.Context().Unregister(o)
925+ return nil
926+}
927+
928+// OnFormat registers a handler for the format event.
929+//
930+// Handlers are appended, so a second call adds another handler rather than
931+// replacing the first. Registration is safe while another goroutine dispatches.
932+func (o *Shm) OnFormat(handler func(format uint32)) {
933+ if handler == nil {
934+ return
935+ }
936+ o.handlersMu.Lock()
937+ defer o.handlersMu.Unlock()
938+ o.onFormat = append(o.onFormat, handler)
939+}
940+
941+// handlersForFormat returns the handlers registered for format, taken
942+// under the lock so a handler may register another handler while events are
943+// being dispatched.
944+func (o *Shm) handlersForFormat() []func(format uint32) {
945+ o.handlersMu.Lock()
946+ defer o.handlersMu.Unlock()
947+ return o.onFormat
948+}
949+
950+// EventSignature returns the declared event argument types in wire order.
951+func (o *Shm) EventSignature(opcode uint16) (string, bool) {
952+ switch opcode {
953+ case 0:
954+ return "uint,", true
955+ default:
956+ return "", false
957+ }
958+}
959+
960+// Dispatch decodes one event on wl_shm and calls the registered handlers.
961+func (o *Shm) Dispatch(event *wl.Event) {
962+ switch event.Opcode {
963+ case 0: // format
964+ format := event.Uint32()
965+
966+ for i, handler := range o.handlersForFormat() {
967+ _ = i
968+ handler(format)
969+ }
970+ default:
971+ }
972+}
973+
974+// BufferInterface is the protocol interface name.
975+const BufferInterface = "wl_buffer"
976+
977+// Buffer is the generated binding for wl_buffer version 1.
978+type Buffer struct {
979+ wl.BaseProxy
980+ // handlersMu guards the handler slices: a client may register or replace
981+ // handlers while another goroutine dispatches events.
982+ handlersMu sync.Mutex
983+ onRelease []func()
984+}
985+
986+// NewBuffer returns an unbound Buffer.
987+func NewBuffer(ctx *wl.Context) *Buffer {
988+ obj := &Buffer{}
989+ obj.SetContext(ctx)
990+ ctx.Register(obj)
991+ return obj
992+}
993+
994+// Destroy a buffer. If and how you need to release the backing storage is defined by the buffer factory interface. For possible side-effects to a surface, see wl_surface.attach.
995+func (o *Buffer) Destroy() error {
996+ if err := o.Context().SendRequest(o, 0); err != nil {
997+ return err
998+ }
999+ o.Context().Unregister(o)
1000+ return nil
1001+}
1002+
1003+// OnRelease registers a handler for the release event.
1004+//
1005+// Handlers are appended, so a second call adds another handler rather than
1006+// replacing the first. Registration is safe while another goroutine dispatches.
1007+func (o *Buffer) OnRelease(handler func()) {
1008+ if handler == nil {
1009+ return
1010+ }
1011+ o.handlersMu.Lock()
1012+ defer o.handlersMu.Unlock()
1013+ o.onRelease = append(o.onRelease, handler)
1014+}
1015+
1016+// handlersForRelease returns the handlers registered for release, taken
1017+// under the lock so a handler may register another handler while events are
1018+// being dispatched.
1019+func (o *Buffer) handlersForRelease() []func() {
1020+ o.handlersMu.Lock()
1021+ defer o.handlersMu.Unlock()
1022+ return o.onRelease
1023+}
1024+
1025+// EventSignature returns the declared event argument types in wire order.
1026+func (o *Buffer) EventSignature(opcode uint16) (string, bool) {
1027+ switch opcode {
1028+ case 0:
1029+ return "", true
1030+ default:
1031+ return "", false
1032+ }
1033+}
1034+
1035+// Dispatch decodes one event on wl_buffer and calls the registered handlers.
1036+func (o *Buffer) Dispatch(event *wl.Event) {
1037+ switch event.Opcode {
1038+ case 0: // release
1039+
1040+ for i, handler := range o.handlersForRelease() {
1041+ _ = i
1042+ handler()
1043+ }
1044+ default:
1045+ }
1046+}
1047+
1048+// DataOfferInterface is the protocol interface name.
1049+const DataOfferInterface = "wl_data_offer"
1050+
1051+// DataOffer is the generated binding for wl_data_offer version 4.
1052+type DataOffer struct {
1053+ wl.BaseProxy
1054+ // handlersMu guards the handler slices: a client may register or replace
1055+ // handlers while another goroutine dispatches events.
1056+ handlersMu sync.Mutex
1057+ onOffer []func(mimeType string)
1058+ onSourceActions []func(sourceActions uint32)
1059+ onAction []func(dndAction uint32)
1060+}
1061+
1062+// NewDataOffer returns an unbound DataOffer.
1063+func NewDataOffer(ctx *wl.Context) *DataOffer {
1064+ obj := &DataOffer{}
1065+ obj.SetContext(ctx)
1066+ ctx.Register(obj)
1067+ return obj
1068+}
1069+
1070+// Indicate that the client can accept the given mime type, or NULL for not accepted. For objects of version 2 or older, this request is used by the client to give feedback whether the client can receive the given mime type, or NULL if none is accepted; the feedback does not determine whether the drag-and-drop operation succeeds or not. For objects of version 3 or newer, this request determines the final result of the drag-and-drop operation. If the end result is that no mime types were accepted, the drag-and-drop operation will be cancelled and the corresponding drag source will receive wl_data_source.cancelled. Clients may still use this event in conjunction with wl_data_source.action for feedback.
1071+func (o *DataOffer) Accept(serial uint32, mimeType string) error {
1072+ if err := o.Context().SendRequest(o, 0, serial, mimeType); err != nil {
1073+ return err
1074+ }
1075+ return nil
1076+}
1077+
1078+// To transfer the offered data, the client issues this request and indicates the mime type it wants to receive. The transfer happens through the passed file descriptor (typically created with the pipe system call). The source client writes the data in the mime type representation requested and then closes the file descriptor. The receiving client reads from the read end of the pipe until EOF and then closes its end, at which point the transfer is complete. This request may happen multiple times for different mime types, both before and after wl_data_device.drop. Drag-and-drop destination clients may preemptively fetch data or examine it more closely to determine acceptance.
1079+func (o *DataOffer) Receive(mimeType string, fd int) error {
1080+ if err := o.Context().SendRequestWithFDs(o, 1, []int{fd}, mimeType, uintptr(fd)); err != nil {
1081+ return err
1082+ }
1083+ _ = wl.CloseSentFD(fd)
1084+ return nil
1085+}
1086+
1087+// Destroy the data offer.
1088+func (o *DataOffer) Destroy() error {
1089+ if err := o.Context().SendRequest(o, 2); err != nil {
1090+ return err
1091+ }
1092+ o.Context().Unregister(o)
1093+ return nil
1094+}
1095+
1096+// Notifies the compositor that the drag destination successfully finished the drag-and-drop operation. Upon receiving this request, the compositor will emit wl_data_source.dnd_finished on the drag source client. It is a client error to perform other requests than wl_data_offer.destroy after this one. It is also an error to perform this request after a NULL mime type has been set in wl_data_offer.accept or no action was received through wl_data_offer.action. If wl_data_offer.finish request is received for a non drag and drop operation, the invalid_finish protocol error is raised.
1097+func (o *DataOffer) Finish() error {
1098+ if err := o.Context().SendRequest(o, 3); err != nil {
1099+ return err
1100+ }
1101+ return nil
1102+}
1103+
1104+// Sets the actions that the destination side client supports for this operation. This request may trigger the emission of wl_data_source.action and wl_data_offer.action events if the compositor needs to change the selected action. This request can be called multiple times throughout the drag-and-drop operation, typically in response to wl_data_device.enter or wl_data_device.motion events. This request determines the final result of the drag-and-drop operation. If the end result is that no action is accepted, the drag source will receive wl_data_source.cancelled. The dnd_actions argument must contain only values expressed in the wl_data_device_manager.dnd_actions enum, and the preferred_action argument must only contain one of those values set, otherwise it will result in a protocol error. While managing an "ask" action, the destination drag-and-drop client may perform further wl_data_offer.receive requests, and is expected to perform one last wl_data_offer.set_actions request with a preferred action other than "ask" (and optionally wl_data_offer.accept) before requesting wl_data_offer.finish, in order to convey the action selected by the user. If the preferred action is not in the wl_data_offer.source_actions mask, an error will be raised. If the "ask" action is dismissed (e.g. user cancellation), the client is expected to perform wl_data_offer.destroy right away. This request can only be made on drag-and-drop offers, a protocol error will be raised otherwise.
1105+func (o *DataOffer) SetActions(dndActions uint32, preferredAction uint32) error {
1106+ if err := o.Context().SendRequest(o, 4, dndActions, preferredAction); err != nil {
1107+ return err
1108+ }
1109+ return nil
1110+}
1111+
1112+// OnOffer registers a handler for the offer event.
1113+//
1114+// Handlers are appended, so a second call adds another handler rather than
1115+// replacing the first. Registration is safe while another goroutine dispatches.
1116+func (o *DataOffer) OnOffer(handler func(mimeType string)) {
1117+ if handler == nil {
1118+ return
1119+ }
1120+ o.handlersMu.Lock()
1121+ defer o.handlersMu.Unlock()
1122+ o.onOffer = append(o.onOffer, handler)
1123+}
1124+
1125+// handlersForOffer returns the handlers registered for offer, taken
1126+// under the lock so a handler may register another handler while events are
1127+// being dispatched.
1128+func (o *DataOffer) handlersForOffer() []func(mimeType string) {
1129+ o.handlersMu.Lock()
1130+ defer o.handlersMu.Unlock()
1131+ return o.onOffer
1132+}
1133+
1134+// OnSourceActions registers a handler for the source_actions event.
1135+//
1136+// Handlers are appended, so a second call adds another handler rather than
1137+// replacing the first. Registration is safe while another goroutine dispatches.
1138+func (o *DataOffer) OnSourceActions(handler func(sourceActions uint32)) {
1139+ if handler == nil {
1140+ return
1141+ }
1142+ o.handlersMu.Lock()
1143+ defer o.handlersMu.Unlock()
1144+ o.onSourceActions = append(o.onSourceActions, handler)
1145+}
1146+
1147+// handlersForSourceActions returns the handlers registered for source_actions, taken
1148+// under the lock so a handler may register another handler while events are
1149+// being dispatched.
1150+func (o *DataOffer) handlersForSourceActions() []func(sourceActions uint32) {
1151+ o.handlersMu.Lock()
1152+ defer o.handlersMu.Unlock()
1153+ return o.onSourceActions
1154+}
1155+
1156+// OnAction registers a handler for the action event.
1157+//
1158+// Handlers are appended, so a second call adds another handler rather than
1159+// replacing the first. Registration is safe while another goroutine dispatches.
1160+func (o *DataOffer) OnAction(handler func(dndAction uint32)) {
1161+ if handler == nil {
1162+ return
1163+ }
1164+ o.handlersMu.Lock()
1165+ defer o.handlersMu.Unlock()
1166+ o.onAction = append(o.onAction, handler)
1167+}
1168+
1169+// handlersForAction returns the handlers registered for action, taken
1170+// under the lock so a handler may register another handler while events are
1171+// being dispatched.
1172+func (o *DataOffer) handlersForAction() []func(dndAction uint32) {
1173+ o.handlersMu.Lock()
1174+ defer o.handlersMu.Unlock()
1175+ return o.onAction
1176+}
1177+
1178+// EventSignature returns the declared event argument types in wire order.
1179+func (o *DataOffer) EventSignature(opcode uint16) (string, bool) {
1180+ switch opcode {
1181+ case 0:
1182+ return "string,", true
1183+ case 1:
1184+ return "uint,", true
1185+ case 2:
1186+ return "uint,", true
1187+ default:
1188+ return "", false
1189+ }
1190+}
1191+
1192+// Dispatch decodes one event on wl_data_offer and calls the registered handlers.
1193+func (o *DataOffer) Dispatch(event *wl.Event) {
1194+ switch event.Opcode {
1195+ case 0: // offer
1196+ mimeType := event.String()
1197+
1198+ for i, handler := range o.handlersForOffer() {
1199+ _ = i
1200+ handler(mimeType)
1201+ }
1202+ case 1: // source_actions
1203+ sourceActions := event.Uint32()
1204+
1205+ for i, handler := range o.handlersForSourceActions() {
1206+ _ = i
1207+ handler(sourceActions)
1208+ }
1209+ case 2: // action
1210+ dndAction := event.Uint32()
1211+
1212+ for i, handler := range o.handlersForAction() {
1213+ _ = i
1214+ handler(dndAction)
1215+ }
1216+ default:
1217+ }
1218+}
1219+
1220+// DataSourceInterface is the protocol interface name.
1221+const DataSourceInterface = "wl_data_source"
1222+
1223+// DataSource is the generated binding for wl_data_source version 4.
1224+type DataSource struct {
1225+ wl.BaseProxy
1226+ // handlersMu guards the handler slices: a client may register or replace
1227+ // handlers while another goroutine dispatches events.
1228+ handlersMu sync.Mutex
1229+ onTarget []func(mimeType string)
1230+ onSend []func(mimeType string, fd *wl.OwnedFD)
1231+ onCancelled []func()
1232+ onDndDropPerformed []func()
1233+ onDndFinished []func()
1234+ onAction []func(dndAction uint32)
1235+}
1236+
1237+// NewDataSource returns an unbound DataSource.
1238+func NewDataSource(ctx *wl.Context) *DataSource {
1239+ obj := &DataSource{}
1240+ obj.SetContext(ctx)
1241+ ctx.Register(obj)
1242+ return obj
1243+}
1244+
1245+// This request adds a mime type to the set of mime types advertised to targets. Can be called several times to offer multiple types.
1246+func (o *DataSource) Offer(mimeType string) error {
1247+ if err := o.Context().SendRequest(o, 0, mimeType); err != nil {
1248+ return err
1249+ }
1250+ return nil
1251+}
1252+
1253+// Destroy the data source.
1254+func (o *DataSource) Destroy() error {
1255+ if err := o.Context().SendRequest(o, 1); err != nil {
1256+ return err
1257+ }
1258+ o.Context().Unregister(o)
1259+ return nil
1260+}
1261+
1262+// Sets the actions that the source side client supports for this operation. This request may trigger wl_data_source.action and wl_data_offer.action events if the compositor needs to change the selected action. The dnd_actions argument must contain only values expressed in the wl_data_device_manager.dnd_actions enum, otherwise it will result in a protocol error. This request must be made once only, and can only be made on sources used in drag-and-drop, so it must be performed before wl_data_device.start_drag. Attempting to use the source other than for drag-and-drop will raise a protocol error.
1263+func (o *DataSource) SetActions(dndActions uint32) error {
1264+ if err := o.Context().SendRequest(o, 2, dndActions); err != nil {
1265+ return err
1266+ }
1267+ return nil
1268+}
1269+
1270+// OnTarget registers a handler for the target event.
1271+//
1272+// Handlers are appended, so a second call adds another handler rather than
1273+// replacing the first. Registration is safe while another goroutine dispatches.
1274+func (o *DataSource) OnTarget(handler func(mimeType string)) {
1275+ if handler == nil {
1276+ return
1277+ }
1278+ o.handlersMu.Lock()
1279+ defer o.handlersMu.Unlock()
1280+ o.onTarget = append(o.onTarget, handler)
1281+}
1282+
1283+// handlersForTarget returns the handlers registered for target, taken
1284+// under the lock so a handler may register another handler while events are
1285+// being dispatched.
1286+func (o *DataSource) handlersForTarget() []func(mimeType string) {
1287+ o.handlersMu.Lock()
1288+ defer o.handlersMu.Unlock()
1289+ return o.onTarget
1290+}
1291+
1292+// OnSend registers a handler for the send event.
1293+//
1294+// Handlers are appended, so a second call adds another handler rather than
1295+// replacing the first. Registration is safe while another goroutine dispatches.
1296+func (o *DataSource) OnSend(handler func(mimeType string, fd *wl.OwnedFD)) {
1297+ if handler == nil {
1298+ return
1299+ }
1300+ o.handlersMu.Lock()
1301+ defer o.handlersMu.Unlock()
1302+ o.onSend = append(o.onSend, handler)
1303+}
1304+
1305+// handlersForSend returns the handlers registered for send, taken
1306+// under the lock so a handler may register another handler while events are
1307+// being dispatched.
1308+func (o *DataSource) handlersForSend() []func(mimeType string, fd *wl.OwnedFD) {
1309+ o.handlersMu.Lock()
1310+ defer o.handlersMu.Unlock()
1311+ return o.onSend
1312+}
1313+
1314+// OnCancelled registers a handler for the cancelled event.
1315+//
1316+// Handlers are appended, so a second call adds another handler rather than
1317+// replacing the first. Registration is safe while another goroutine dispatches.
1318+func (o *DataSource) OnCancelled(handler func()) {
1319+ if handler == nil {
1320+ return
1321+ }
1322+ o.handlersMu.Lock()
1323+ defer o.handlersMu.Unlock()
1324+ o.onCancelled = append(o.onCancelled, handler)
1325+}
1326+
1327+// handlersForCancelled returns the handlers registered for cancelled, taken
1328+// under the lock so a handler may register another handler while events are
1329+// being dispatched.
1330+func (o *DataSource) handlersForCancelled() []func() {
1331+ o.handlersMu.Lock()
1332+ defer o.handlersMu.Unlock()
1333+ return o.onCancelled
1334+}
1335+
1336+// OnDndDropPerformed registers a handler for the dnd_drop_performed event.
1337+//
1338+// Handlers are appended, so a second call adds another handler rather than
1339+// replacing the first. Registration is safe while another goroutine dispatches.
1340+func (o *DataSource) OnDndDropPerformed(handler func()) {
1341+ if handler == nil {
1342+ return
1343+ }
1344+ o.handlersMu.Lock()
1345+ defer o.handlersMu.Unlock()
1346+ o.onDndDropPerformed = append(o.onDndDropPerformed, handler)
1347+}
1348+
1349+// handlersForDndDropPerformed returns the handlers registered for dnd_drop_performed, taken
1350+// under the lock so a handler may register another handler while events are
1351+// being dispatched.
1352+func (o *DataSource) handlersForDndDropPerformed() []func() {
1353+ o.handlersMu.Lock()
1354+ defer o.handlersMu.Unlock()
1355+ return o.onDndDropPerformed
1356+}
1357+
1358+// OnDndFinished registers a handler for the dnd_finished event.
1359+//
1360+// Handlers are appended, so a second call adds another handler rather than
1361+// replacing the first. Registration is safe while another goroutine dispatches.
1362+func (o *DataSource) OnDndFinished(handler func()) {
1363+ if handler == nil {
1364+ return
1365+ }
1366+ o.handlersMu.Lock()
1367+ defer o.handlersMu.Unlock()
1368+ o.onDndFinished = append(o.onDndFinished, handler)
1369+}
1370+
1371+// handlersForDndFinished returns the handlers registered for dnd_finished, taken
1372+// under the lock so a handler may register another handler while events are
1373+// being dispatched.
1374+func (o *DataSource) handlersForDndFinished() []func() {
1375+ o.handlersMu.Lock()
1376+ defer o.handlersMu.Unlock()
1377+ return o.onDndFinished
1378+}
1379+
1380+// OnAction registers a handler for the action event.
1381+//
1382+// Handlers are appended, so a second call adds another handler rather than
1383+// replacing the first. Registration is safe while another goroutine dispatches.
1384+func (o *DataSource) OnAction(handler func(dndAction uint32)) {
1385+ if handler == nil {
1386+ return
1387+ }
1388+ o.handlersMu.Lock()
1389+ defer o.handlersMu.Unlock()
1390+ o.onAction = append(o.onAction, handler)
1391+}
1392+
1393+// handlersForAction returns the handlers registered for action, taken
1394+// under the lock so a handler may register another handler while events are
1395+// being dispatched.
1396+func (o *DataSource) handlersForAction() []func(dndAction uint32) {
1397+ o.handlersMu.Lock()
1398+ defer o.handlersMu.Unlock()
1399+ return o.onAction
1400+}
1401+
1402+// EventSignature returns the declared event argument types in wire order.
1403+func (o *DataSource) EventSignature(opcode uint16) (string, bool) {
1404+ switch opcode {
1405+ case 0:
1406+ return "string,", true
1407+ case 1:
1408+ return "string,fd,", true
1409+ case 2:
1410+ return "", true
1411+ case 3:
1412+ return "", true
1413+ case 4:
1414+ return "", true
1415+ case 5:
1416+ return "uint,", true
1417+ default:
1418+ return "", false
1419+ }
1420+}
1421+
1422+// Dispatch decodes one event on wl_data_source and calls the registered handlers.
1423+func (o *DataSource) Dispatch(event *wl.Event) {
1424+ switch event.Opcode {
1425+ case 0: // target
1426+ mimeType := event.String()
1427+
1428+ for i, handler := range o.handlersForTarget() {
1429+ _ = i
1430+ handler(mimeType)
1431+ }
1432+ case 1: // send
1433+ mimeType := event.String()
1434+ fd := event.FD()
1435+ defer func() { _ = fd.Close() }()
1436+ for i, handler := range o.handlersForSend() {
1437+ if i > 0 {
1438+ fd = nil
1439+ }
1440+ handler(mimeType, fd)
1441+ }
1442+ case 2: // cancelled
1443+
1444+ for i, handler := range o.handlersForCancelled() {
1445+ _ = i
1446+ handler()
1447+ }
1448+ case 3: // dnd_drop_performed
1449+
1450+ for i, handler := range o.handlersForDndDropPerformed() {
1451+ _ = i
1452+ handler()
1453+ }
1454+ case 4: // dnd_finished
1455+
1456+ for i, handler := range o.handlersForDndFinished() {
1457+ _ = i
1458+ handler()
1459+ }
1460+ case 5: // action
1461+ dndAction := event.Uint32()
1462+
1463+ for i, handler := range o.handlersForAction() {
1464+ _ = i
1465+ handler(dndAction)
1466+ }
1467+ default:
1468+ }
1469+}
1470+
1471+// DataDeviceInterface is the protocol interface name.
1472+const DataDeviceInterface = "wl_data_device"
1473+
1474+// DataDevice is the generated binding for wl_data_device version 4.
1475+type DataDevice struct {
1476+ wl.BaseProxy
1477+ // handlersMu guards the handler slices: a client may register or replace
1478+ // handlers while another goroutine dispatches events.
1479+ handlersMu sync.Mutex
1480+ onDataOffer []func(idObject *DataOffer)
1481+ onEnter []func(serial uint32, surfaceID uint32, x wl.Fixed, y wl.Fixed, idID uint32)
1482+ onLeave []func()
1483+ onMotion []func(time uint32, x wl.Fixed, y wl.Fixed)
1484+ onDrop []func()
1485+ onSelection []func(idID uint32)
1486+}
1487+
1488+// NewDataDevice returns an unbound DataDevice.
1489+func NewDataDevice(ctx *wl.Context) *DataDevice {
1490+ obj := &DataDevice{}
1491+ obj.SetContext(ctx)
1492+ ctx.Register(obj)
1493+ return obj
1494+}
1495+
1496+// This request asks the compositor to start a drag-and-drop operation on behalf of the client. The source argument is the data source that provides the data for the eventual data transfer. If source is NULL, enter, leave and motion events are sent only to the client that initiated the drag and the client is expected to handle the data passing internally. If source is destroyed, the drag-and-drop session will be cancelled. The origin surface is the surface where the drag originates and the client must have an active implicit grab that matches the serial. The icon surface is an optional (can be NULL) surface that provides an icon to be moved around with the cursor. Initially, the top-left corner of the icon surface is placed at the cursor hotspot, but subsequent wl_surface.offset requests can move the relative position. Attach requests must be confirmed with wl_surface.commit as usual. The icon surface is given the role of a drag-and-drop icon. If the icon surface already has another role, it raises a protocol error. The input region is ignored for wl_surfaces with the role of a drag-and-drop icon. The given source may not be used in any further set_selection or start_drag requests. Attempting to reuse a previously-used source may send a used_source error.
1497+func (o *DataDevice) StartDrag(source *DataSource, origin *Surface, icon *Surface, serial uint32) error {
1498+ var arg0 wl.Object
1499+ if source != nil {
1500+ arg0 = source
1501+ }
1502+ var arg1 wl.Object
1503+ if origin != nil {
1504+ arg1 = origin
1505+ }
1506+ var arg2 wl.Object
1507+ if icon != nil {
1508+ arg2 = icon
1509+ }
1510+ if err := o.Context().SendRequest(o, 0, arg0, arg1, arg2, serial); err != nil {
1511+ return err
1512+ }
1513+ return nil
1514+}
1515+
1516+// This request asks the compositor to set the selection to the data from the source on behalf of the client. To unset the selection, set the source to NULL. The given source may not be used in any further set_selection or start_drag requests. Attempting to reuse a previously-used source may send a used_source error.
1517+func (o *DataDevice) SetSelection(source *DataSource, serial uint32) error {
1518+ var arg0 wl.Object
1519+ if source != nil {
1520+ arg0 = source
1521+ }
1522+ if err := o.Context().SendRequest(o, 1, arg0, serial); err != nil {
1523+ return err
1524+ }
1525+ return nil
1526+}
1527+
1528+// This request destroys the data device.
1529+func (o *DataDevice) Release() error {
1530+ if err := o.Context().SendRequest(o, 2); err != nil {
1531+ return err
1532+ }
1533+ o.Context().Unregister(o)
1534+ return nil
1535+}
1536+
1537+// OnDataOffer registers a handler for the data_offer event.
1538+//
1539+// Handlers are appended, so a second call adds another handler rather than
1540+// replacing the first. Registration is safe while another goroutine dispatches.
1541+func (o *DataDevice) OnDataOffer(handler func(idObject *DataOffer)) {
1542+ if handler == nil {
1543+ return
1544+ }
1545+ o.handlersMu.Lock()
1546+ defer o.handlersMu.Unlock()
1547+ o.onDataOffer = append(o.onDataOffer, handler)
1548+}
1549+
1550+// handlersForDataOffer returns the handlers registered for data_offer, taken
1551+// under the lock so a handler may register another handler while events are
1552+// being dispatched.
1553+func (o *DataDevice) handlersForDataOffer() []func(idObject *DataOffer) {
1554+ o.handlersMu.Lock()
1555+ defer o.handlersMu.Unlock()
1556+ return o.onDataOffer
1557+}
1558+
1559+// OnEnter registers a handler for the enter event.
1560+//
1561+// Handlers are appended, so a second call adds another handler rather than
1562+// replacing the first. Registration is safe while another goroutine dispatches.
1563+func (o *DataDevice) OnEnter(handler func(serial uint32, surfaceID uint32, x wl.Fixed, y wl.Fixed, idID uint32)) {
1564+ if handler == nil {
1565+ return
1566+ }
1567+ o.handlersMu.Lock()
1568+ defer o.handlersMu.Unlock()
1569+ o.onEnter = append(o.onEnter, handler)
1570+}
1571+
1572+// handlersForEnter returns the handlers registered for enter, taken
1573+// under the lock so a handler may register another handler while events are
1574+// being dispatched.
1575+func (o *DataDevice) handlersForEnter() []func(serial uint32, surfaceID uint32, x wl.Fixed, y wl.Fixed, idID uint32) {
1576+ o.handlersMu.Lock()
1577+ defer o.handlersMu.Unlock()
1578+ return o.onEnter
1579+}
1580+
1581+// OnLeave registers a handler for the leave event.
1582+//
1583+// Handlers are appended, so a second call adds another handler rather than
1584+// replacing the first. Registration is safe while another goroutine dispatches.
1585+func (o *DataDevice) OnLeave(handler func()) {
1586+ if handler == nil {
1587+ return
1588+ }
1589+ o.handlersMu.Lock()
1590+ defer o.handlersMu.Unlock()
1591+ o.onLeave = append(o.onLeave, handler)
1592+}
1593+
1594+// handlersForLeave returns the handlers registered for leave, taken
1595+// under the lock so a handler may register another handler while events are
1596+// being dispatched.
1597+func (o *DataDevice) handlersForLeave() []func() {
1598+ o.handlersMu.Lock()
1599+ defer o.handlersMu.Unlock()
1600+ return o.onLeave
1601+}
1602+
1603+// OnMotion registers a handler for the motion event.
1604+//
1605+// Handlers are appended, so a second call adds another handler rather than
1606+// replacing the first. Registration is safe while another goroutine dispatches.
1607+func (o *DataDevice) OnMotion(handler func(time uint32, x wl.Fixed, y wl.Fixed)) {
1608+ if handler == nil {
1609+ return
1610+ }
1611+ o.handlersMu.Lock()
1612+ defer o.handlersMu.Unlock()
1613+ o.onMotion = append(o.onMotion, handler)
1614+}
1615+
1616+// handlersForMotion returns the handlers registered for motion, taken
1617+// under the lock so a handler may register another handler while events are
1618+// being dispatched.
1619+func (o *DataDevice) handlersForMotion() []func(time uint32, x wl.Fixed, y wl.Fixed) {
1620+ o.handlersMu.Lock()
1621+ defer o.handlersMu.Unlock()
1622+ return o.onMotion
1623+}
1624+
1625+// OnDrop registers a handler for the drop event.
1626+//
1627+// Handlers are appended, so a second call adds another handler rather than
1628+// replacing the first. Registration is safe while another goroutine dispatches.
1629+func (o *DataDevice) OnDrop(handler func()) {
1630+ if handler == nil {
1631+ return
1632+ }
1633+ o.handlersMu.Lock()
1634+ defer o.handlersMu.Unlock()
1635+ o.onDrop = append(o.onDrop, handler)
1636+}
1637+
1638+// handlersForDrop returns the handlers registered for drop, taken
1639+// under the lock so a handler may register another handler while events are
1640+// being dispatched.
1641+func (o *DataDevice) handlersForDrop() []func() {
1642+ o.handlersMu.Lock()
1643+ defer o.handlersMu.Unlock()
1644+ return o.onDrop
1645+}
1646+
1647+// OnSelection registers a handler for the selection event.
1648+//
1649+// Handlers are appended, so a second call adds another handler rather than
1650+// replacing the first. Registration is safe while another goroutine dispatches.
1651+func (o *DataDevice) OnSelection(handler func(idID uint32)) {
1652+ if handler == nil {
1653+ return
1654+ }
1655+ o.handlersMu.Lock()
1656+ defer o.handlersMu.Unlock()
1657+ o.onSelection = append(o.onSelection, handler)
1658+}
1659+
1660+// handlersForSelection returns the handlers registered for selection, taken
1661+// under the lock so a handler may register another handler while events are
1662+// being dispatched.
1663+func (o *DataDevice) handlersForSelection() []func(idID uint32) {
1664+ o.handlersMu.Lock()
1665+ defer o.handlersMu.Unlock()
1666+ return o.onSelection
1667+}
1668+
1669+// EventSignature returns the declared event argument types in wire order.
1670+func (o *DataDevice) EventSignature(opcode uint16) (string, bool) {
1671+ switch opcode {
1672+ case 0:
1673+ return "new_id,", true
1674+ case 1:
1675+ return "uint,object,fixed,fixed,object,", true
1676+ case 2:
1677+ return "", true
1678+ case 3:
1679+ return "uint,fixed,fixed,", true
1680+ case 4:
1681+ return "", true
1682+ case 5:
1683+ return "object,", true
1684+ default:
1685+ return "", false
1686+ }
1687+}
1688+
1689+// Dispatch decodes one event on wl_data_device and calls the registered handlers.
1690+func (o *DataDevice) Dispatch(event *wl.Event) {
1691+ switch event.Opcode {
1692+ case 0: // data_offer
1693+ idID := event.Uint32()
1694+ idObject := &DataOffer{}
1695+ idObject.SetContext(o.Context())
1696+ idObject.SetID(idID)
1697+ o.Context().Register(idObject)
1698+
1699+ for i, handler := range o.handlersForDataOffer() {
1700+ _ = i
1701+ handler(idObject)
1702+ }
1703+ case 1: // enter
1704+ serial := event.Uint32()
1705+ surfaceID := event.Uint32()
1706+ x := event.Fixed()
1707+ y := event.Fixed()
1708+ idID := event.Uint32()
1709+
1710+ for i, handler := range o.handlersForEnter() {
1711+ _ = i
1712+ handler(serial, surfaceID, x, y, idID)
1713+ }
1714+ case 2: // leave
1715+
1716+ for i, handler := range o.handlersForLeave() {
1717+ _ = i
1718+ handler()
1719+ }
1720+ case 3: // motion
1721+ time := event.Uint32()
1722+ x := event.Fixed()
1723+ y := event.Fixed()
1724+
1725+ for i, handler := range o.handlersForMotion() {
1726+ _ = i
1727+ handler(time, x, y)
1728+ }
1729+ case 4: // drop
1730+
1731+ for i, handler := range o.handlersForDrop() {
1732+ _ = i
1733+ handler()
1734+ }
1735+ case 5: // selection
1736+ idID := event.Uint32()
1737+
1738+ for i, handler := range o.handlersForSelection() {
1739+ _ = i
1740+ handler(idID)
1741+ }
1742+ default:
1743+ }
1744+}
1745+
1746+// DataDeviceManagerInterface is the protocol interface name.
1747+const DataDeviceManagerInterface = "wl_data_device_manager"
1748+
1749+// DataDeviceManager is the generated binding for wl_data_device_manager version 4.
1750+type DataDeviceManager struct {
1751+ wl.BaseProxy
1752+}
1753+
1754+// NewDataDeviceManager returns an unbound DataDeviceManager.
1755+func NewDataDeviceManager(ctx *wl.Context) *DataDeviceManager {
1756+ obj := &DataDeviceManager{}
1757+ obj.SetContext(ctx)
1758+ ctx.Register(obj)
1759+ return obj
1760+}
1761+
1762+// Create a new data source.
1763+func (o *DataDeviceManager) CreateDataSource() (*DataSource, error) {
1764+ child := &DataSource{}
1765+ child.SetContext(o.Context())
1766+ child.SetID(o.Context().AllocateID())
1767+ o.Context().Register(child)
1768+ if err := o.Context().SendRequest(o, 0, child); err != nil {
1769+ o.Context().Unregister(child)
1770+ return nil, err
1771+ }
1772+ return child, nil
1773+}
1774+
1775+// Create a new data device for a given seat.
1776+func (o *DataDeviceManager) GetDataDevice(seat *Seat) (*DataDevice, error) {
1777+ var arg1 wl.Object
1778+ if seat != nil {
1779+ arg1 = seat
1780+ }
1781+ child := &DataDevice{}
1782+ child.SetContext(o.Context())
1783+ child.SetID(o.Context().AllocateID())
1784+ o.Context().Register(child)
1785+ if err := o.Context().SendRequest(o, 1, child, arg1); err != nil {
1786+ o.Context().Unregister(child)
1787+ return nil, err
1788+ }
1789+ return child, nil
1790+}
1791+
1792+// This request destroys the wl_data_device_manager. This has no effect on any other objects.
1793+func (o *DataDeviceManager) Release() error {
1794+ if err := o.Context().SendRequest(o, 2); err != nil {
1795+ return err
1796+ }
1797+ o.Context().Unregister(o)
1798+ return nil
1799+}
1800+
1801+// EventSignature returns the declared event argument types in wire order.
1802+func (o *DataDeviceManager) EventSignature(opcode uint16) (string, bool) {
1803+ switch opcode {
1804+ default:
1805+ return "", false
1806+ }
1807+}
1808+
1809+// Dispatch decodes one event on wl_data_device_manager and calls the registered handlers.
1810+func (o *DataDeviceManager) Dispatch(event *wl.Event) {
1811+ switch event.Opcode {
1812+ default:
1813+ }
1814+}
1815+
1816+// ShellInterface is the protocol interface name.
1817+const ShellInterface = "wl_shell"
1818+
1819+// Shell is the generated binding for wl_shell version 1.
1820+type Shell struct {
1821+ wl.BaseProxy
1822+}
1823+
1824+// NewShell returns an unbound Shell.
1825+func NewShell(ctx *wl.Context) *Shell {
1826+ obj := &Shell{}
1827+ obj.SetContext(ctx)
1828+ ctx.Register(obj)
1829+ return obj
1830+}
1831+
1832+// Create a shell surface for an existing surface. This gives the wl_surface the role of a shell surface. If the wl_surface already has another role, it raises a protocol error. Only one shell surface can be associated with a given surface.
1833+func (o *Shell) GetShellSurface(surface *Surface) (*ShellSurface, error) {
1834+ var arg1 wl.Object
1835+ if surface != nil {
1836+ arg1 = surface
1837+ }
1838+ child := &ShellSurface{}
1839+ child.SetContext(o.Context())
1840+ child.SetID(o.Context().AllocateID())
1841+ o.Context().Register(child)
1842+ if err := o.Context().SendRequest(o, 0, child, arg1); err != nil {
1843+ o.Context().Unregister(child)
1844+ return nil, err
1845+ }
1846+ return child, nil
1847+}
1848+
1849+// EventSignature returns the declared event argument types in wire order.
1850+func (o *Shell) EventSignature(opcode uint16) (string, bool) {
1851+ switch opcode {
1852+ default:
1853+ return "", false
1854+ }
1855+}
1856+
1857+// Dispatch decodes one event on wl_shell and calls the registered handlers.
1858+func (o *Shell) Dispatch(event *wl.Event) {
1859+ switch event.Opcode {
1860+ default:
1861+ }
1862+}
1863+
1864+// ShellSurfaceInterface is the protocol interface name.
1865+const ShellSurfaceInterface = "wl_shell_surface"
1866+
1867+// ShellSurface is the generated binding for wl_shell_surface version 1.
1868+type ShellSurface struct {
1869+ wl.BaseProxy
1870+ // handlersMu guards the handler slices: a client may register or replace
1871+ // handlers while another goroutine dispatches events.
1872+ handlersMu sync.Mutex
1873+ onPing []func(serial uint32)
1874+ onConfigure []func(edges uint32, width int32, height int32)
1875+ onPopupDone []func()
1876+}
1877+
1878+// NewShellSurface returns an unbound ShellSurface.
1879+func NewShellSurface(ctx *wl.Context) *ShellSurface {
1880+ obj := &ShellSurface{}
1881+ obj.SetContext(ctx)
1882+ ctx.Register(obj)
1883+ return obj
1884+}
1885+
1886+// A client must respond to a ping event with a pong request or the client may be deemed unresponsive.
1887+func (o *ShellSurface) Pong(serial uint32) error {
1888+ if err := o.Context().SendRequest(o, 0, serial); err != nil {
1889+ return err
1890+ }
1891+ return nil
1892+}
1893+
1894+// Start a pointer-driven move of the surface. This request must be used in response to a button press event. The server may ignore move requests depending on the state of the surface (e.g. fullscreen or maximized).
1895+func (o *ShellSurface) Move(seat *Seat, serial uint32) error {
1896+ var arg0 wl.Object
1897+ if seat != nil {
1898+ arg0 = seat
1899+ }
1900+ if err := o.Context().SendRequest(o, 1, arg0, serial); err != nil {
1901+ return err
1902+ }
1903+ return nil
1904+}
1905+
1906+// Start a pointer-driven resizing of the surface. This request must be used in response to a button press event. The server may ignore resize requests depending on the state of the surface (e.g. fullscreen or maximized).
1907+func (o *ShellSurface) Resize(seat *Seat, serial uint32, edges uint32) error {
1908+ var arg0 wl.Object
1909+ if seat != nil {
1910+ arg0 = seat
1911+ }
1912+ if err := o.Context().SendRequest(o, 2, arg0, serial, edges); err != nil {
1913+ return err
1914+ }
1915+ return nil
1916+}
1917+
1918+// Map the surface as a toplevel surface. A toplevel surface is not fullscreen, maximized or transient.
1919+func (o *ShellSurface) SetToplevel() error {
1920+ if err := o.Context().SendRequest(o, 3); err != nil {
1921+ return err
1922+ }
1923+ return nil
1924+}
1925+
1926+// Map the surface relative to an existing surface. The x and y arguments specify the location of the upper left corner of the surface relative to the upper left corner of the parent surface, in surface-local coordinates. The flags argument controls details of the transient behaviour.
1927+func (o *ShellSurface) SetTransient(parent *Surface, x int32, y int32, flags uint32) error {
1928+ var arg0 wl.Object
1929+ if parent != nil {
1930+ arg0 = parent
1931+ }
1932+ if err := o.Context().SendRequest(o, 4, arg0, x, y, flags); err != nil {
1933+ return err
1934+ }
1935+ return nil
1936+}
1937+
1938+// Map the surface as a fullscreen surface. If an output parameter is given then the surface will be made fullscreen on that output. If the client does not specify the output then the compositor will apply its policy - usually choosing the output on which the surface has the biggest surface area. The client may specify a method to resolve a size conflict between the output size and the surface size - this is provided through the method parameter. The framerate parameter is used only when the method is set to "driver", to indicate the preferred framerate. A value of 0 indicates that the client does not care about framerate. The framerate is specified in mHz, that is framerate of 60000 is 60Hz. A method of "scale" or "driver" implies a scaling operation of the surface, either via a direct scaling operation or a change of the output mode. This will override any kind of output scaling, so that mapping a surface with a buffer size equal to the mode can fill the screen independent of buffer_scale. A method of "fill" means we don't scale up the buffer, however any output scale is applied. This means that you may run into an edge case where the application maps a buffer with the same size of the output mode but buffer_scale 1 (thus making a surface larger than the output). In this case it is allowed to downscale the results to fit the screen. The compositor must reply to this request with a configure event with the dimensions for the output on which the surface will be made fullscreen.
1939+func (o *ShellSurface) SetFullscreen(method uint32, framerate uint32, output *Output) error {
1940+ var arg2 wl.Object
1941+ if output != nil {
1942+ arg2 = output
1943+ }
1944+ if err := o.Context().SendRequest(o, 5, method, framerate, arg2); err != nil {
1945+ return err
1946+ }
1947+ return nil
1948+}
1949+
1950+// Map the surface as a popup. A popup surface is a transient surface with an added pointer grab. An existing implicit grab will be changed to owner-events mode, and the popup grab will continue after the implicit grab ends (i.e. releasing the mouse button does not cause the popup to be unmapped). The popup grab continues until the window is destroyed or a mouse button is pressed in any other client's window. A click in any of the client's surfaces is reported as normal, however, clicks in other clients' surfaces will be discarded and trigger the callback. The x and y arguments specify the location of the upper left corner of the surface relative to the upper left corner of the parent surface, in surface-local coordinates.
1951+func (o *ShellSurface) SetPopup(seat *Seat, serial uint32, parent *Surface, x int32, y int32, flags uint32) error {
1952+ var arg0 wl.Object
1953+ if seat != nil {
1954+ arg0 = seat
1955+ }
1956+ var arg2 wl.Object
1957+ if parent != nil {
1958+ arg2 = parent
1959+ }
1960+ if err := o.Context().SendRequest(o, 6, arg0, serial, arg2, x, y, flags); err != nil {
1961+ return err
1962+ }
1963+ return nil
1964+}
1965+
1966+// Map the surface as a maximized surface. If an output parameter is given then the surface will be maximized on that output. If the client does not specify the output then the compositor will apply its policy - usually choosing the output on which the surface has the biggest surface area. The compositor will reply with a configure event telling the expected new surface size. The operation is completed on the next buffer attach to this surface. A maximized surface typically fills the entire output it is bound to, except for desktop elements such as panels. This is the main difference between a maximized shell surface and a fullscreen shell surface. The details depend on the compositor implementation.
1967+func (o *ShellSurface) SetMaximized(output *Output) error {
1968+ var arg0 wl.Object
1969+ if output != nil {
1970+ arg0 = output
1971+ }
1972+ if err := o.Context().SendRequest(o, 7, arg0); err != nil {
1973+ return err
1974+ }
1975+ return nil
1976+}
1977+
1978+// Set a short title for the surface. This string may be used to identify the surface in a task bar, window list, or other user interface elements provided by the compositor. The string must be encoded in UTF-8.
1979+func (o *ShellSurface) SetTitle(title string) error {
1980+ if err := o.Context().SendRequest(o, 8, title); err != nil {
1981+ return err
1982+ }
1983+ return nil
1984+}
1985+
1986+// Set a class for the surface. The surface class identifies the general class of applications to which the surface belongs. A common convention is to use the file name (or the full path if it is a non-standard location) of the application's .desktop file as the class.
1987+func (o *ShellSurface) SetClass(class string) error {
1988+ if err := o.Context().SendRequest(o, 9, class); err != nil {
1989+ return err
1990+ }
1991+ return nil
1992+}
1993+
1994+// OnPing registers a handler for the ping event.
1995+//
1996+// Handlers are appended, so a second call adds another handler rather than
1997+// replacing the first. Registration is safe while another goroutine dispatches.
1998+func (o *ShellSurface) OnPing(handler func(serial uint32)) {
1999+ if handler == nil {
2000+ return
2001+ }
2002+ o.handlersMu.Lock()
2003+ defer o.handlersMu.Unlock()
2004+ o.onPing = append(o.onPing, handler)
2005+}
2006+
2007+// handlersForPing returns the handlers registered for ping, taken
2008+// under the lock so a handler may register another handler while events are
2009+// being dispatched.
2010+func (o *ShellSurface) handlersForPing() []func(serial uint32) {
2011+ o.handlersMu.Lock()
2012+ defer o.handlersMu.Unlock()
2013+ return o.onPing
2014+}
2015+
2016+// OnConfigure registers a handler for the configure event.
2017+//
2018+// Handlers are appended, so a second call adds another handler rather than
2019+// replacing the first. Registration is safe while another goroutine dispatches.
2020+func (o *ShellSurface) OnConfigure(handler func(edges uint32, width int32, height int32)) {
2021+ if handler == nil {
2022+ return
2023+ }
2024+ o.handlersMu.Lock()
2025+ defer o.handlersMu.Unlock()
2026+ o.onConfigure = append(o.onConfigure, handler)
2027+}
2028+
2029+// handlersForConfigure returns the handlers registered for configure, taken
2030+// under the lock so a handler may register another handler while events are
2031+// being dispatched.
2032+func (o *ShellSurface) handlersForConfigure() []func(edges uint32, width int32, height int32) {
2033+ o.handlersMu.Lock()
2034+ defer o.handlersMu.Unlock()
2035+ return o.onConfigure
2036+}
2037+
2038+// OnPopupDone registers a handler for the popup_done event.
2039+//
2040+// Handlers are appended, so a second call adds another handler rather than
2041+// replacing the first. Registration is safe while another goroutine dispatches.
2042+func (o *ShellSurface) OnPopupDone(handler func()) {
2043+ if handler == nil {
2044+ return
2045+ }
2046+ o.handlersMu.Lock()
2047+ defer o.handlersMu.Unlock()
2048+ o.onPopupDone = append(o.onPopupDone, handler)
2049+}
2050+
2051+// handlersForPopupDone returns the handlers registered for popup_done, taken
2052+// under the lock so a handler may register another handler while events are
2053+// being dispatched.
2054+func (o *ShellSurface) handlersForPopupDone() []func() {
2055+ o.handlersMu.Lock()
2056+ defer o.handlersMu.Unlock()
2057+ return o.onPopupDone
2058+}
2059+
2060+// EventSignature returns the declared event argument types in wire order.
2061+func (o *ShellSurface) EventSignature(opcode uint16) (string, bool) {
2062+ switch opcode {
2063+ case 0:
2064+ return "uint,", true
2065+ case 1:
2066+ return "uint,int,int,", true
2067+ case 2:
2068+ return "", true
2069+ default:
2070+ return "", false
2071+ }
2072+}
2073+
2074+// Dispatch decodes one event on wl_shell_surface and calls the registered handlers.
2075+func (o *ShellSurface) Dispatch(event *wl.Event) {
2076+ switch event.Opcode {
2077+ case 0: // ping
2078+ serial := event.Uint32()
2079+
2080+ for i, handler := range o.handlersForPing() {
2081+ _ = i
2082+ handler(serial)
2083+ }
2084+ case 1: // configure
2085+ edges := event.Uint32()
2086+ width := event.Int32()
2087+ height := event.Int32()
2088+
2089+ for i, handler := range o.handlersForConfigure() {
2090+ _ = i
2091+ handler(edges, width, height)
2092+ }
2093+ case 2: // popup_done
2094+
2095+ for i, handler := range o.handlersForPopupDone() {
2096+ _ = i
2097+ handler()
2098+ }
2099+ default:
2100+ }
2101+}
2102+
2103+// SurfaceInterface is the protocol interface name.
2104+const SurfaceInterface = "wl_surface"
2105+
2106+// Surface is the generated binding for wl_surface version 7.
2107+type Surface struct {
2108+ wl.BaseProxy
2109+ // handlersMu guards the handler slices: a client may register or replace
2110+ // handlers while another goroutine dispatches events.
2111+ handlersMu sync.Mutex
2112+ onEnter []func(outputID uint32)
2113+ onLeave []func(outputID uint32)
2114+ onPreferredBufferScale []func(factor int32)
2115+ onPreferredBufferTransform []func(transform uint32)
2116+}
2117+
2118+// NewSurface returns an unbound Surface.
2119+func NewSurface(ctx *wl.Context) *Surface {
2120+ obj := &Surface{}
2121+ obj.SetContext(ctx)
2122+ ctx.Register(obj)
2123+ return obj
2124+}
2125+
2126+// Deletes the surface and invalidates its object ID.
2127+func (o *Surface) Destroy() error {
2128+ if err := o.Context().SendRequest(o, 0); err != nil {
2129+ return err
2130+ }
2131+ o.Context().Unregister(o)
2132+ return nil
2133+}
2134+
2135+// Set a buffer as the content of this surface. The new size of the surface is calculated based on the buffer size transformed by the inverse buffer_transform and the inverse buffer_scale. This means that at commit time the supplied buffer size must be an integer multiple of the buffer_scale. If that's not the case, an invalid_size error is sent. The x and y arguments specify the location of the new pending buffer's upper left corner, relative to the current buffer's upper left corner, in surface-local coordinates. In other words, the x and y, combined with the new surface size define in which directions the surface's size changes. Setting anything other than 0 as x and y arguments is discouraged, and should instead be replaced with using the separate wl_surface.offset request. When the bound wl_surface version is 5 or higher, passing any non-zero x or y is a protocol violation, and will result in an 'invalid_offset' error being raised. The x and y arguments are ignored and do not change the pending state. To achieve equivalent semantics, use wl_surface.offset. Surface contents are double-buffered state, see wl_surface.commit. The initial surface contents are void; there is no content. wl_surface.attach assigns the given wl_buffer as the pending wl_buffer. wl_surface.commit makes the pending wl_buffer the new surface contents, and the size of the surface becomes the size calculated from the wl_buffer, as described above. After commit, there is no pending buffer until the next attach. Committing a pending wl_buffer allows the compositor to read the pixels in the wl_buffer. The compositor may access the pixels at any time after the wl_surface.commit request. When the compositor will not access the pixels anymore, it will send the wl_buffer.release event. Only after receiving wl_buffer.release, the client may reuse the wl_buffer. A wl_buffer that has been attached and then replaced by another attach instead of committed will not receive a release event, and is not used by the compositor. If a pending wl_buffer has been committed to more than one wl_surface, the delivery of wl_buffer.release events becomes undefined. A well behaved client should not rely on wl_buffer.release events in this case. Instead, clients hitting this case should use wl_surface.get_release or use a protocol extension providing per-commit release notifications (if none of these options are available, a fallback can be implemented by creating multiple wl_buffer objects from the same backing storage). Destroying the wl_buffer after wl_buffer.release does not change the surface contents. Destroying the wl_buffer before wl_buffer.release is allowed as long as the underlying buffer storage isn't re-used (this can happen e.g. on client process termination). However, if the client destroys the wl_buffer before receiving the wl_buffer.release event and mutates the underlying buffer storage, the surface contents become undefined immediately. If wl_surface.attach is sent with a NULL wl_buffer, the following wl_surface.commit will remove the surface content. If a pending wl_buffer has been destroyed, the result is not specified. Many compositors are known to remove the surface content on the following wl_surface.commit, but this behaviour is not universal. Clients seeking to maximise compatibility should not destroy pending buffers and should ensure that they explicitly remove content from surfaces, even after destroying buffers.
2136+func (o *Surface) Attach(buffer *Buffer, x int32, y int32) error {
2137+ var arg0 wl.Object
2138+ if buffer != nil {
2139+ arg0 = buffer
2140+ }
2141+ if err := o.Context().SendRequest(o, 1, arg0, x, y); err != nil {
2142+ return err
2143+ }
2144+ return nil
2145+}
2146+
2147+// This request is used to describe the regions where the pending buffer is different from the current surface contents, and where the surface therefore needs to be repainted. The compositor ignores the parts of the damage that fall outside of the surface. Damage is double-buffered state, see wl_surface.commit. The damage rectangle is specified in surface-local coordinates, where x and y specify the upper left corner of the damage rectangle. The initial value for pending damage is empty: no damage. wl_surface.damage adds pending damage: the new pending damage is the union of old pending damage and the given rectangle. wl_surface.commit assigns pending damage as the current damage, and clears pending damage. The server will clear the current damage as it repaints the surface. Note! New clients should not use this request. Instead damage can be posted with wl_surface.damage_buffer which uses buffer coordinates instead of surface coordinates.
2148+func (o *Surface) Damage(x int32, y int32, width int32, height int32) error {
2149+ if err := o.Context().SendRequest(o, 2, x, y, width, height); err != nil {
2150+ return err
2151+ }
2152+ return nil
2153+}
2154+
2155+// Request a notification when it is a good time to start drawing a new frame, by creating a frame callback. This is useful for throttling redrawing operations, and driving animations. When a client is animating on a wl_surface, it can use the 'frame' request to get notified when it is a good time to draw and commit the next frame of animation. If the client commits an update earlier than that, it is likely that some updates will not make it to the display, and the client is wasting resources by drawing too often. The frame request will take effect on the next wl_surface.commit. The notification will only be posted for one frame unless requested again. For a wl_surface, the notifications are posted in the order the frame requests were committed. The server must send the notifications so that a client will not send excessive updates, while still allowing the highest possible update rate for clients that wait for the reply before drawing again. The server should give some time for the client to draw and commit after sending the frame callback events to let it hit the next output refresh. A server should avoid signaling the frame callbacks if the surface is not visible in any way, e.g. the surface is off-screen, or completely obscured by other opaque surfaces. The object returned by this request will be destroyed by the compositor after the callback is fired and as such the client must not attempt to use it after that point. The callback_data passed in the callback is the current time, in milliseconds, with an undefined base.
2156+func (o *Surface) Frame() (*Callback, error) {
2157+ child := &Callback{}
2158+ child.SetContext(o.Context())
2159+ child.SetID(o.Context().AllocateID())
2160+ o.Context().Register(child)
2161+ if err := o.Context().SendRequest(o, 3, child); err != nil {
2162+ o.Context().Unregister(child)
2163+ return nil, err
2164+ }
2165+ return child, nil
2166+}
2167+
2168+// This request sets the region of the surface that contains opaque content. The opaque region is an optimization hint for the compositor that lets it optimize the redrawing of content behind opaque regions. Setting an opaque region is not required for correct behaviour, but marking transparent content as opaque will result in repaint artifacts. The opaque region is specified in surface-local coordinates. The compositor ignores the parts of the opaque region that fall outside of the surface. Opaque region is double-buffered state, see wl_surface.commit. wl_surface.set_opaque_region changes the pending opaque region. wl_surface.commit copies the pending region to the current region. Otherwise, the pending and current regions are never changed. The initial value for an opaque region is empty. Setting the pending opaque region has copy semantics, and the wl_region object can be destroyed immediately. A NULL wl_region causes the pending opaque region to be set to empty.
2169+func (o *Surface) SetOpaqueRegion(region *Region) error {
2170+ var arg0 wl.Object
2171+ if region != nil {
2172+ arg0 = region
2173+ }
2174+ if err := o.Context().SendRequest(o, 4, arg0); err != nil {
2175+ return err
2176+ }
2177+ return nil
2178+}
2179+
2180+// This request sets the region of the surface that can receive pointer and touch events. Input events happening outside of this region will try the next surface in the server surface stack. The compositor ignores the parts of the input region that fall outside of the surface. The input region is specified in surface-local coordinates. Input region is double-buffered state, see wl_surface.commit. wl_surface.set_input_region changes the pending input region. wl_surface.commit copies the pending region to the current region. Otherwise the pending and current regions are never changed, except cursor and icon surfaces are special cases, see wl_pointer.set_cursor and wl_data_device.start_drag. The initial value for an input region is infinite. That means the whole surface will accept input. Setting the pending input region has copy semantics, and the wl_region object can be destroyed immediately. A NULL wl_region causes the input region to be set to infinite.
2181+func (o *Surface) SetInputRegion(region *Region) error {
2182+ var arg0 wl.Object
2183+ if region != nil {
2184+ arg0 = region
2185+ }
2186+ if err := o.Context().SendRequest(o, 5, arg0); err != nil {
2187+ return err
2188+ }
2189+ return nil
2190+}
2191+
2192+// Surface state (input, opaque, and damage regions, attached buffers, etc.) is double-buffered. Protocol requests modify the pending state, as opposed to the active state in use by the compositor. All requests that need a commit to become effective are documented to affect double-buffered state. Other interfaces may add further double-buffered surface state. A commit request atomically creates a Content Update (CU) from the pending state, even if the pending state has not been touched. The content update is placed at the end of a per-surface queue until it becomes active. After commit, the new pending state is as documented for each related request. A CU is either a Desync Content Update (DCU) or a Sync Content Update (SCU). If the surface is effectively synchronized at the commit request, it is a SCU, otherwise a DCU. When a surface transitions from effectively synchronized to effectively desynchronized, all SCUs in its queue which are not reachable by any DCU become DCUs and dependency edges from outside the queue to these CUs are removed. See wl_subsurface for the definition of 'effectively synchronized' and 'effectively desynchronized'. When a CU is placed in the queue, the CU has a dependency on the CU in front of it and to the SCU at end of the queue of every direct child surface if that SCU exists and does not have another dependent. This can form a directed acyclic graph of CUs with dependencies as edges. In addition to surface state, the CU can have constraints that must be satisfied before it can be applied. Other interfaces may add CU constraints. All DCUs which do not have a SCU in front of themselves in their queue, are candidates. If the graph that's reachable by a candidate does not have any unsatisfied constraints, the entire graph must be applied atomically. When a CU is applied, the wl_buffer is applied before all other state. This means that all coordinates in double-buffered state are relative to the newly attached wl_buffers, except for wl_surface.attach itself. If there is no newly attached wl_buffer, the coordinates are relative to the previous content update.
2193+func (o *Surface) Commit() error {
2194+ if err := o.Context().SendRequest(o, 6); err != nil {
2195+ return err
2196+ }
2197+ return nil
2198+}
2199+
2200+// This request sets the transformation that the client has already applied to the content of the buffer. The accepted values for the transform parameter are the values for wl_output.transform. The compositor applies the inverse of this transformation whenever it uses the buffer contents. Buffer transform is double-buffered state, see wl_surface.commit. A newly created surface has its buffer transformation set to normal. wl_surface.set_buffer_transform changes the pending buffer transformation. wl_surface.commit copies the pending buffer transformation to the current one. Otherwise, the pending and current values are never changed. The purpose of this request is to allow clients to render content according to the output transform, thus permitting the compositor to use certain optimizations even if the display is rotated. Using hardware overlays and scanning out a client buffer for fullscreen surfaces are examples of such optimizations. Those optimizations are highly dependent on the compositor implementation, so the use of this request should be considered on a case-by-case basis. Note that if the transform value includes 90 or 270 degree rotation, the width of the buffer will become the surface height and the height of the buffer will become the surface width. If transform is not one of the values from the wl_output.transform enum the invalid_transform protocol error is raised.
2201+func (o *Surface) SetBufferTransform(transform int32) error {
2202+ if err := o.Context().SendRequest(o, 7, transform); err != nil {
2203+ return err
2204+ }
2205+ return nil
2206+}
2207+
2208+// This request sets an optional scaling factor on how the compositor interprets the contents of the buffer attached to the window. Buffer scale is double-buffered state, see wl_surface.commit. A newly created surface has its buffer scale set to 1. wl_surface.set_buffer_scale changes the pending buffer scale. wl_surface.commit copies the pending buffer scale to the current one. Otherwise, the pending and current values are never changed. The purpose of this request is to allow clients to supply higher resolution buffer data for use on high resolution outputs. It is intended that you pick the same buffer scale as the scale of the output that the surface is displayed on. This means the compositor can avoid scaling when rendering the surface on that output. Note that if the scale is larger than 1, then you have to attach a buffer that is larger (by a factor of scale in each dimension) than the desired surface size. If scale is not greater than 0 the invalid_scale protocol error is raised.
2209+func (o *Surface) SetBufferScale(scale int32) error {
2210+ if err := o.Context().SendRequest(o, 8, scale); err != nil {
2211+ return err
2212+ }
2213+ return nil
2214+}
2215+
2216+// This request is used to describe the regions where the pending buffer is different from the current surface contents, and where the surface therefore needs to be repainted. The compositor ignores the parts of the damage that fall outside of the surface. Damage is double-buffered state, see wl_surface.commit. The damage rectangle is specified in buffer coordinates, where x and y specify the upper left corner of the damage rectangle. The initial value for pending damage is empty: no damage. wl_surface.damage_buffer adds pending damage: the new pending damage is the union of old pending damage and the given rectangle. wl_surface.commit assigns pending damage as the current damage, and clears pending damage. The server will clear the current damage as it repaints the surface. This request differs from wl_surface.damage in only one way - it takes damage in buffer coordinates instead of surface-local coordinates. While this generally is more intuitive than surface coordinates, it is especially desirable when using wp_viewport or when a drawing library (like EGL) is unaware of buffer scale and buffer transform. Note: Because buffer transformation changes and damage requests may be interleaved in the protocol stream, it is impossible to determine the actual mapping between surface and buffer damage until wl_surface.commit time. Therefore, compositors wishing to take both kinds of damage into account will have to accumulate damage from the two requests separately and only transform from one to the other after receiving the wl_surface.commit.
2217+func (o *Surface) DamageBuffer(x int32, y int32, width int32, height int32) error {
2218+ if err := o.Context().SendRequest(o, 9, x, y, width, height); err != nil {
2219+ return err
2220+ }
2221+ return nil
2222+}
2223+
2224+// The x and y arguments specify the location of the new pending buffer's upper left corner, relative to the current buffer's upper left corner, in surface-local coordinates. In other words, the x and y, combined with the new surface size define in which directions the surface's size changes. The exact semantics of wl_surface.offset are role-specific. Refer to the documentation of specific roles for more information. Surface location offset is double-buffered state, see wl_surface.commit. This request is semantically equivalent to and the replaces the x and y arguments in the wl_surface.attach request in wl_surface versions prior to 5. See wl_surface.attach for details.
2225+func (o *Surface) Offset(x int32, y int32) error {
2226+ if err := o.Context().SendRequest(o, 10, x, y); err != nil {
2227+ return err
2228+ }
2229+ return nil
2230+}
2231+
2232+// Create a callback for the release of the buffer attached by the client with wl_surface.attach. The compositor will release the buffer when it has finished its usage of the underlying storage for the relevant commit. Once the client receives this event, and assuming the associated buffer is not pending release from other wl_surface.commit requests, the client can safely re-use the buffer. Release callbacks are double-buffered state, and will be associated with the pending buffer at wl_surface.commit time. The callback_data passed in the wl_callback.done event is unused and is always zero. Sending this request without attaching a non-null buffer in the same content update is a protocol error. The compositor will send the no_buffer error in this case.
2233+func (o *Surface) GetRelease() (*Callback, error) {
2234+ child := &Callback{}
2235+ child.SetContext(o.Context())
2236+ child.SetID(o.Context().AllocateID())
2237+ o.Context().Register(child)
2238+ if err := o.Context().SendRequest(o, 11, child); err != nil {
2239+ o.Context().Unregister(child)
2240+ return nil, err
2241+ }
2242+ return child, nil
2243+}
2244+
2245+// OnEnter registers a handler for the enter event.
2246+//
2247+// Handlers are appended, so a second call adds another handler rather than
2248+// replacing the first. Registration is safe while another goroutine dispatches.
2249+func (o *Surface) OnEnter(handler func(outputID uint32)) {
2250+ if handler == nil {
2251+ return
2252+ }
2253+ o.handlersMu.Lock()
2254+ defer o.handlersMu.Unlock()
2255+ o.onEnter = append(o.onEnter, handler)
2256+}
2257+
2258+// handlersForEnter returns the handlers registered for enter, taken
2259+// under the lock so a handler may register another handler while events are
2260+// being dispatched.
2261+func (o *Surface) handlersForEnter() []func(outputID uint32) {
2262+ o.handlersMu.Lock()
2263+ defer o.handlersMu.Unlock()
2264+ return o.onEnter
2265+}
2266+
2267+// OnLeave registers a handler for the leave event.
2268+//
2269+// Handlers are appended, so a second call adds another handler rather than
2270+// replacing the first. Registration is safe while another goroutine dispatches.
2271+func (o *Surface) OnLeave(handler func(outputID uint32)) {
2272+ if handler == nil {
2273+ return
2274+ }
2275+ o.handlersMu.Lock()
2276+ defer o.handlersMu.Unlock()
2277+ o.onLeave = append(o.onLeave, handler)
2278+}
2279+
2280+// handlersForLeave returns the handlers registered for leave, taken
2281+// under the lock so a handler may register another handler while events are
2282+// being dispatched.
2283+func (o *Surface) handlersForLeave() []func(outputID uint32) {
2284+ o.handlersMu.Lock()
2285+ defer o.handlersMu.Unlock()
2286+ return o.onLeave
2287+}
2288+
2289+// OnPreferredBufferScale registers a handler for the preferred_buffer_scale event.
2290+//
2291+// Handlers are appended, so a second call adds another handler rather than
2292+// replacing the first. Registration is safe while another goroutine dispatches.
2293+func (o *Surface) OnPreferredBufferScale(handler func(factor int32)) {
2294+ if handler == nil {
2295+ return
2296+ }
2297+ o.handlersMu.Lock()
2298+ defer o.handlersMu.Unlock()
2299+ o.onPreferredBufferScale = append(o.onPreferredBufferScale, handler)
2300+}
2301+
2302+// handlersForPreferredBufferScale returns the handlers registered for preferred_buffer_scale, taken
2303+// under the lock so a handler may register another handler while events are
2304+// being dispatched.
2305+func (o *Surface) handlersForPreferredBufferScale() []func(factor int32) {
2306+ o.handlersMu.Lock()
2307+ defer o.handlersMu.Unlock()
2308+ return o.onPreferredBufferScale
2309+}
2310+
2311+// OnPreferredBufferTransform registers a handler for the preferred_buffer_transform event.
2312+//
2313+// Handlers are appended, so a second call adds another handler rather than
2314+// replacing the first. Registration is safe while another goroutine dispatches.
2315+func (o *Surface) OnPreferredBufferTransform(handler func(transform uint32)) {
2316+ if handler == nil {
2317+ return
2318+ }
2319+ o.handlersMu.Lock()
2320+ defer o.handlersMu.Unlock()
2321+ o.onPreferredBufferTransform = append(o.onPreferredBufferTransform, handler)
2322+}
2323+
2324+// handlersForPreferredBufferTransform returns the handlers registered for preferred_buffer_transform, taken
2325+// under the lock so a handler may register another handler while events are
2326+// being dispatched.
2327+func (o *Surface) handlersForPreferredBufferTransform() []func(transform uint32) {
2328+ o.handlersMu.Lock()
2329+ defer o.handlersMu.Unlock()
2330+ return o.onPreferredBufferTransform
2331+}
2332+
2333+// EventSignature returns the declared event argument types in wire order.
2334+func (o *Surface) EventSignature(opcode uint16) (string, bool) {
2335+ switch opcode {
2336+ case 0:
2337+ return "object,", true
2338+ case 1:
2339+ return "object,", true
2340+ case 2:
2341+ return "int,", true
2342+ case 3:
2343+ return "uint,", true
2344+ default:
2345+ return "", false
2346+ }
2347+}
2348+
2349+// Dispatch decodes one event on wl_surface and calls the registered handlers.
2350+func (o *Surface) Dispatch(event *wl.Event) {
2351+ switch event.Opcode {
2352+ case 0: // enter
2353+ outputID := event.Uint32()
2354+
2355+ for i, handler := range o.handlersForEnter() {
2356+ _ = i
2357+ handler(outputID)
2358+ }
2359+ case 1: // leave
2360+ outputID := event.Uint32()
2361+
2362+ for i, handler := range o.handlersForLeave() {
2363+ _ = i
2364+ handler(outputID)
2365+ }
2366+ case 2: // preferred_buffer_scale
2367+ factor := event.Int32()
2368+
2369+ for i, handler := range o.handlersForPreferredBufferScale() {
2370+ _ = i
2371+ handler(factor)
2372+ }
2373+ case 3: // preferred_buffer_transform
2374+ transform := event.Uint32()
2375+
2376+ for i, handler := range o.handlersForPreferredBufferTransform() {
2377+ _ = i
2378+ handler(transform)
2379+ }
2380+ default:
2381+ }
2382+}
2383+
2384+// SeatInterface is the protocol interface name.
2385+const SeatInterface = "wl_seat"
2386+
2387+// Seat is the generated binding for wl_seat version 11.
2388+type Seat struct {
2389+ wl.BaseProxy
2390+ // handlersMu guards the handler slices: a client may register or replace
2391+ // handlers while another goroutine dispatches events.
2392+ handlersMu sync.Mutex
2393+ onCapabilities []func(capabilities uint32)
2394+ onName []func(name string)
2395+}
2396+
2397+// NewSeat returns an unbound Seat.
2398+func NewSeat(ctx *wl.Context) *Seat {
2399+ obj := &Seat{}
2400+ obj.SetContext(ctx)
2401+ ctx.Register(obj)
2402+ return obj
2403+}
2404+
2405+// The ID provided will be initialized to the wl_pointer interface for this seat. This request only takes effect if the seat has the pointer capability, or has had the pointer capability in the past. It is a protocol violation to issue this request on a seat that has never had the pointer capability. The missing_capability error will be sent in this case.
2406+func (o *Seat) GetPointer() (*Pointer, error) {
2407+ child := &Pointer{}
2408+ child.SetContext(o.Context())
2409+ child.SetID(o.Context().AllocateID())
2410+ o.Context().Register(child)
2411+ if err := o.Context().SendRequest(o, 0, child); err != nil {
2412+ o.Context().Unregister(child)
2413+ return nil, err
2414+ }
2415+ return child, nil
2416+}
2417+
2418+// The ID provided will be initialized to the wl_keyboard interface for this seat. This request only takes effect if the seat has the keyboard capability, or has had the keyboard capability in the past. It is a protocol violation to issue this request on a seat that has never had the keyboard capability. The missing_capability error will be sent in this case.
2419+func (o *Seat) GetKeyboard() (*Keyboard, error) {
2420+ child := &Keyboard{}
2421+ child.SetContext(o.Context())
2422+ child.SetID(o.Context().AllocateID())
2423+ o.Context().Register(child)
2424+ if err := o.Context().SendRequest(o, 1, child); err != nil {
2425+ o.Context().Unregister(child)
2426+ return nil, err
2427+ }
2428+ return child, nil
2429+}
2430+
2431+// The ID provided will be initialized to the wl_touch interface for this seat. This request only takes effect if the seat has the touch capability, or has had the touch capability in the past. It is a protocol violation to issue this request on a seat that has never had the touch capability. The missing_capability error will be sent in this case.
2432+func (o *Seat) GetTouch() (*Touch, error) {
2433+ child := &Touch{}
2434+ child.SetContext(o.Context())
2435+ child.SetID(o.Context().AllocateID())
2436+ o.Context().Register(child)
2437+ if err := o.Context().SendRequest(o, 2, child); err != nil {
2438+ o.Context().Unregister(child)
2439+ return nil, err
2440+ }
2441+ return child, nil
2442+}
2443+
2444+// Using this request a client can tell the server that it is not going to use the seat object anymore.
2445+func (o *Seat) Release() error {
2446+ if err := o.Context().SendRequest(o, 3); err != nil {
2447+ return err
2448+ }
2449+ o.Context().Unregister(o)
2450+ return nil
2451+}
2452+
2453+// OnCapabilities registers a handler for the capabilities event.
2454+//
2455+// Handlers are appended, so a second call adds another handler rather than
2456+// replacing the first. Registration is safe while another goroutine dispatches.
2457+func (o *Seat) OnCapabilities(handler func(capabilities uint32)) {
2458+ if handler == nil {
2459+ return
2460+ }
2461+ o.handlersMu.Lock()
2462+ defer o.handlersMu.Unlock()
2463+ o.onCapabilities = append(o.onCapabilities, handler)
2464+}
2465+
2466+// handlersForCapabilities returns the handlers registered for capabilities, taken
2467+// under the lock so a handler may register another handler while events are
2468+// being dispatched.
2469+func (o *Seat) handlersForCapabilities() []func(capabilities uint32) {
2470+ o.handlersMu.Lock()
2471+ defer o.handlersMu.Unlock()
2472+ return o.onCapabilities
2473+}
2474+
2475+// OnName registers a handler for the name event.
2476+//
2477+// Handlers are appended, so a second call adds another handler rather than
2478+// replacing the first. Registration is safe while another goroutine dispatches.
2479+func (o *Seat) OnName(handler func(name string)) {
2480+ if handler == nil {
2481+ return
2482+ }
2483+ o.handlersMu.Lock()
2484+ defer o.handlersMu.Unlock()
2485+ o.onName = append(o.onName, handler)
2486+}
2487+
2488+// handlersForName returns the handlers registered for name, taken
2489+// under the lock so a handler may register another handler while events are
2490+// being dispatched.
2491+func (o *Seat) handlersForName() []func(name string) {
2492+ o.handlersMu.Lock()
2493+ defer o.handlersMu.Unlock()
2494+ return o.onName
2495+}
2496+
2497+// EventSignature returns the declared event argument types in wire order.
2498+func (o *Seat) EventSignature(opcode uint16) (string, bool) {
2499+ switch opcode {
2500+ case 0:
2501+ return "uint,", true
2502+ case 1:
2503+ return "string,", true
2504+ default:
2505+ return "", false
2506+ }
2507+}
2508+
2509+// Dispatch decodes one event on wl_seat and calls the registered handlers.
2510+func (o *Seat) Dispatch(event *wl.Event) {
2511+ switch event.Opcode {
2512+ case 0: // capabilities
2513+ capabilities := event.Uint32()
2514+
2515+ for i, handler := range o.handlersForCapabilities() {
2516+ _ = i
2517+ handler(capabilities)
2518+ }
2519+ case 1: // name
2520+ name := event.String()
2521+
2522+ for i, handler := range o.handlersForName() {
2523+ _ = i
2524+ handler(name)
2525+ }
2526+ default:
2527+ }
2528+}
2529+
2530+// PointerInterface is the protocol interface name.
2531+const PointerInterface = "wl_pointer"
2532+
2533+// Pointer is the generated binding for wl_pointer version 11.
2534+type Pointer struct {
2535+ wl.BaseProxy
2536+ // handlersMu guards the handler slices: a client may register or replace
2537+ // handlers while another goroutine dispatches events.
2538+ handlersMu sync.Mutex
2539+ onEnter []func(serial uint32, surfaceID uint32, surfaceX wl.Fixed, surfaceY wl.Fixed)
2540+ onLeave []func(serial uint32, surfaceID uint32)
2541+ onMotion []func(time uint32, surfaceX wl.Fixed, surfaceY wl.Fixed)
2542+ onButton []func(serial uint32, time uint32, button uint32, state uint32)
2543+ onAxis []func(time uint32, axis uint32, value wl.Fixed)
2544+ onFrame []func()
2545+ onAxisSource []func(axisSource uint32)
2546+ onAxisStop []func(time uint32, axis uint32)
2547+ onAxisDiscrete []func(axis uint32, discrete int32)
2548+ onAxisValue120 []func(axis uint32, value120 int32)
2549+ onAxisRelativeDirection []func(axis uint32, direction uint32)
2550+ onWarp []func(surfaceX wl.Fixed, surfaceY wl.Fixed)
2551+}
2552+
2553+// NewPointer returns an unbound Pointer.
2554+func NewPointer(ctx *wl.Context) *Pointer {
2555+ obj := &Pointer{}
2556+ obj.SetContext(ctx)
2557+ ctx.Register(obj)
2558+ return obj
2559+}
2560+
2561+// Set the pointer surface, i.e., the surface that contains the pointer image (cursor). This request gives the surface the role of a cursor. If the surface already has another role, it raises a protocol error. The cursor actually changes only if the pointer focus for this device is one of the requesting client's surfaces or the surface parameter is the current pointer surface. If there was a previous surface set with this request it is replaced. If surface is NULL, the pointer image is hidden. The parameters hotspot_x and hotspot_y define the position of the pointer surface relative to the pointer location. Its top-left corner is always at (x, y) - (hotspot_x, hotspot_y), where (x, y) are the coordinates of the pointer location, in surface-local coordinates. On wl_surface.offset requests to the pointer surface, hotspot_x and hotspot_y are decremented by the x and y parameters passed to the request. The offset must be applied by wl_surface.commit as usual. The hotspot can also be updated by passing the currently set pointer surface to this request with new values for hotspot_x and hotspot_y. The input region is ignored for wl_surfaces with the role of a cursor. When the use as a cursor ends, the wl_surface is unmapped. The serial parameter must match the latest wl_pointer.enter serial number sent to the client. Otherwise the request will be ignored.
2562+func (o *Pointer) SetCursor(serial uint32, surface *Surface, hotspotX int32, hotspotY int32) error {
2563+ var arg1 wl.Object
2564+ if surface != nil {
2565+ arg1 = surface
2566+ }
2567+ if err := o.Context().SendRequest(o, 0, serial, arg1, hotspotX, hotspotY); err != nil {
2568+ return err
2569+ }
2570+ return nil
2571+}
2572+
2573+// Using this request a client can tell the server that it is not going to use the pointer object anymore. This request destroys the pointer proxy object, so clients must not call wl_pointer_destroy() after using this request.
2574+func (o *Pointer) Release() error {
2575+ if err := o.Context().SendRequest(o, 1); err != nil {
2576+ return err
2577+ }
2578+ o.Context().Unregister(o)
2579+ return nil
2580+}
2581+
2582+// OnEnter registers a handler for the enter event.
2583+//
2584+// Handlers are appended, so a second call adds another handler rather than
2585+// replacing the first. Registration is safe while another goroutine dispatches.
2586+func (o *Pointer) OnEnter(handler func(serial uint32, surfaceID uint32, surfaceX wl.Fixed, surfaceY wl.Fixed)) {
2587+ if handler == nil {
2588+ return
2589+ }
2590+ o.handlersMu.Lock()
2591+ defer o.handlersMu.Unlock()
2592+ o.onEnter = append(o.onEnter, handler)
2593+}
2594+
2595+// handlersForEnter returns the handlers registered for enter, taken
2596+// under the lock so a handler may register another handler while events are
2597+// being dispatched.
2598+func (o *Pointer) handlersForEnter() []func(serial uint32, surfaceID uint32, surfaceX wl.Fixed, surfaceY wl.Fixed) {
2599+ o.handlersMu.Lock()
2600+ defer o.handlersMu.Unlock()
2601+ return o.onEnter
2602+}
2603+
2604+// OnLeave registers a handler for the leave event.
2605+//
2606+// Handlers are appended, so a second call adds another handler rather than
2607+// replacing the first. Registration is safe while another goroutine dispatches.
2608+func (o *Pointer) OnLeave(handler func(serial uint32, surfaceID uint32)) {
2609+ if handler == nil {
2610+ return
2611+ }
2612+ o.handlersMu.Lock()
2613+ defer o.handlersMu.Unlock()
2614+ o.onLeave = append(o.onLeave, handler)
2615+}
2616+
2617+// handlersForLeave returns the handlers registered for leave, taken
2618+// under the lock so a handler may register another handler while events are
2619+// being dispatched.
2620+func (o *Pointer) handlersForLeave() []func(serial uint32, surfaceID uint32) {
2621+ o.handlersMu.Lock()
2622+ defer o.handlersMu.Unlock()
2623+ return o.onLeave
2624+}
2625+
2626+// OnMotion registers a handler for the motion event.
2627+//
2628+// Handlers are appended, so a second call adds another handler rather than
2629+// replacing the first. Registration is safe while another goroutine dispatches.
2630+func (o *Pointer) OnMotion(handler func(time uint32, surfaceX wl.Fixed, surfaceY wl.Fixed)) {
2631+ if handler == nil {
2632+ return
2633+ }
2634+ o.handlersMu.Lock()
2635+ defer o.handlersMu.Unlock()
2636+ o.onMotion = append(o.onMotion, handler)
2637+}
2638+
2639+// handlersForMotion returns the handlers registered for motion, taken
2640+// under the lock so a handler may register another handler while events are
2641+// being dispatched.
2642+func (o *Pointer) handlersForMotion() []func(time uint32, surfaceX wl.Fixed, surfaceY wl.Fixed) {
2643+ o.handlersMu.Lock()
2644+ defer o.handlersMu.Unlock()
2645+ return o.onMotion
2646+}
2647+
2648+// OnButton registers a handler for the button event.
2649+//
2650+// Handlers are appended, so a second call adds another handler rather than
2651+// replacing the first. Registration is safe while another goroutine dispatches.
2652+func (o *Pointer) OnButton(handler func(serial uint32, time uint32, button uint32, state uint32)) {
2653+ if handler == nil {
2654+ return
2655+ }
2656+ o.handlersMu.Lock()
2657+ defer o.handlersMu.Unlock()
2658+ o.onButton = append(o.onButton, handler)
2659+}
2660+
2661+// handlersForButton returns the handlers registered for button, taken
2662+// under the lock so a handler may register another handler while events are
2663+// being dispatched.
2664+func (o *Pointer) handlersForButton() []func(serial uint32, time uint32, button uint32, state uint32) {
2665+ o.handlersMu.Lock()
2666+ defer o.handlersMu.Unlock()
2667+ return o.onButton
2668+}
2669+
2670+// OnAxis registers a handler for the axis event.
2671+//
2672+// Handlers are appended, so a second call adds another handler rather than
2673+// replacing the first. Registration is safe while another goroutine dispatches.
2674+func (o *Pointer) OnAxis(handler func(time uint32, axis uint32, value wl.Fixed)) {
2675+ if handler == nil {
2676+ return
2677+ }
2678+ o.handlersMu.Lock()
2679+ defer o.handlersMu.Unlock()
2680+ o.onAxis = append(o.onAxis, handler)
2681+}
2682+
2683+// handlersForAxis returns the handlers registered for axis, taken
2684+// under the lock so a handler may register another handler while events are
2685+// being dispatched.
2686+func (o *Pointer) handlersForAxis() []func(time uint32, axis uint32, value wl.Fixed) {
2687+ o.handlersMu.Lock()
2688+ defer o.handlersMu.Unlock()
2689+ return o.onAxis
2690+}
2691+
2692+// OnFrame registers a handler for the frame event.
2693+//
2694+// Handlers are appended, so a second call adds another handler rather than
2695+// replacing the first. Registration is safe while another goroutine dispatches.
2696+func (o *Pointer) OnFrame(handler func()) {
2697+ if handler == nil {
2698+ return
2699+ }
2700+ o.handlersMu.Lock()
2701+ defer o.handlersMu.Unlock()
2702+ o.onFrame = append(o.onFrame, handler)
2703+}
2704+
2705+// handlersForFrame returns the handlers registered for frame, taken
2706+// under the lock so a handler may register another handler while events are
2707+// being dispatched.
2708+func (o *Pointer) handlersForFrame() []func() {
2709+ o.handlersMu.Lock()
2710+ defer o.handlersMu.Unlock()
2711+ return o.onFrame
2712+}
2713+
2714+// OnAxisSource registers a handler for the axis_source event.
2715+//
2716+// Handlers are appended, so a second call adds another handler rather than
2717+// replacing the first. Registration is safe while another goroutine dispatches.
2718+func (o *Pointer) OnAxisSource(handler func(axisSource uint32)) {
2719+ if handler == nil {
2720+ return
2721+ }
2722+ o.handlersMu.Lock()
2723+ defer o.handlersMu.Unlock()
2724+ o.onAxisSource = append(o.onAxisSource, handler)
2725+}
2726+
2727+// handlersForAxisSource returns the handlers registered for axis_source, taken
2728+// under the lock so a handler may register another handler while events are
2729+// being dispatched.
2730+func (o *Pointer) handlersForAxisSource() []func(axisSource uint32) {
2731+ o.handlersMu.Lock()
2732+ defer o.handlersMu.Unlock()
2733+ return o.onAxisSource
2734+}
2735+
2736+// OnAxisStop registers a handler for the axis_stop event.
2737+//
2738+// Handlers are appended, so a second call adds another handler rather than
2739+// replacing the first. Registration is safe while another goroutine dispatches.
2740+func (o *Pointer) OnAxisStop(handler func(time uint32, axis uint32)) {
2741+ if handler == nil {
2742+ return
2743+ }
2744+ o.handlersMu.Lock()
2745+ defer o.handlersMu.Unlock()
2746+ o.onAxisStop = append(o.onAxisStop, handler)
2747+}
2748+
2749+// handlersForAxisStop returns the handlers registered for axis_stop, taken
2750+// under the lock so a handler may register another handler while events are
2751+// being dispatched.
2752+func (o *Pointer) handlersForAxisStop() []func(time uint32, axis uint32) {
2753+ o.handlersMu.Lock()
2754+ defer o.handlersMu.Unlock()
2755+ return o.onAxisStop
2756+}
2757+
2758+// OnAxisDiscrete registers a handler for the axis_discrete event.
2759+//
2760+// Handlers are appended, so a second call adds another handler rather than
2761+// replacing the first. Registration is safe while another goroutine dispatches.
2762+func (o *Pointer) OnAxisDiscrete(handler func(axis uint32, discrete int32)) {
2763+ if handler == nil {
2764+ return
2765+ }
2766+ o.handlersMu.Lock()
2767+ defer o.handlersMu.Unlock()
2768+ o.onAxisDiscrete = append(o.onAxisDiscrete, handler)
2769+}
2770+
2771+// handlersForAxisDiscrete returns the handlers registered for axis_discrete, taken
2772+// under the lock so a handler may register another handler while events are
2773+// being dispatched.
2774+func (o *Pointer) handlersForAxisDiscrete() []func(axis uint32, discrete int32) {
2775+ o.handlersMu.Lock()
2776+ defer o.handlersMu.Unlock()
2777+ return o.onAxisDiscrete
2778+}
2779+
2780+// OnAxisValue120 registers a handler for the axis_value120 event.
2781+//
2782+// Handlers are appended, so a second call adds another handler rather than
2783+// replacing the first. Registration is safe while another goroutine dispatches.
2784+func (o *Pointer) OnAxisValue120(handler func(axis uint32, value120 int32)) {
2785+ if handler == nil {
2786+ return
2787+ }
2788+ o.handlersMu.Lock()
2789+ defer o.handlersMu.Unlock()
2790+ o.onAxisValue120 = append(o.onAxisValue120, handler)
2791+}
2792+
2793+// handlersForAxisValue120 returns the handlers registered for axis_value120, taken
2794+// under the lock so a handler may register another handler while events are
2795+// being dispatched.
2796+func (o *Pointer) handlersForAxisValue120() []func(axis uint32, value120 int32) {
2797+ o.handlersMu.Lock()
2798+ defer o.handlersMu.Unlock()
2799+ return o.onAxisValue120
2800+}
2801+
2802+// OnAxisRelativeDirection registers a handler for the axis_relative_direction event.
2803+//
2804+// Handlers are appended, so a second call adds another handler rather than
2805+// replacing the first. Registration is safe while another goroutine dispatches.
2806+func (o *Pointer) OnAxisRelativeDirection(handler func(axis uint32, direction uint32)) {
2807+ if handler == nil {
2808+ return
2809+ }
2810+ o.handlersMu.Lock()
2811+ defer o.handlersMu.Unlock()
2812+ o.onAxisRelativeDirection = append(o.onAxisRelativeDirection, handler)
2813+}
2814+
2815+// handlersForAxisRelativeDirection returns the handlers registered for axis_relative_direction, taken
2816+// under the lock so a handler may register another handler while events are
2817+// being dispatched.
2818+func (o *Pointer) handlersForAxisRelativeDirection() []func(axis uint32, direction uint32) {
2819+ o.handlersMu.Lock()
2820+ defer o.handlersMu.Unlock()
2821+ return o.onAxisRelativeDirection
2822+}
2823+
2824+// OnWarp registers a handler for the warp event.
2825+//
2826+// Handlers are appended, so a second call adds another handler rather than
2827+// replacing the first. Registration is safe while another goroutine dispatches.
2828+func (o *Pointer) OnWarp(handler func(surfaceX wl.Fixed, surfaceY wl.Fixed)) {
2829+ if handler == nil {
2830+ return
2831+ }
2832+ o.handlersMu.Lock()
2833+ defer o.handlersMu.Unlock()
2834+ o.onWarp = append(o.onWarp, handler)
2835+}
2836+
2837+// handlersForWarp returns the handlers registered for warp, taken
2838+// under the lock so a handler may register another handler while events are
2839+// being dispatched.
2840+func (o *Pointer) handlersForWarp() []func(surfaceX wl.Fixed, surfaceY wl.Fixed) {
2841+ o.handlersMu.Lock()
2842+ defer o.handlersMu.Unlock()
2843+ return o.onWarp
2844+}
2845+
2846+// EventSignature returns the declared event argument types in wire order.
2847+func (o *Pointer) EventSignature(opcode uint16) (string, bool) {
2848+ switch opcode {
2849+ case 0:
2850+ return "uint,object,fixed,fixed,", true
2851+ case 1:
2852+ return "uint,object,", true
2853+ case 2:
2854+ return "uint,fixed,fixed,", true
2855+ case 3:
2856+ return "uint,uint,uint,uint,", true
2857+ case 4:
2858+ return "uint,uint,fixed,", true
2859+ case 5:
2860+ return "", true
2861+ case 6:
2862+ return "uint,", true
2863+ case 7:
2864+ return "uint,uint,", true
2865+ case 8:
2866+ return "uint,int,", true
2867+ case 9:
2868+ return "uint,int,", true
2869+ case 10:
2870+ return "uint,uint,", true
2871+ case 11:
2872+ return "fixed,fixed,", true
2873+ default:
2874+ return "", false
2875+ }
2876+}
2877+
2878+// Dispatch decodes one event on wl_pointer and calls the registered handlers.
2879+func (o *Pointer) Dispatch(event *wl.Event) {
2880+ switch event.Opcode {
2881+ case 0: // enter
2882+ serial := event.Uint32()
2883+ surfaceID := event.Uint32()
2884+ surfaceX := event.Fixed()
2885+ surfaceY := event.Fixed()
2886+
2887+ for i, handler := range o.handlersForEnter() {
2888+ _ = i
2889+ handler(serial, surfaceID, surfaceX, surfaceY)
2890+ }
2891+ case 1: // leave
2892+ serial := event.Uint32()
2893+ surfaceID := event.Uint32()
2894+
2895+ for i, handler := range o.handlersForLeave() {
2896+ _ = i
2897+ handler(serial, surfaceID)
2898+ }
2899+ case 2: // motion
2900+ time := event.Uint32()
2901+ surfaceX := event.Fixed()
2902+ surfaceY := event.Fixed()
2903+
2904+ for i, handler := range o.handlersForMotion() {
2905+ _ = i
2906+ handler(time, surfaceX, surfaceY)
2907+ }
2908+ case 3: // button
2909+ serial := event.Uint32()
2910+ time := event.Uint32()
2911+ button := event.Uint32()
2912+ state := event.Uint32()
2913+
2914+ for i, handler := range o.handlersForButton() {
2915+ _ = i
2916+ handler(serial, time, button, state)
2917+ }
2918+ case 4: // axis
2919+ time := event.Uint32()
2920+ axis := event.Uint32()
2921+ value := event.Fixed()
2922+
2923+ for i, handler := range o.handlersForAxis() {
2924+ _ = i
2925+ handler(time, axis, value)
2926+ }
2927+ case 5: // frame
2928+
2929+ for i, handler := range o.handlersForFrame() {
2930+ _ = i
2931+ handler()
2932+ }
2933+ case 6: // axis_source
2934+ axisSource := event.Uint32()
2935+
2936+ for i, handler := range o.handlersForAxisSource() {
2937+ _ = i
2938+ handler(axisSource)
2939+ }
2940+ case 7: // axis_stop
2941+ time := event.Uint32()
2942+ axis := event.Uint32()
2943+
2944+ for i, handler := range o.handlersForAxisStop() {
2945+ _ = i
2946+ handler(time, axis)
2947+ }
2948+ case 8: // axis_discrete
2949+ axis := event.Uint32()
2950+ discrete := event.Int32()
2951+
2952+ for i, handler := range o.handlersForAxisDiscrete() {
2953+ _ = i
2954+ handler(axis, discrete)
2955+ }
2956+ case 9: // axis_value120
2957+ axis := event.Uint32()
2958+ value120 := event.Int32()
2959+
2960+ for i, handler := range o.handlersForAxisValue120() {
2961+ _ = i
2962+ handler(axis, value120)
2963+ }
2964+ case 10: // axis_relative_direction
2965+ axis := event.Uint32()
2966+ direction := event.Uint32()
2967+
2968+ for i, handler := range o.handlersForAxisRelativeDirection() {
2969+ _ = i
2970+ handler(axis, direction)
2971+ }
2972+ case 11: // warp
2973+ surfaceX := event.Fixed()
2974+ surfaceY := event.Fixed()
2975+
2976+ for i, handler := range o.handlersForWarp() {
2977+ _ = i
2978+ handler(surfaceX, surfaceY)
2979+ }
2980+ default:
2981+ }
2982+}
2983+
2984+// KeyboardInterface is the protocol interface name.
2985+const KeyboardInterface = "wl_keyboard"
2986+
2987+// Keyboard is the generated binding for wl_keyboard version 11.
2988+type Keyboard struct {
2989+ wl.BaseProxy
2990+ // handlersMu guards the handler slices: a client may register or replace
2991+ // handlers while another goroutine dispatches events.
2992+ handlersMu sync.Mutex
2993+ onKeymap []func(format uint32, fd *wl.OwnedFD, size uint32)
2994+ onEnter []func(serial uint32, surfaceID uint32, keys []byte)
2995+ onLeave []func(serial uint32, surfaceID uint32)
2996+ onKey []func(serial uint32, time uint32, key uint32, state uint32)
2997+ onModifiers []func(serial uint32, modsDepressed uint32, modsLatched uint32, modsLocked uint32, group uint32)
2998+ onRepeatInfo []func(rate int32, delay int32)
2999+}
3000+
3001+// NewKeyboard returns an unbound Keyboard.
3002+func NewKeyboard(ctx *wl.Context) *Keyboard {
3003+ obj := &Keyboard{}
3004+ obj.SetContext(ctx)
3005+ ctx.Register(obj)
3006+ return obj
3007+}
3008+
3009+// release the keyboard object
3010+func (o *Keyboard) Release() error {
3011+ if err := o.Context().SendRequest(o, 0); err != nil {
3012+ return err
3013+ }
3014+ o.Context().Unregister(o)
3015+ return nil
3016+}
3017+
3018+// OnKeymap registers a handler for the keymap event.
3019+//
3020+// Handlers are appended, so a second call adds another handler rather than
3021+// replacing the first. Registration is safe while another goroutine dispatches.
3022+func (o *Keyboard) OnKeymap(handler func(format uint32, fd *wl.OwnedFD, size uint32)) {
3023+ if handler == nil {
3024+ return
3025+ }
3026+ o.handlersMu.Lock()
3027+ defer o.handlersMu.Unlock()
3028+ o.onKeymap = append(o.onKeymap, handler)
3029+}
3030+
3031+// handlersForKeymap returns the handlers registered for keymap, taken
3032+// under the lock so a handler may register another handler while events are
3033+// being dispatched.
3034+func (o *Keyboard) handlersForKeymap() []func(format uint32, fd *wl.OwnedFD, size uint32) {
3035+ o.handlersMu.Lock()
3036+ defer o.handlersMu.Unlock()
3037+ return o.onKeymap
3038+}
3039+
3040+// OnEnter registers a handler for the enter event.
3041+//
3042+// Handlers are appended, so a second call adds another handler rather than
3043+// replacing the first. Registration is safe while another goroutine dispatches.
3044+func (o *Keyboard) OnEnter(handler func(serial uint32, surfaceID uint32, keys []byte)) {
3045+ if handler == nil {
3046+ return
3047+ }
3048+ o.handlersMu.Lock()
3049+ defer o.handlersMu.Unlock()
3050+ o.onEnter = append(o.onEnter, handler)
3051+}
3052+
3053+// handlersForEnter returns the handlers registered for enter, taken
3054+// under the lock so a handler may register another handler while events are
3055+// being dispatched.
3056+func (o *Keyboard) handlersForEnter() []func(serial uint32, surfaceID uint32, keys []byte) {
3057+ o.handlersMu.Lock()
3058+ defer o.handlersMu.Unlock()
3059+ return o.onEnter
3060+}
3061+
3062+// OnLeave registers a handler for the leave event.
3063+//
3064+// Handlers are appended, so a second call adds another handler rather than
3065+// replacing the first. Registration is safe while another goroutine dispatches.
3066+func (o *Keyboard) OnLeave(handler func(serial uint32, surfaceID uint32)) {
3067+ if handler == nil {
3068+ return
3069+ }
3070+ o.handlersMu.Lock()
3071+ defer o.handlersMu.Unlock()
3072+ o.onLeave = append(o.onLeave, handler)
3073+}
3074+
3075+// handlersForLeave returns the handlers registered for leave, taken
3076+// under the lock so a handler may register another handler while events are
3077+// being dispatched.
3078+func (o *Keyboard) handlersForLeave() []func(serial uint32, surfaceID uint32) {
3079+ o.handlersMu.Lock()
3080+ defer o.handlersMu.Unlock()
3081+ return o.onLeave
3082+}
3083+
3084+// OnKey registers a handler for the key event.
3085+//
3086+// Handlers are appended, so a second call adds another handler rather than
3087+// replacing the first. Registration is safe while another goroutine dispatches.
3088+func (o *Keyboard) OnKey(handler func(serial uint32, time uint32, key uint32, state uint32)) {
3089+ if handler == nil {
3090+ return
3091+ }
3092+ o.handlersMu.Lock()
3093+ defer o.handlersMu.Unlock()
3094+ o.onKey = append(o.onKey, handler)
3095+}
3096+
3097+// handlersForKey returns the handlers registered for key, taken
3098+// under the lock so a handler may register another handler while events are
3099+// being dispatched.
3100+func (o *Keyboard) handlersForKey() []func(serial uint32, time uint32, key uint32, state uint32) {
3101+ o.handlersMu.Lock()
3102+ defer o.handlersMu.Unlock()
3103+ return o.onKey
3104+}
3105+
3106+// OnModifiers registers a handler for the modifiers event.
3107+//
3108+// Handlers are appended, so a second call adds another handler rather than
3109+// replacing the first. Registration is safe while another goroutine dispatches.
3110+func (o *Keyboard) OnModifiers(handler func(serial uint32, modsDepressed uint32, modsLatched uint32, modsLocked uint32, group uint32)) {
3111+ if handler == nil {
3112+ return
3113+ }
3114+ o.handlersMu.Lock()
3115+ defer o.handlersMu.Unlock()
3116+ o.onModifiers = append(o.onModifiers, handler)
3117+}
3118+
3119+// handlersForModifiers returns the handlers registered for modifiers, taken
3120+// under the lock so a handler may register another handler while events are
3121+// being dispatched.
3122+func (o *Keyboard) handlersForModifiers() []func(serial uint32, modsDepressed uint32, modsLatched uint32, modsLocked uint32, group uint32) {
3123+ o.handlersMu.Lock()
3124+ defer o.handlersMu.Unlock()
3125+ return o.onModifiers
3126+}
3127+
3128+// OnRepeatInfo registers a handler for the repeat_info event.
3129+//
3130+// Handlers are appended, so a second call adds another handler rather than
3131+// replacing the first. Registration is safe while another goroutine dispatches.
3132+func (o *Keyboard) OnRepeatInfo(handler func(rate int32, delay int32)) {
3133+ if handler == nil {
3134+ return
3135+ }
3136+ o.handlersMu.Lock()
3137+ defer o.handlersMu.Unlock()
3138+ o.onRepeatInfo = append(o.onRepeatInfo, handler)
3139+}
3140+
3141+// handlersForRepeatInfo returns the handlers registered for repeat_info, taken
3142+// under the lock so a handler may register another handler while events are
3143+// being dispatched.
3144+func (o *Keyboard) handlersForRepeatInfo() []func(rate int32, delay int32) {
3145+ o.handlersMu.Lock()
3146+ defer o.handlersMu.Unlock()
3147+ return o.onRepeatInfo
3148+}
3149+
3150+// EventSignature returns the declared event argument types in wire order.
3151+func (o *Keyboard) EventSignature(opcode uint16) (string, bool) {
3152+ switch opcode {
3153+ case 0:
3154+ return "uint,fd,uint,", true
3155+ case 1:
3156+ return "uint,object,array,", true
3157+ case 2:
3158+ return "uint,object,", true
3159+ case 3:
3160+ return "uint,uint,uint,uint,", true
3161+ case 4:
3162+ return "uint,uint,uint,uint,uint,", true
3163+ case 5:
3164+ return "int,int,", true
3165+ default:
3166+ return "", false
3167+ }
3168+}
3169+
3170+// Dispatch decodes one event on wl_keyboard and calls the registered handlers.
3171+func (o *Keyboard) Dispatch(event *wl.Event) {
3172+ switch event.Opcode {
3173+ case 0: // keymap
3174+ format := event.Uint32()
3175+ fd := event.FD()
3176+ size := event.Uint32()
3177+ defer func() { _ = fd.Close() }()
3178+ for i, handler := range o.handlersForKeymap() {
3179+ if i > 0 {
3180+ fd = nil
3181+ }
3182+ handler(format, fd, size)
3183+ }
3184+ case 1: // enter
3185+ serial := event.Uint32()
3186+ surfaceID := event.Uint32()
3187+ keys := event.Array()
3188+
3189+ for i, handler := range o.handlersForEnter() {
3190+ _ = i
3191+ handler(serial, surfaceID, keys)
3192+ }
3193+ case 2: // leave
3194+ serial := event.Uint32()
3195+ surfaceID := event.Uint32()
3196+
3197+ for i, handler := range o.handlersForLeave() {
3198+ _ = i
3199+ handler(serial, surfaceID)
3200+ }
3201+ case 3: // key
3202+ serial := event.Uint32()
3203+ time := event.Uint32()
3204+ key := event.Uint32()
3205+ state := event.Uint32()
3206+
3207+ for i, handler := range o.handlersForKey() {
3208+ _ = i
3209+ handler(serial, time, key, state)
3210+ }
3211+ case 4: // modifiers
3212+ serial := event.Uint32()
3213+ modsDepressed := event.Uint32()
3214+ modsLatched := event.Uint32()
3215+ modsLocked := event.Uint32()
3216+ group := event.Uint32()
3217+
3218+ for i, handler := range o.handlersForModifiers() {
3219+ _ = i
3220+ handler(serial, modsDepressed, modsLatched, modsLocked, group)
3221+ }
3222+ case 5: // repeat_info
3223+ rate := event.Int32()
3224+ delay := event.Int32()
3225+
3226+ for i, handler := range o.handlersForRepeatInfo() {
3227+ _ = i
3228+ handler(rate, delay)
3229+ }
3230+ default:
3231+ }
3232+}
3233+
3234+// TouchInterface is the protocol interface name.
3235+const TouchInterface = "wl_touch"
3236+
3237+// Touch is the generated binding for wl_touch version 11.
3238+type Touch struct {
3239+ wl.BaseProxy
3240+ // handlersMu guards the handler slices: a client may register or replace
3241+ // handlers while another goroutine dispatches events.
3242+ handlersMu sync.Mutex
3243+ onDown []func(serial uint32, time uint32, surfaceID uint32, id int32, x wl.Fixed, y wl.Fixed)
3244+ onUp []func(serial uint32, time uint32, id int32)
3245+ onMotion []func(time uint32, id int32, x wl.Fixed, y wl.Fixed)
3246+ onFrame []func()
3247+ onCancel []func()
3248+ onShape []func(id int32, major wl.Fixed, minor wl.Fixed)
3249+ onOrientation []func(id int32, orientation wl.Fixed)
3250+}
3251+
3252+// NewTouch returns an unbound Touch.
3253+func NewTouch(ctx *wl.Context) *Touch {
3254+ obj := &Touch{}
3255+ obj.SetContext(ctx)
3256+ ctx.Register(obj)
3257+ return obj
3258+}
3259+
3260+// release the touch object
3261+func (o *Touch) Release() error {
3262+ if err := o.Context().SendRequest(o, 0); err != nil {
3263+ return err
3264+ }
3265+ o.Context().Unregister(o)
3266+ return nil
3267+}
3268+
3269+// OnDown registers a handler for the down event.
3270+//
3271+// Handlers are appended, so a second call adds another handler rather than
3272+// replacing the first. Registration is safe while another goroutine dispatches.
3273+func (o *Touch) OnDown(handler func(serial uint32, time uint32, surfaceID uint32, id int32, x wl.Fixed, y wl.Fixed)) {
3274+ if handler == nil {
3275+ return
3276+ }
3277+ o.handlersMu.Lock()
3278+ defer o.handlersMu.Unlock()
3279+ o.onDown = append(o.onDown, handler)
3280+}
3281+
3282+// handlersForDown returns the handlers registered for down, taken
3283+// under the lock so a handler may register another handler while events are
3284+// being dispatched.
3285+func (o *Touch) handlersForDown() []func(serial uint32, time uint32, surfaceID uint32, id int32, x wl.Fixed, y wl.Fixed) {
3286+ o.handlersMu.Lock()
3287+ defer o.handlersMu.Unlock()
3288+ return o.onDown
3289+}
3290+
3291+// OnUp registers a handler for the up event.
3292+//
3293+// Handlers are appended, so a second call adds another handler rather than
3294+// replacing the first. Registration is safe while another goroutine dispatches.
3295+func (o *Touch) OnUp(handler func(serial uint32, time uint32, id int32)) {
3296+ if handler == nil {
3297+ return
3298+ }
3299+ o.handlersMu.Lock()
3300+ defer o.handlersMu.Unlock()
3301+ o.onUp = append(o.onUp, handler)
3302+}
3303+
3304+// handlersForUp returns the handlers registered for up, taken
3305+// under the lock so a handler may register another handler while events are
3306+// being dispatched.
3307+func (o *Touch) handlersForUp() []func(serial uint32, time uint32, id int32) {
3308+ o.handlersMu.Lock()
3309+ defer o.handlersMu.Unlock()
3310+ return o.onUp
3311+}
3312+
3313+// OnMotion registers a handler for the motion event.
3314+//
3315+// Handlers are appended, so a second call adds another handler rather than
3316+// replacing the first. Registration is safe while another goroutine dispatches.
3317+func (o *Touch) OnMotion(handler func(time uint32, id int32, x wl.Fixed, y wl.Fixed)) {
3318+ if handler == nil {
3319+ return
3320+ }
3321+ o.handlersMu.Lock()
3322+ defer o.handlersMu.Unlock()
3323+ o.onMotion = append(o.onMotion, handler)
3324+}
3325+
3326+// handlersForMotion returns the handlers registered for motion, taken
3327+// under the lock so a handler may register another handler while events are
3328+// being dispatched.
3329+func (o *Touch) handlersForMotion() []func(time uint32, id int32, x wl.Fixed, y wl.Fixed) {
3330+ o.handlersMu.Lock()
3331+ defer o.handlersMu.Unlock()
3332+ return o.onMotion
3333+}
3334+
3335+// OnFrame registers a handler for the frame event.
3336+//
3337+// Handlers are appended, so a second call adds another handler rather than
3338+// replacing the first. Registration is safe while another goroutine dispatches.
3339+func (o *Touch) OnFrame(handler func()) {
3340+ if handler == nil {
3341+ return
3342+ }
3343+ o.handlersMu.Lock()
3344+ defer o.handlersMu.Unlock()
3345+ o.onFrame = append(o.onFrame, handler)
3346+}
3347+
3348+// handlersForFrame returns the handlers registered for frame, taken
3349+// under the lock so a handler may register another handler while events are
3350+// being dispatched.
3351+func (o *Touch) handlersForFrame() []func() {
3352+ o.handlersMu.Lock()
3353+ defer o.handlersMu.Unlock()
3354+ return o.onFrame
3355+}
3356+
3357+// OnCancel registers a handler for the cancel event.
3358+//
3359+// Handlers are appended, so a second call adds another handler rather than
3360+// replacing the first. Registration is safe while another goroutine dispatches.
3361+func (o *Touch) OnCancel(handler func()) {
3362+ if handler == nil {
3363+ return
3364+ }
3365+ o.handlersMu.Lock()
3366+ defer o.handlersMu.Unlock()
3367+ o.onCancel = append(o.onCancel, handler)
3368+}
3369+
3370+// handlersForCancel returns the handlers registered for cancel, taken
3371+// under the lock so a handler may register another handler while events are
3372+// being dispatched.
3373+func (o *Touch) handlersForCancel() []func() {
3374+ o.handlersMu.Lock()
3375+ defer o.handlersMu.Unlock()
3376+ return o.onCancel
3377+}
3378+
3379+// OnShape registers a handler for the shape event.
3380+//
3381+// Handlers are appended, so a second call adds another handler rather than
3382+// replacing the first. Registration is safe while another goroutine dispatches.
3383+func (o *Touch) OnShape(handler func(id int32, major wl.Fixed, minor wl.Fixed)) {
3384+ if handler == nil {
3385+ return
3386+ }
3387+ o.handlersMu.Lock()
3388+ defer o.handlersMu.Unlock()
3389+ o.onShape = append(o.onShape, handler)
3390+}
3391+
3392+// handlersForShape returns the handlers registered for shape, taken
3393+// under the lock so a handler may register another handler while events are
3394+// being dispatched.
3395+func (o *Touch) handlersForShape() []func(id int32, major wl.Fixed, minor wl.Fixed) {
3396+ o.handlersMu.Lock()
3397+ defer o.handlersMu.Unlock()
3398+ return o.onShape
3399+}
3400+
3401+// OnOrientation registers a handler for the orientation event.
3402+//
3403+// Handlers are appended, so a second call adds another handler rather than
3404+// replacing the first. Registration is safe while another goroutine dispatches.
3405+func (o *Touch) OnOrientation(handler func(id int32, orientation wl.Fixed)) {
3406+ if handler == nil {
3407+ return
3408+ }
3409+ o.handlersMu.Lock()
3410+ defer o.handlersMu.Unlock()
3411+ o.onOrientation = append(o.onOrientation, handler)
3412+}
3413+
3414+// handlersForOrientation returns the handlers registered for orientation, taken
3415+// under the lock so a handler may register another handler while events are
3416+// being dispatched.
3417+func (o *Touch) handlersForOrientation() []func(id int32, orientation wl.Fixed) {
3418+ o.handlersMu.Lock()
3419+ defer o.handlersMu.Unlock()
3420+ return o.onOrientation
3421+}
3422+
3423+// EventSignature returns the declared event argument types in wire order.
3424+func (o *Touch) EventSignature(opcode uint16) (string, bool) {
3425+ switch opcode {
3426+ case 0:
3427+ return "uint,uint,object,int,fixed,fixed,", true
3428+ case 1:
3429+ return "uint,uint,int,", true
3430+ case 2:
3431+ return "uint,int,fixed,fixed,", true
3432+ case 3:
3433+ return "", true
3434+ case 4:
3435+ return "", true
3436+ case 5:
3437+ return "int,fixed,fixed,", true
3438+ case 6:
3439+ return "int,fixed,", true
3440+ default:
3441+ return "", false
3442+ }
3443+}
3444+
3445+// Dispatch decodes one event on wl_touch and calls the registered handlers.
3446+func (o *Touch) Dispatch(event *wl.Event) {
3447+ switch event.Opcode {
3448+ case 0: // down
3449+ serial := event.Uint32()
3450+ time := event.Uint32()
3451+ surfaceID := event.Uint32()
3452+ id := event.Int32()
3453+ x := event.Fixed()
3454+ y := event.Fixed()
3455+
3456+ for i, handler := range o.handlersForDown() {
3457+ _ = i
3458+ handler(serial, time, surfaceID, id, x, y)
3459+ }
3460+ case 1: // up
3461+ serial := event.Uint32()
3462+ time := event.Uint32()
3463+ id := event.Int32()
3464+
3465+ for i, handler := range o.handlersForUp() {
3466+ _ = i
3467+ handler(serial, time, id)
3468+ }
3469+ case 2: // motion
3470+ time := event.Uint32()
3471+ id := event.Int32()
3472+ x := event.Fixed()
3473+ y := event.Fixed()
3474+
3475+ for i, handler := range o.handlersForMotion() {
3476+ _ = i
3477+ handler(time, id, x, y)
3478+ }
3479+ case 3: // frame
3480+
3481+ for i, handler := range o.handlersForFrame() {
3482+ _ = i
3483+ handler()
3484+ }
3485+ case 4: // cancel
3486+
3487+ for i, handler := range o.handlersForCancel() {
3488+ _ = i
3489+ handler()
3490+ }
3491+ case 5: // shape
3492+ id := event.Int32()
3493+ major := event.Fixed()
3494+ minor := event.Fixed()
3495+
3496+ for i, handler := range o.handlersForShape() {
3497+ _ = i
3498+ handler(id, major, minor)
3499+ }
3500+ case 6: // orientation
3501+ id := event.Int32()
3502+ orientation := event.Fixed()
3503+
3504+ for i, handler := range o.handlersForOrientation() {
3505+ _ = i
3506+ handler(id, orientation)
3507+ }
3508+ default:
3509+ }
3510+}
3511+
3512+// OutputInterface is the protocol interface name.
3513+const OutputInterface = "wl_output"
3514+
3515+// Output is the generated binding for wl_output version 4.
3516+type Output struct {
3517+ wl.BaseProxy
3518+ // handlersMu guards the handler slices: a client may register or replace
3519+ // handlers while another goroutine dispatches events.
3520+ handlersMu sync.Mutex
3521+ onGeometry []func(x int32, y int32, physicalWidth int32, physicalHeight int32, subpixel int32, make string, model string, transform int32)
3522+ onMode []func(flags uint32, width int32, height int32, refresh int32)
3523+ onDone []func()
3524+ onScale []func(factor int32)
3525+ onName []func(name string)
3526+ onDescription []func(description string)
3527+}
3528+
3529+// NewOutput returns an unbound Output.
3530+func NewOutput(ctx *wl.Context) *Output {
3531+ obj := &Output{}
3532+ obj.SetContext(ctx)
3533+ ctx.Register(obj)
3534+ return obj
3535+}
3536+
3537+// Using this request a client can tell the server that it is not going to use the output object anymore.
3538+func (o *Output) Release() error {
3539+ if err := o.Context().SendRequest(o, 0); err != nil {
3540+ return err
3541+ }
3542+ o.Context().Unregister(o)
3543+ return nil
3544+}
3545+
3546+// OnGeometry registers a handler for the geometry event.
3547+//
3548+// Handlers are appended, so a second call adds another handler rather than
3549+// replacing the first. Registration is safe while another goroutine dispatches.
3550+func (o *Output) OnGeometry(handler func(x int32, y int32, physicalWidth int32, physicalHeight int32, subpixel int32, make string, model string, transform int32)) {
3551+ if handler == nil {
3552+ return
3553+ }
3554+ o.handlersMu.Lock()
3555+ defer o.handlersMu.Unlock()
3556+ o.onGeometry = append(o.onGeometry, handler)
3557+}
3558+
3559+// handlersForGeometry returns the handlers registered for geometry, taken
3560+// under the lock so a handler may register another handler while events are
3561+// being dispatched.
3562+func (o *Output) handlersForGeometry() []func(x int32, y int32, physicalWidth int32, physicalHeight int32, subpixel int32, make string, model string, transform int32) {
3563+ o.handlersMu.Lock()
3564+ defer o.handlersMu.Unlock()
3565+ return o.onGeometry
3566+}
3567+
3568+// OnMode registers a handler for the mode event.
3569+//
3570+// Handlers are appended, so a second call adds another handler rather than
3571+// replacing the first. Registration is safe while another goroutine dispatches.
3572+func (o *Output) OnMode(handler func(flags uint32, width int32, height int32, refresh int32)) {
3573+ if handler == nil {
3574+ return
3575+ }
3576+ o.handlersMu.Lock()
3577+ defer o.handlersMu.Unlock()
3578+ o.onMode = append(o.onMode, handler)
3579+}
3580+
3581+// handlersForMode returns the handlers registered for mode, taken
3582+// under the lock so a handler may register another handler while events are
3583+// being dispatched.
3584+func (o *Output) handlersForMode() []func(flags uint32, width int32, height int32, refresh int32) {
3585+ o.handlersMu.Lock()
3586+ defer o.handlersMu.Unlock()
3587+ return o.onMode
3588+}
3589+
3590+// OnDone registers a handler for the done event.
3591+//
3592+// Handlers are appended, so a second call adds another handler rather than
3593+// replacing the first. Registration is safe while another goroutine dispatches.
3594+func (o *Output) OnDone(handler func()) {
3595+ if handler == nil {
3596+ return
3597+ }
3598+ o.handlersMu.Lock()
3599+ defer o.handlersMu.Unlock()
3600+ o.onDone = append(o.onDone, handler)
3601+}
3602+
3603+// handlersForDone returns the handlers registered for done, taken
3604+// under the lock so a handler may register another handler while events are
3605+// being dispatched.
3606+func (o *Output) handlersForDone() []func() {
3607+ o.handlersMu.Lock()
3608+ defer o.handlersMu.Unlock()
3609+ return o.onDone
3610+}
3611+
3612+// OnScale registers a handler for the scale event.
3613+//
3614+// Handlers are appended, so a second call adds another handler rather than
3615+// replacing the first. Registration is safe while another goroutine dispatches.
3616+func (o *Output) OnScale(handler func(factor int32)) {
3617+ if handler == nil {
3618+ return
3619+ }
3620+ o.handlersMu.Lock()
3621+ defer o.handlersMu.Unlock()
3622+ o.onScale = append(o.onScale, handler)
3623+}
3624+
3625+// handlersForScale returns the handlers registered for scale, taken
3626+// under the lock so a handler may register another handler while events are
3627+// being dispatched.
3628+func (o *Output) handlersForScale() []func(factor int32) {
3629+ o.handlersMu.Lock()
3630+ defer o.handlersMu.Unlock()
3631+ return o.onScale
3632+}
3633+
3634+// OnName registers a handler for the name event.
3635+//
3636+// Handlers are appended, so a second call adds another handler rather than
3637+// replacing the first. Registration is safe while another goroutine dispatches.
3638+func (o *Output) OnName(handler func(name string)) {
3639+ if handler == nil {
3640+ return
3641+ }
3642+ o.handlersMu.Lock()
3643+ defer o.handlersMu.Unlock()
3644+ o.onName = append(o.onName, handler)
3645+}
3646+
3647+// handlersForName returns the handlers registered for name, taken
3648+// under the lock so a handler may register another handler while events are
3649+// being dispatched.
3650+func (o *Output) handlersForName() []func(name string) {
3651+ o.handlersMu.Lock()
3652+ defer o.handlersMu.Unlock()
3653+ return o.onName
3654+}
3655+
3656+// OnDescription registers a handler for the description event.
3657+//
3658+// Handlers are appended, so a second call adds another handler rather than
3659+// replacing the first. Registration is safe while another goroutine dispatches.
3660+func (o *Output) OnDescription(handler func(description string)) {
3661+ if handler == nil {
3662+ return
3663+ }
3664+ o.handlersMu.Lock()
3665+ defer o.handlersMu.Unlock()
3666+ o.onDescription = append(o.onDescription, handler)
3667+}
3668+
3669+// handlersForDescription returns the handlers registered for description, taken
3670+// under the lock so a handler may register another handler while events are
3671+// being dispatched.
3672+func (o *Output) handlersForDescription() []func(description string) {
3673+ o.handlersMu.Lock()
3674+ defer o.handlersMu.Unlock()
3675+ return o.onDescription
3676+}
3677+
3678+// EventSignature returns the declared event argument types in wire order.
3679+func (o *Output) EventSignature(opcode uint16) (string, bool) {
3680+ switch opcode {
3681+ case 0:
3682+ return "int,int,int,int,int,string,string,int,", true
3683+ case 1:
3684+ return "uint,int,int,int,", true
3685+ case 2:
3686+ return "", true
3687+ case 3:
3688+ return "int,", true
3689+ case 4:
3690+ return "string,", true
3691+ case 5:
3692+ return "string,", true
3693+ default:
3694+ return "", false
3695+ }
3696+}
3697+
3698+// Dispatch decodes one event on wl_output and calls the registered handlers.
3699+func (o *Output) Dispatch(event *wl.Event) {
3700+ switch event.Opcode {
3701+ case 0: // geometry
3702+ x := event.Int32()
3703+ y := event.Int32()
3704+ physicalWidth := event.Int32()
3705+ physicalHeight := event.Int32()
3706+ subpixel := event.Int32()
3707+ make := event.String()
3708+ model := event.String()
3709+ transform := event.Int32()
3710+
3711+ for i, handler := range o.handlersForGeometry() {
3712+ _ = i
3713+ handler(x, y, physicalWidth, physicalHeight, subpixel, make, model, transform)
3714+ }
3715+ case 1: // mode
3716+ flags := event.Uint32()
3717+ width := event.Int32()
3718+ height := event.Int32()
3719+ refresh := event.Int32()
3720+
3721+ for i, handler := range o.handlersForMode() {
3722+ _ = i
3723+ handler(flags, width, height, refresh)
3724+ }
3725+ case 2: // done
3726+
3727+ for i, handler := range o.handlersForDone() {
3728+ _ = i
3729+ handler()
3730+ }
3731+ case 3: // scale
3732+ factor := event.Int32()
3733+
3734+ for i, handler := range o.handlersForScale() {
3735+ _ = i
3736+ handler(factor)
3737+ }
3738+ case 4: // name
3739+ name := event.String()
3740+
3741+ for i, handler := range o.handlersForName() {
3742+ _ = i
3743+ handler(name)
3744+ }
3745+ case 5: // description
3746+ description := event.String()
3747+
3748+ for i, handler := range o.handlersForDescription() {
3749+ _ = i
3750+ handler(description)
3751+ }
3752+ default:
3753+ }
3754+}
3755+
3756+// RegionInterface is the protocol interface name.
3757+const RegionInterface = "wl_region"
3758+
3759+// Region is the generated binding for wl_region version 7.
3760+type Region struct {
3761+ wl.BaseProxy
3762+}
3763+
3764+// NewRegion returns an unbound Region.
3765+func NewRegion(ctx *wl.Context) *Region {
3766+ obj := &Region{}
3767+ obj.SetContext(ctx)
3768+ ctx.Register(obj)
3769+ return obj
3770+}
3771+
3772+// Destroy the region. This will invalidate the object ID.
3773+func (o *Region) Destroy() error {
3774+ if err := o.Context().SendRequest(o, 0); err != nil {
3775+ return err
3776+ }
3777+ o.Context().Unregister(o)
3778+ return nil
3779+}
3780+
3781+// Add the specified rectangle to the region.
3782+func (o *Region) Add(x int32, y int32, width int32, height int32) error {
3783+ if err := o.Context().SendRequest(o, 1, x, y, width, height); err != nil {
3784+ return err
3785+ }
3786+ return nil
3787+}
3788+
3789+// Subtract the specified rectangle from the region.
3790+func (o *Region) Subtract(x int32, y int32, width int32, height int32) error {
3791+ if err := o.Context().SendRequest(o, 2, x, y, width, height); err != nil {
3792+ return err
3793+ }
3794+ return nil
3795+}
3796+
3797+// EventSignature returns the declared event argument types in wire order.
3798+func (o *Region) EventSignature(opcode uint16) (string, bool) {
3799+ switch opcode {
3800+ default:
3801+ return "", false
3802+ }
3803+}
3804+
3805+// Dispatch decodes one event on wl_region and calls the registered handlers.
3806+func (o *Region) Dispatch(event *wl.Event) {
3807+ switch event.Opcode {
3808+ default:
3809+ }
3810+}
3811+
3812+// SubcompositorInterface is the protocol interface name.
3813+const SubcompositorInterface = "wl_subcompositor"
3814+
3815+// Subcompositor is the generated binding for wl_subcompositor version 1.
3816+type Subcompositor struct {
3817+ wl.BaseProxy
3818+}
3819+
3820+// NewSubcompositor returns an unbound Subcompositor.
3821+func NewSubcompositor(ctx *wl.Context) *Subcompositor {
3822+ obj := &Subcompositor{}
3823+ obj.SetContext(ctx)
3824+ ctx.Register(obj)
3825+ return obj
3826+}
3827+
3828+// Informs the server that the client will not be using this protocol object anymore. This does not affect any other objects, wl_subsurface objects included.
3829+func (o *Subcompositor) Destroy() error {
3830+ if err := o.Context().SendRequest(o, 0); err != nil {
3831+ return err
3832+ }
3833+ o.Context().Unregister(o)
3834+ return nil
3835+}
3836+
3837+// Create a sub-surface interface for the given surface, and associate it with the given parent surface. This turns a plain wl_surface into a sub-surface. The to-be sub-surface must not already have another role, and it must not have an existing wl_subsurface object. Otherwise the bad_surface protocol error is raised. Adding sub-surfaces to a parent is a double-buffered operation on the parent (see wl_surface.commit). The effect of adding a sub-surface becomes visible on the next time the state of the parent surface is applied. The parent surface must not be one of the child surface's descendants, and the parent must be different from the child surface, otherwise the bad_parent protocol error is raised. This request modifies the behaviour of wl_surface.commit request on the sub-surface, see the documentation on wl_subsurface interface.
3838+func (o *Subcompositor) GetSubsurface(surface *Surface, parent *Surface) (*Subsurface, error) {
3839+ var arg1 wl.Object
3840+ if surface != nil {
3841+ arg1 = surface
3842+ }
3843+ var arg2 wl.Object
3844+ if parent != nil {
3845+ arg2 = parent
3846+ }
3847+ child := &Subsurface{}
3848+ child.SetContext(o.Context())
3849+ child.SetID(o.Context().AllocateID())
3850+ o.Context().Register(child)
3851+ if err := o.Context().SendRequest(o, 1, child, arg1, arg2); err != nil {
3852+ o.Context().Unregister(child)
3853+ return nil, err
3854+ }
3855+ return child, nil
3856+}
3857+
3858+// EventSignature returns the declared event argument types in wire order.
3859+func (o *Subcompositor) EventSignature(opcode uint16) (string, bool) {
3860+ switch opcode {
3861+ default:
3862+ return "", false
3863+ }
3864+}
3865+
3866+// Dispatch decodes one event on wl_subcompositor and calls the registered handlers.
3867+func (o *Subcompositor) Dispatch(event *wl.Event) {
3868+ switch event.Opcode {
3869+ default:
3870+ }
3871+}
3872+
3873+// SubsurfaceInterface is the protocol interface name.
3874+const SubsurfaceInterface = "wl_subsurface"
3875+
3876+// Subsurface is the generated binding for wl_subsurface version 1.
3877+type Subsurface struct {
3878+ wl.BaseProxy
3879+}
3880+
3881+// NewSubsurface returns an unbound Subsurface.
3882+func NewSubsurface(ctx *wl.Context) *Subsurface {
3883+ obj := &Subsurface{}
3884+ obj.SetContext(ctx)
3885+ ctx.Register(obj)
3886+ return obj
3887+}
3888+
3889+// The sub-surface interface is removed from the wl_surface object that was turned into a sub-surface with a wl_subcompositor.get_subsurface request. The wl_surface's association to the parent is deleted. The wl_surface is unmapped immediately.
3890+func (o *Subsurface) Destroy() error {
3891+ if err := o.Context().SendRequest(o, 0); err != nil {
3892+ return err
3893+ }
3894+ o.Context().Unregister(o)
3895+ return nil
3896+}
3897+
3898+// This sets the position of the sub-surface, relative to the parent surface. The sub-surface will be moved so that its origin (top left corner pixel) will be at the location x, y of the parent surface coordinate system. The coordinates are not restricted to the parent surface area. Negative values are allowed. The initial position is 0, 0. Position is double-buffered state on the parent surface, see wl_subsurface and wl_surface.commit for more information.
3899+func (o *Subsurface) SetPosition(x int32, y int32) error {
3900+ if err := o.Context().SendRequest(o, 1, x, y); err != nil {
3901+ return err
3902+ }
3903+ return nil
3904+}
3905+
3906+// This sub-surface is taken from the stack, and put back just above the reference surface, changing the z-order of the sub-surfaces. The reference surface must be one of the sibling surfaces, or the parent surface. Using any other surface, including this sub-surface, will cause a protocol error. A new sub-surface is initially added as the top-most in the stack of its siblings and parent. Z-order is double-buffered state on the parent surface, see wl_subsurface and wl_surface.commit for more information.
3907+func (o *Subsurface) PlaceAbove(sibling *Surface) error {
3908+ var arg0 wl.Object
3909+ if sibling != nil {
3910+ arg0 = sibling
3911+ }
3912+ if err := o.Context().SendRequest(o, 2, arg0); err != nil {
3913+ return err
3914+ }
3915+ return nil
3916+}
3917+
3918+// The sub-surface is placed just below the reference surface. See wl_subsurface.place_above.
3919+func (o *Subsurface) PlaceBelow(sibling *Surface) error {
3920+ var arg0 wl.Object
3921+ if sibling != nil {
3922+ arg0 = sibling
3923+ }
3924+ if err := o.Context().SendRequest(o, 3, arg0); err != nil {
3925+ return err
3926+ }
3927+ return nil
3928+}
3929+
3930+// Change the commit behaviour of the sub-surface to synchronized mode. See wl_subsurface and wl_surface.commit for more information.
3931+func (o *Subsurface) SetSync() error {
3932+ if err := o.Context().SendRequest(o, 4); err != nil {
3933+ return err
3934+ }
3935+ return nil
3936+}
3937+
3938+// Change the commit behaviour of the sub-surface to desynchronized mode. See wl_subsurface and wl_surface.commit for more information.
3939+func (o *Subsurface) SetDesync() error {
3940+ if err := o.Context().SendRequest(o, 5); err != nil {
3941+ return err
3942+ }
3943+ return nil
3944+}
3945+
3946+// EventSignature returns the declared event argument types in wire order.
3947+func (o *Subsurface) EventSignature(opcode uint16) (string, bool) {
3948+ switch opcode {
3949+ default:
3950+ return "", false
3951+ }
3952+}
3953+
3954+// Dispatch decodes one event on wl_subsurface and calls the registered handlers.
3955+func (o *Subsurface) Dispatch(event *wl.Event) {
3956+ switch event.Opcode {
3957+ default:
3958+ }
3959+}
3960+
3961+// FixesInterface is the protocol interface name.
3962+const FixesInterface = "wl_fixes"
3963+
3964+// Fixes is the generated binding for wl_fixes version 2.
3965+type Fixes struct {
3966+ wl.BaseProxy
3967+}
3968+
3969+// NewFixes returns an unbound Fixes.
3970+func NewFixes(ctx *wl.Context) *Fixes {
3971+ obj := &Fixes{}
3972+ obj.SetContext(ctx)
3973+ ctx.Register(obj)
3974+ return obj
3975+}
3976+
3977+// destroys this object
3978+func (o *Fixes) Destroy() error {
3979+ if err := o.Context().SendRequest(o, 0); err != nil {
3980+ return err
3981+ }
3982+ o.Context().Unregister(o)
3983+ return nil
3984+}
3985+
3986+// This request destroys a wl_registry object. The client should no longer use the wl_registry after making this request. The compositor will emit a wl_display.delete_id event with the object ID of the registry and will no longer emit any events on the registry. The client should re-use the object ID once it receives the wl_display.delete_id event.
3987+func (o *Fixes) DestroyRegistry(registry *wl.Registry) error {
3988+ var arg0 wl.Object
3989+ if registry != nil {
3990+ arg0 = registry
3991+ }
3992+ if err := o.Context().SendRequest(o, 1, arg0); err != nil {
3993+ return err
3994+ }
3995+ return nil
3996+}
3997+
3998+// Acknowledge the removal of the specified global. If no global with the specified name exists or the global is not removed, the wl_fixes.invalid_ack_remove protocol error will be posted. Due to the Wayland protocol being asynchronous, the wl_global objects cannot be destroyed immediately. For example, if a wl_global is removed and a client attempts to bind that global around same time, it can result in a protocol error due to an unknown global name in the bind request. In order to avoid crashing clients, the compositor should remove the wl_global once it is guaranteed that no more bind requests will come. The wl_fixes.ack_global_remove() request is used to signal to the compositor that the client will not bind the given global anymore. After all clients acknowledge the removal of the global, the compositor can safely destroy it. The client must call the wl_fixes.ack_global_remove() request in response to a wl_registry.global_remove() event even if it did not bind the corresponding global.
3999+func (o *Fixes) AckGlobalRemove(registry *wl.Registry, name uint32) error {
4000+ var arg0 wl.Object
4001+ if registry != nil {
4002+ arg0 = registry
4003+ }
4004+ if err := o.Context().SendRequest(o, 2, arg0, name); err != nil {
4005+ return err
4006+ }
4007+ return nil
4008+}
4009+
4010+// EventSignature returns the declared event argument types in wire order.
4011+func (o *Fixes) EventSignature(opcode uint16) (string, bool) {
4012+ switch opcode {
4013+ default:
4014+ return "", false
4015+ }
4016+}
4017+
4018+// Dispatch decodes one event on wl_fixes and calls the registered handlers.
4019+func (o *Fixes) Dispatch(event *wl.Event) {
4020+ switch event.Opcode {
4021+ default:
4022+ }
4023+}
M scm_linux.go +21 -20
@@ -6,9 +6,12 @@ package wlturbo
66 import (
77 "errors"
88 "fmt"
9- "golang.org/x/sys/unix"
9+ "io"
10+ "net"
1011 "sync"
1112 "syscall"
13+
14+ "golang.org/x/sys/unix"
1215 )
1316
1417 // maxRecvFDs bounds how many ancillary file descriptors a single read accepts.
@@ -88,20 +91,9 @@ func parseFDs(oob []byte) ([]int, error) {
8891 return fds, nil
8992 }
9093
91-// queueFDs appends descriptors to this connection's pending list.
92-func (d *Display) queueFDs(fds []int) {
93- if len(fds) == 0 {
94- return
95- }
96- d.fdMu.Lock()
97- d.pendingFDs = append(d.pendingFDs, fds...)
98- d.fdMu.Unlock()
99-}
100-
101-// nextFD removes and returns the oldest pending descriptor.
94+// queueFDs is called only by the active Dispatch reader.
95+func (d *Display) queueFDs(fds []int) { d.pendingFDs = append(d.pendingFDs, fds...) }
10296 func (d *Display) nextFD() (int, bool) {
103- d.fdMu.Lock()
104- defer d.fdMu.Unlock()
10597 if len(d.pendingFDs) == 0 {
10698 return -1, false
10799 }
@@ -110,13 +102,10 @@ func (d *Display) nextFD() (int, bool) {
110102 return fd, true
111103 }
112104
113-// closePendingFDs closes every descriptor this connection still holds.
105+// closePendingFDs is called under recvMu (including during shutdown).
114106 func (d *Display) closePendingFDs() {
115- d.fdMu.Lock()
116107 fds := d.pendingFDs
117108 d.pendingFDs = nil
118- d.fdMu.Unlock()
119-
120109 for _, fd := range fds {
121110 if fd >= 0 {
122111 _ = unix.Close(fd)
@@ -124,20 +113,32 @@ func (d *Display) closePendingFDs() {
124113 }
125114 }
126115
116+// CloseSentFD releases a descriptor after a complete successful Wayland send.
117+func CloseSentFD(fd int) error { return unix.Close(fd) }
118+
127119 // sendmsgWithFDs sends a message, attaching file descriptors when present.
128120 func (d *Display) sendmsgWithFDs(buf []byte, fds []int) error {
129121 d.sendMu.Lock()
130122 defer d.sendMu.Unlock()
131123
124+ if d.closed.Load() {
125+ return net.ErrClosed
126+ }
132127 if len(fds) == 0 {
133- _, err := d.conn.Write(buf)
128+ n, err := d.conn.Write(buf)
129+ if err == nil && n != len(buf) {
130+ return io.ErrShortWrite
131+ }
134132 return err
135133 }
136134 if d.unix == nil {
137135 return errors.New("wlturbo: cannot send file descriptors over a non-Unix connection")
138136 }
139137
140- _, _, err := d.unix.WriteMsgUnix(buf, unix.UnixRights(fds...), nil)
138+ n, _, err := d.unix.WriteMsgUnix(buf, unix.UnixRights(fds...), nil)
139+ if err == nil && n != len(buf) {
140+ return io.ErrShortWrite
141+ }
141142 return err
142143 }
143144
A signature.go +50 -0
@@ -0,0 +1,50 @@
1+package wlturbo
2+
3+import (
4+ "encoding/binary"
5+ "fmt"
6+)
7+
8+// validateEventBody rejects truncated, unterminated and trailing wire values
9+// before generated code decodes or registers any children.
10+func validateEventBody(sig string, body []byte) error {
11+ pos := 0
12+ for len(sig) > 0 {
13+ end := 0
14+ for end < len(sig) && sig[end] != ',' {
15+ end++
16+ }
17+ kind := sig[:end]
18+ if end == len(sig) {
19+ return fmt.Errorf("invalid signature %q", sig)
20+ }
21+ sig = sig[end+1:]
22+ if kind == "fd" {
23+ continue
24+ }
25+ if len(body)-pos < 4 {
26+ return ErrMalformedFrame
27+ }
28+ switch kind {
29+ case "int", "uint", "fixed", "object", "new_id":
30+ pos += 4
31+ case "string", "array":
32+ n := uint64(binary.LittleEndian.Uint32(body[pos:]))
33+ pos += 4
34+ padded := (n + 3) &^ uint64(3)
35+ if padded > uint64(len(body)-pos) {
36+ return ErrMalformedFrame
37+ }
38+ if kind == "string" && n > 0 && body[pos+int(n)-1] != 0 {
39+ return ErrMalformedFrame
40+ }
41+ pos += int(padded)
42+ default:
43+ return fmt.Errorf("invalid argument kind %q: %w", kind, ErrMalformedFrame)
44+ }
45+ }
46+ if pos != len(body) {
47+ return ErrMalformedFrame
48+ }
49+ return nil
50+}
M transport_test.go +10 -5
@@ -92,6 +92,11 @@ func newChunkDisplay(chunks [][]byte) (*Display, *[]EventRecord) {
9292 BaseProxy: BaseProxy{id: 7, context: d.context},
9393 records: &records,
9494 })
95+ for _, opcode := range []uint16{3, 4, 5} {
96+ signature := "uint,"
97+ if opcode == 3 { signature = "uint,uint," }
98+ d.RegisterEventSignature(7, opcode, signature)
99+ }
95100 return d, &records
96101 }
97102
@@ -132,7 +137,7 @@ func TestDisplayDispatch_Fragmented(t *testing.T) {
132137 }
133138
134139 func TestDisplayDispatch_Coalesced(t *testing.T) {
135- first := message(7, 3, []byte{0x11, 0x12, 0x13, 0x14})
140+ first := message(7, 4, []byte{0x11, 0x12, 0x13, 0x14})
136141 second := message(7, 4, []byte{0x21, 0x22, 0x23, 0x24})
137142
138143 d, records := newChunkDisplay([][]byte{append(append([]byte{}, first...), second...)})
@@ -146,7 +151,7 @@ func TestDisplayDispatch_Coalesced(t *testing.T) {
146151 }
147152
148153 want := []EventRecord{
149- {Object: 7, Opcode: 3, Body: []byte{0x11, 0x12, 0x13, 0x14}},
154+ {Object: 7, Opcode: 4, Body: []byte{0x11, 0x12, 0x13, 0x14}},
150155 {Object: 7, Opcode: 4, Body: []byte{0x21, 0x22, 0x23, 0x24}},
151156 }
152157 if !reflect.DeepEqual(*records, want) {
@@ -157,7 +162,7 @@ func TestDisplayDispatch_Coalesced(t *testing.T) {
157162 func TestDisplayDispatch_HalfCoalesced(t *testing.T) {
158163 // A read boundary that ends between the header and the body of the second
159164 // message must not be mistaken for a frame boundary.
160- whole := append(message(7, 3, []byte{0x01, 0x02, 0x03, 0x04}),
165+ whole := append(message(7, 4, []byte{0x01, 0x02, 0x03, 0x04}),
161166 message(7, 5, []byte{0x05, 0x06, 0x07, 0x08})...)
162167
163168 split := HeaderSize + 4 + 4 // mid-body of the second message
@@ -171,7 +176,7 @@ func TestDisplayDispatch_HalfCoalesced(t *testing.T) {
171176 }
172177
173178 want := []EventRecord{
174- {Object: 7, Opcode: 3, Body: []byte{0x01, 0x02, 0x03, 0x04}},
179+ {Object: 7, Opcode: 4, Body: []byte{0x01, 0x02, 0x03, 0x04}},
175180 {Object: 7, Opcode: 5, Body: []byte{0x05, 0x06, 0x07, 0x08}},
176181 }
177182 if !reflect.DeepEqual(*records, want) {
@@ -299,7 +304,7 @@ func TestDisplayDispatch_PeerClose(t *testing.T) {
299304 },
300305 {
301306 name: "closed after a complete message",
302- chunks: [][]byte{message(7, 3, []byte{0x01, 0x02, 0x03, 0x04})},
307+ chunks: [][]byte{message(7, 4, []byte{0x01, 0x02, 0x03, 0x04})},
303308 },
304309 }
305310
M wl/wl.go +2 -18
@@ -21,14 +21,7 @@ type (
2121 RegistryGlobalRemoveHandler = wlturbo.RegistryGlobalRemoveHandler
2222 RegistryGlobalEvent = wlturbo.RegistryGlobalEvent
2323 RegistryGlobalRemoveEvent = wlturbo.RegistryGlobalRemoveEvent
24- Seat = wlturbo.Seat
25- Surface = wlturbo.Surface
26- Pointer = wlturbo.Pointer
27- Keyboard = wlturbo.Keyboard
28- Touch = wlturbo.Touch
29- Output = wlturbo.Output
30- Region = wlturbo.Region
31- Compositor = wlturbo.Compositor
24+ OwnedFD = wlturbo.OwnedFD
3225
3326 // Transport failures. Without these, a caller that imports this shim has to
3427 // import the root package as well just to classify an error.
@@ -40,10 +33,8 @@ type (
4033 var (
4134 Connect = wlturbo.Connect
4235 NewFixed = wlturbo.NewFixed
43- NewSeat = wlturbo.NewSeat
4436 NewContext = wlturbo.NewContext
45- NewSurface = wlturbo.NewSurface
46- NewCompositor = wlturbo.NewCompositor
37+ CloseSentFD = wlturbo.CloseSentFD
4738 CreateAnonymousFile = wlturbo.CreateAnonymousFile
4839 MapMemory = wlturbo.MapMemory
4940 UnmapMemory = wlturbo.UnmapMemory
@@ -57,10 +48,3 @@ var (
5748 ErrUnknownOpcode = wlturbo.ErrUnknownOpcode
5849 ErrDisplayError = wlturbo.ErrDisplayError
5950 )
60-
61-// Seat capability constants
62-const (
63- SeatCapabilityPointer = wlturbo.SeatCapabilityPointer
64- SeatCapabilityKeyboard = wlturbo.SeatCapabilityKeyboard
65- SeatCapabilityTouch = wlturbo.SeatCapabilityTouch
66-)

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 8

↑↓ moveenter openesc close