func (i *Registry) AddGlobalHandler(f RegistryGlobalHandlerFunc) {
	if f == nil {
		return
	}
	i.globalHandlers = append(i.globalHandlers, f)
}
AddGlobalHandler : adds handler for RegistryGlobalEvent
package client
import (
	"reflect"
	"golang.org/x/sys/unix"
)
type Display struct {
	BaseProxy
	errorHandlers    []DisplayErrorHandlerFunc
	deleteIdHandlers []DisplayDeleteIdHandlerFunc
}
func NewDisplay(ctx *Context) *Display {
	wlDisplay := &Display{}
	ctx.Register(wlDisplay)
	return wlDisplay
}
func (i *Display) Sync() (*Callback, error) {
	callback := NewCallback(i.Context())
	const opcode = 0
	const rLen = 8 + 4
	r := make([]byte, rLen)
	l := 0
	PutUint32(r[l:4], i.ID())
	l += 4
	PutUint32(r[l:l+4], uint32(rLen<<16|opcode&0x0000ffff))
	l += 4
	PutUint32(r[l:l+4], callback.ID())
	l += 4
	err := i.Context().WriteMsg(r, nil)
	return callback, err
}
func (i *Display) GetRegistry() (*Registry, error) {
	registry := NewRegistry(i.Context())
	const opcode = 1
	const rLen = 8 + 4
	r := make([]byte, rLen)
	l := 0
	PutUint32(r[l:4], i.ID())
	l += 4
	PutUint32(r[l:l+4], uint32(rLen<<16|opcode&0x0000ffff))
	l += 4
	PutUint32(r[l:l+4], registry.ID())
	l += 4
	err := i.Context().WriteMsg(r, nil)
	return registry, err
}
func (i *Display) Destroy() error {
	i.Context().Unregister(i)
	return nil
}
type DisplayError uint32
const (
	DisplayErrorInvalidObject DisplayError = 0
	DisplayErrorInvalidMethod DisplayError = 1
	DisplayErrorNoMemory DisplayError = 2
	DisplayErrorImplementation DisplayError = 3
)
func (e DisplayError) Name() string {
	switch e {
	case DisplayErrorInvalidObject:
		return "invalid_object"
	case DisplayErrorInvalidMethod:
		return "invalid_method"
	case DisplayErrorNoMemory:
		return "no_memory"
	case DisplayErrorImplementation:
		return "implementation"
	default:
		return ""
	}
}
func (e DisplayError) Value() string {
	switch e {
	case DisplayErrorInvalidObject:
		return "0"
	case DisplayErrorInvalidMethod:
		return "1"
	case DisplayErrorNoMemory:
		return "2"
	case DisplayErrorImplementation:
		return "3"
	default:
		return ""
	}
}
func (e DisplayError) String() string {
	return e.Name() + "=" + e.Value()
}
type DisplayErrorEvent struct {
	ObjectId Proxy
	Code     uint32
	Message  string
}
type DisplayErrorHandlerFunc func(DisplayErrorEvent)
func (i *Display) AddErrorHandler(f DisplayErrorHandlerFunc) {
	if f == nil {
		return
	}
	i.errorHandlers = append(i.errorHandlers, f)
}
func (i *Display) RemoveErrorHandler(f DisplayErrorHandlerFunc) {
	for j, e := range i.errorHandlers {
		if reflect.ValueOf(e).Pointer() == reflect.ValueOf(f).Pointer() {
			i.errorHandlers = append(i.errorHandlers[:j], i.errorHandlers[j+1:]...)
			return
		}
	}
}
type DisplayDeleteIdEvent struct {
	Id uint32
}
type DisplayDeleteIdHandlerFunc func(DisplayDeleteIdEvent)
func (i *Display) AddDeleteIdHandler(f DisplayDeleteIdHandlerFunc) {
	if f == nil {
		return
	}
	i.deleteIdHandlers = append(i.deleteIdHandlers, f)
}
func (i *Display) RemoveDeleteIdHandler(f DisplayDeleteIdHandlerFunc) {
	for j, e := range i.deleteIdHandlers {
		if reflect.ValueOf(e).Pointer() == reflect.ValueOf(f).Pointer() {
			i.deleteIdHandlers = append(i.deleteIdHandlers[:j], i.deleteIdHandlers[j+1:]...)
			return
		}
	}
}
func (i *Display) Dispatch(opcode uint16, fd uintptr, data []byte) {
	switch opcode {
	case 0:
		if len(i.errorHandlers) == 0 {
			return
		}
		var e DisplayErrorEvent
		l := 0
		e.ObjectId = i.Context().GetProxy(Uint32(data[l : l+4]))
		l += 4
		e.Code = Uint32(data[l : l+4])
		l += 4
		messageLen := PaddedLen(int(Uint32(data[l : l+4])))
		l += 4
		e.Message = String(data[l : l+messageLen])
		l += messageLen
		for _, f := range i.errorHandlers {
			f(e)
		}
	case 1:
		if len(i.deleteIdHandlers) == 0 {
			return
		}
		var e DisplayDeleteIdEvent
		l := 0
		e.Id = Uint32(data[l : l+4])
		l += 4
		for _, f := range i.deleteIdHandlers {
			f(e)
		}
	}
}
type Registry struct {
	BaseProxy
	globalHandlers       []RegistryGlobalHandlerFunc
	globalRemoveHandlers []RegistryGlobalRemoveHandlerFunc
}
func NewRegistry(ctx *Context) *Registry {
	wlRegistry := &Registry{}
	ctx.Register(wlRegistry)
	return wlRegistry
}
func (i *Registry) Bind(name uint32, iface string, version uint32, id Proxy) error {
	const opcode = 0
	ifaceLen := PaddedLen(len(iface) + 1)
	rLen := 8 + 4 + (4 + ifaceLen) + 4 + 4
	r := make([]byte, rLen)
	l := 0
	PutUint32(r[l:4], i.ID())
	l += 4
	PutUint32(r[l:l+4], uint32(rLen<<16|opcode&0x0000ffff))
	l += 4
	PutUint32(r[l:l+4], uint32(name))
	l += 4
	PutString(r[l:l+(4+ifaceLen)], iface, ifaceLen)
	l += (4 + ifaceLen)
	PutUint32(r[l:l+4], uint32(version))
	l += 4
	PutUint32(r[l:l+4], id.ID())
	l += 4
	err := i.Context().WriteMsg(r, nil)
	return err
}
func (i *Registry) Destroy() error {
	i.Context().Unregister(i)
	return nil
}
type RegistryGlobalEvent struct {
	Name      uint32
	Interface string
	Version   uint32
}
type RegistryGlobalHandlerFunc func(RegistryGlobalEvent)