1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: wlr_gamma_control_unstable_v1
3// Source: wlr-gamma-control-unstable-v1.xml
4
5// Upstream protocol copyright and license:
6// Copyright © 2015 Giulio camuffo
7// Copyright © 2018 Simon Ser
8//
9// Permission to use, copy, modify, distribute, and sell this
10// software and its documentation for any purpose is hereby granted
11// without fee, provided that the above copyright notice appear in
12// all copies and that both that copyright notice and this permission
13// notice appear in supporting documentation, and that the name of
14// the copyright holders not be used in advertising or publicity
15// pertaining to distribution of the software without specific,
16// written prior permission. The copyright holders make no
17// representations about the suitability of this software for any
18// purpose. It is provided "as is" without express or implied
19// warranty.
20//
21// THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
22// SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
23// FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
24// SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
26// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
27// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
28// THIS SOFTWARE.
29
30package wlrgammacontrol
31
32import (
33 "sync"
34
35 cross_wl_output "github.com/bnema/go-wayland-bindings/client/wayland"
36 "github.com/bnema/wlturbo/wl"
37)
38
39// ERROR_INVALID_GAMMA is the error invalid_gamma value.
40const ERROR_INVALID_GAMMA = 1
41
42// GammaControlManagerInterface is the protocol interface name.
43const GammaControlManagerInterface = "zwlr_gamma_control_manager_v1"
44
45// GammaControlManager is the generated binding for zwlr_gamma_control_manager_v1 version 1.
46type GammaControlManager struct {
47 wl.BaseProxy
48}
49
50// NewGammaControlManager returns an unbound GammaControlManager.
51func NewGammaControlManager(ctx *wl.Context) *GammaControlManager {
52 obj := &GammaControlManager{}
53 obj.SetContext(ctx)
54 ctx.Register(obj)
55 return obj
56}
57
58// Create a gamma control that can be used to adjust gamma tables for the provided output.
59func (o *GammaControlManager) GetGammaControl(output *cross_wl_output.Output) (*GammaControl, error) {
60 var arg1 wl.Object
61 if output != nil {
62 arg1 = output
63 }
64 child := &GammaControl{}
65 child.SetContext(o.Context())
66 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwlr_gamma_control_manager_v1.get_gamma_control", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil {
67 return nil, err
68 }
69 return child, nil
70}
71
72// All objects created by the manager will still remain valid, until their appropriate destroy request has been called.
73func (o *GammaControlManager) Destroy() error {
74 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwlr_gamma_control_manager_v1.destroy", Destructor: true}); err != nil {
75 return err
76 }
77 return nil
78}
79
80// EventSignature returns the declared event argument types in wire order.
81func (o *GammaControlManager) EventSignature(opcode uint16) (string, bool) {
82 switch opcode {
83 default:
84 return "", false
85 }
86}
87
88// Dispatch decodes one event on zwlr_gamma_control_manager_v1 and calls the registered handlers.
89func (o *GammaControlManager) Dispatch(event *wl.Event) {
90 switch event.Opcode {
91 default:
92 }
93}
94
95// GammaControlInterface is the protocol interface name.
96const GammaControlInterface = "zwlr_gamma_control_v1"
97
98// GammaControl is the generated binding for zwlr_gamma_control_v1 version 1.
99type GammaControl struct {
100 wl.BaseProxy
101 // handlersMu guards the handler slices: a client may register or replace
102 // handlers while another goroutine dispatches events.
103 handlersMu sync.Mutex
104 onGammaSize []func(size uint32)
105 onFailed []func()
106}
107
108// NewGammaControl returns an unbound GammaControl.
109func NewGammaControl(ctx *wl.Context) *GammaControl {
110 obj := &GammaControl{}
111 obj.SetContext(ctx)
112 ctx.Register(obj)
113 return obj
114}
115
116// Set the gamma table. The file descriptor can be memory-mapped to provide the raw gamma table, which contains successive gamma ramps for the red, green and blue channels. Each gamma ramp is an array of 16-byte unsigned integers which has the same length as the gamma size. The file descriptor data must have the same length as three times the gamma size.
117func (o *GammaControl) SetGamma(fd int) error {
118 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwlr_gamma_control_v1.set_gamma", FDs: []int{fd}}, wl.ArgFD()); err != nil {
119 return err
120 }
121 return nil
122}
123
124// Destroys the gamma control object. If the object is still valid, this restores the original gamma tables.
125func (o *GammaControl) Destroy() error {
126 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwlr_gamma_control_v1.destroy", Destructor: true}); err != nil {
127 return err
128 }
129 return nil
130}
131
132// OnGammaSize registers a handler for the gamma_size event.
133//
134// Handlers are appended, so a second call adds another handler rather than
135// replacing the first. Registration is safe while another goroutine dispatches.
136func (o *GammaControl) OnGammaSize(handler func(size uint32)) {
137 if handler == nil {
138 return
139 }
140 o.handlersMu.Lock()
141 defer o.handlersMu.Unlock()
142 o.onGammaSize = append(o.onGammaSize, handler)
143}
144
145// handlersForGammaSize returns the handlers registered for gamma_size, taken
146// under the lock so a handler may register another handler while events are
147// being dispatched.
148func (o *GammaControl) handlersForGammaSize() []func(size uint32) {
149 o.handlersMu.Lock()
150 defer o.handlersMu.Unlock()
151 return o.onGammaSize
152}
153
154// OnFailed registers a handler for the failed event.
155//
156// Handlers are appended, so a second call adds another handler rather than
157// replacing the first. Registration is safe while another goroutine dispatches.
158func (o *GammaControl) OnFailed(handler func()) {
159 if handler == nil {
160 return
161 }
162 o.handlersMu.Lock()
163 defer o.handlersMu.Unlock()
164 o.onFailed = append(o.onFailed, handler)
165}
166
167// handlersForFailed returns the handlers registered for failed, taken
168// under the lock so a handler may register another handler while events are
169// being dispatched.
170func (o *GammaControl) handlersForFailed() []func() {
171 o.handlersMu.Lock()
172 defer o.handlersMu.Unlock()
173 return o.onFailed
174}
175
176// EventSignature returns the declared event argument types in wire order.
177func (o *GammaControl) EventSignature(opcode uint16) (string, bool) {
178 switch opcode {
179 case 0:
180 return "uint,", true
181 case 1:
182 return "", true
183 default:
184 return "", false
185 }
186}
187
188// Dispatch decodes one event on zwlr_gamma_control_v1 and calls the registered handlers.
189func (o *GammaControl) Dispatch(event *wl.Event) {
190 switch event.Opcode {
191 case 0: // gamma_size
192 size := event.Uint32()
193
194 for i, handler := range o.handlersForGammaSize() {
195 _ = i
196 handler(size)
197 }
198 case 1: // failed
199
200 for i, handler := range o.handlersForFailed() {
201 _ = i
202 handler()
203 }
204 default:
205 }
206}