1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: input_timestamps_unstable_v1
3// Source: input-timestamps-unstable-v1.xml
4
5// Upstream protocol copyright and license:
6// Copyright © 2017 Collabora, Ltd.
7//
8// Permission is hereby granted, free of charge, to any person obtaining a
9// copy of this software and associated documentation files (the "Software"),
10// to deal in the Software without restriction, including without limitation
11// the rights to use, copy, modify, merge, publish, distribute, sublicense,
12// and/or sell copies of the Software, and to permit persons to whom the
13// Software is furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice (including the next
16// paragraph) shall be included in all copies or substantial portions of the
17// Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25// DEALINGS IN THE SOFTWARE.
26
27package inputtimestamps
28
29import (
30 "sync"
31
32 cross_wl_keyboard "github.com/bnema/go-wayland-bindings/client/wayland"
33 cross_wl_pointer "github.com/bnema/go-wayland-bindings/client/wayland"
34 cross_wl_touch "github.com/bnema/go-wayland-bindings/client/wayland"
35 "github.com/bnema/wlturbo/wl"
36)
37
38// InputTimestampsManagerInterface is the protocol interface name.
39const InputTimestampsManagerInterface = "zwp_input_timestamps_manager_v1"
40
41// InputTimestampsManager is the generated binding for zwp_input_timestamps_manager_v1 version 1.
42type InputTimestampsManager struct {
43 wl.BaseProxy
44}
45
46// NewInputTimestampsManager returns an unbound InputTimestampsManager.
47func NewInputTimestampsManager(ctx *wl.Context) *InputTimestampsManager {
48 obj := &InputTimestampsManager{}
49 obj.SetContext(ctx)
50 ctx.Register(obj)
51 return obj
52}
53
54// Informs the server that the client will no longer be using this protocol object. Existing objects created by this object are not affected.
55func (o *InputTimestampsManager) Destroy() error {
56 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_input_timestamps_manager_v1.destroy", Destructor: true}); err != nil {
57 return err
58 }
59 return nil
60}
61
62// Creates a new input timestamps object that represents a subscription to high-resolution timestamp events for all wl_keyboard events that carry a timestamp. If the associated wl_keyboard object is invalidated, either through client action (e.g. release) or server-side changes, the input timestamps object becomes inert and the client should destroy it by calling zwp_input_timestamps_v1.destroy.
63func (o *InputTimestampsManager) GetKeyboardTimestamps(keyboard *cross_wl_keyboard.Keyboard) (*InputTimestamps, error) {
64 var arg1 wl.Object
65 if keyboard != nil {
66 arg1 = keyboard
67 }
68 child := &InputTimestamps{}
69 child.SetContext(o.Context())
70 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_input_timestamps_manager_v1.get_keyboard_timestamps", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil {
71 return nil, err
72 }
73 return child, nil
74}
75
76// Creates a new input timestamps object that represents a subscription to high-resolution timestamp events for all wl_pointer events that carry a timestamp. If the associated wl_pointer object is invalidated, either through client action (e.g. release) or server-side changes, the input timestamps object becomes inert and the client should destroy it by calling zwp_input_timestamps_v1.destroy.
77func (o *InputTimestampsManager) GetPointerTimestamps(pointer *cross_wl_pointer.Pointer) (*InputTimestamps, error) {
78 var arg1 wl.Object
79 if pointer != nil {
80 arg1 = pointer
81 }
82 child := &InputTimestamps{}
83 child.SetContext(o.Context())
84 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "zwp_input_timestamps_manager_v1.get_pointer_timestamps", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil {
85 return nil, err
86 }
87 return child, nil
88}
89
90// Creates a new input timestamps object that represents a subscription to high-resolution timestamp events for all wl_touch events that carry a timestamp. If the associated wl_touch object becomes invalid, either through client action (e.g. release) or server-side changes, the input timestamps object becomes inert and the client should destroy it by calling zwp_input_timestamps_v1.destroy.
91func (o *InputTimestampsManager) GetTouchTimestamps(touch *cross_wl_touch.Touch) (*InputTimestamps, error) {
92 var arg1 wl.Object
93 if touch != nil {
94 arg1 = touch
95 }
96 child := &InputTimestamps{}
97 child.SetContext(o.Context())
98 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 3, Name: "zwp_input_timestamps_manager_v1.get_touch_timestamps", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil {
99 return nil, err
100 }
101 return child, nil
102}
103
104// EventSignature returns the declared event argument types in wire order.
105func (o *InputTimestampsManager) EventSignature(opcode uint16) (string, bool) {
106 switch opcode {
107 default:
108 return "", false
109 }
110}
111
112// Dispatch decodes one event on zwp_input_timestamps_manager_v1 and calls the registered handlers.
113func (o *InputTimestampsManager) Dispatch(event *wl.Event) {
114 switch event.Opcode {
115 default:
116 }
117}
118
119// InputTimestampsInterface is the protocol interface name.
120const InputTimestampsInterface = "zwp_input_timestamps_v1"
121
122// InputTimestamps is the generated binding for zwp_input_timestamps_v1 version 1.
123type InputTimestamps struct {
124 wl.BaseProxy
125 // handlersMu guards the handler slices: a client may register or replace
126 // handlers while another goroutine dispatches events.
127 handlersMu sync.Mutex
128 onTimestamp []func(tvSecHi uint32, tvSecLo uint32, tvNsec uint32)
129}
130
131// NewInputTimestamps returns an unbound InputTimestamps.
132func NewInputTimestamps(ctx *wl.Context) *InputTimestamps {
133 obj := &InputTimestamps{}
134 obj.SetContext(ctx)
135 ctx.Register(obj)
136 return obj
137}
138
139// Informs the server that the client will no longer be using this protocol object. After the server processes the request, no more timestamp events will be emitted.
140func (o *InputTimestamps) Destroy() error {
141 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_input_timestamps_v1.destroy", Destructor: true}); err != nil {
142 return err
143 }
144 return nil
145}
146
147// OnTimestamp registers a handler for the timestamp event.
148//
149// Handlers are appended, so a second call adds another handler rather than
150// replacing the first. Registration is safe while another goroutine dispatches.
151func (o *InputTimestamps) OnTimestamp(handler func(tvSecHi uint32, tvSecLo uint32, tvNsec uint32)) {
152 if handler == nil {
153 return
154 }
155 o.handlersMu.Lock()
156 defer o.handlersMu.Unlock()
157 o.onTimestamp = append(o.onTimestamp, handler)
158}
159
160// handlersForTimestamp returns the handlers registered for timestamp, taken
161// under the lock so a handler may register another handler while events are
162// being dispatched.
163func (o *InputTimestamps) handlersForTimestamp() []func(tvSecHi uint32, tvSecLo uint32, tvNsec uint32) {
164 o.handlersMu.Lock()
165 defer o.handlersMu.Unlock()
166 return o.onTimestamp
167}
168
169// EventSignature returns the declared event argument types in wire order.
170func (o *InputTimestamps) EventSignature(opcode uint16) (string, bool) {
171 switch opcode {
172 case 0:
173 return "uint,uint,uint,", true
174 default:
175 return "", false
176 }
177}
178
179// Dispatch decodes one event on zwp_input_timestamps_v1 and calls the registered handlers.
180func (o *InputTimestamps) Dispatch(event *wl.Event) {
181 switch event.Opcode {
182 case 0: // timestamp
183 tvSecHi := event.Uint32()
184 tvSecLo := event.Uint32()
185 tvNsec := event.Uint32()
186
187 for i, handler := range o.handlersForTimestamp() {
188 _ = i
189 handler(tvSecHi, tvSecLo, tvNsec)
190 }
191 default:
192 }
193}