1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: ext_idle_notify_v1
3// Source: ext-idle-notify-v1.xml
4
5// Upstream protocol copyright and license:
6// Copyright © 2015 Martin Gräßlin
7// Copyright © 2022 Simon Ser
8//
9// Permission is hereby granted, free of charge, to any person obtaining a
10// copy of this software and associated documentation files (the "Software"),
11// to deal in the Software without restriction, including without limitation
12// the rights to use, copy, modify, merge, publish, distribute, sublicense,
13// and/or sell copies of the Software, and to permit persons to whom the
14// Software is furnished to do so, subject to the following conditions:
15//
16// The above copyright notice and this permission notice (including the next
17// paragraph) shall be included in all copies or substantial portions of the
18// Software.
19//
20// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26// DEALINGS IN THE SOFTWARE.
27
28package extidlenotify
29
30import (
31 "sync"
32
33 cross_wl_seat "github.com/bnema/go-wayland-bindings/client/wayland"
34 "github.com/bnema/wlturbo/wl"
35)
36
37// ExtIdleNotifierInterface is the protocol interface name.
38const ExtIdleNotifierInterface = "ext_idle_notifier_v1"
39
40// ExtIdleNotifier is the generated binding for ext_idle_notifier_v1 version 2.
41type ExtIdleNotifier struct {
42 wl.BaseProxy
43}
44
45// NewExtIdleNotifier returns an unbound ExtIdleNotifier.
46func NewExtIdleNotifier(ctx *wl.Context) *ExtIdleNotifier {
47 obj := &ExtIdleNotifier{}
48 obj.SetContext(ctx)
49 ctx.Register(obj)
50 return obj
51}
52
53// Destroy the manager object. All objects created via this interface remain valid.
54func (o *ExtIdleNotifier) Destroy() error {
55 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_idle_notifier_v1.destroy", Destructor: true}); err != nil {
56 return err
57 }
58 return nil
59}
60
61// Create a new idle notification object. The notification object has a minimum timeout duration and is tied to a seat. The client will be notified if the seat is inactive for at least the provided timeout. See ext_idle_notification_v1 for more details. A zero timeout is valid and means the client wants to be notified as soon as possible when the seat is inactive.
62func (o *ExtIdleNotifier) GetIdleNotification(timeout uint32, seat *cross_wl_seat.Seat) (*ExtIdleNotification, error) {
63 var arg2 wl.Object
64 if seat != nil {
65 arg2 = seat
66 }
67 child := &ExtIdleNotification{}
68 child.SetContext(o.Context())
69 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_idle_notifier_v1.get_idle_notification", Child: child}, wl.ArgObject(child), wl.ArgUint(timeout), wl.ArgObject(arg2)); err != nil {
70 return nil, err
71 }
72 return child, nil
73}
74
75// Create a new idle notification object to track input from the user, such as keyboard and mouse movement. Because this object is meant to track user input alone, it ignores idle inhibitors. The notification object has a minimum timeout duration and is tied to a seat. The client will be notified if the seat is inactive for at least the provided timeout. See ext_idle_notification_v1 for more details. A zero timeout is valid and means the client wants to be notified as soon as possible when the seat is inactive.
76func (o *ExtIdleNotifier) GetInputIdleNotification(timeout uint32, seat *cross_wl_seat.Seat) (*ExtIdleNotification, error) {
77 var arg2 wl.Object
78 if seat != nil {
79 arg2 = seat
80 }
81 child := &ExtIdleNotification{}
82 child.SetContext(o.Context())
83 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "ext_idle_notifier_v1.get_input_idle_notification", Since: 2, Child: child}, wl.ArgObject(child), wl.ArgUint(timeout), wl.ArgObject(arg2)); err != nil {
84 return nil, err
85 }
86 return child, nil
87}
88
89// EventSignature returns the declared event argument types in wire order.
90func (o *ExtIdleNotifier) EventSignature(opcode uint16) (string, bool) {
91 switch opcode {
92 default:
93 return "", false
94 }
95}
96
97// Dispatch decodes one event on ext_idle_notifier_v1 and calls the registered handlers.
98func (o *ExtIdleNotifier) Dispatch(event *wl.Event) {
99 switch event.Opcode {
100 default:
101 }
102}
103
104// ExtIdleNotificationInterface is the protocol interface name.
105const ExtIdleNotificationInterface = "ext_idle_notification_v1"
106
107// ExtIdleNotification is the generated binding for ext_idle_notification_v1 version 2.
108type ExtIdleNotification struct {
109 wl.BaseProxy
110 // handlersMu guards the handler slices: a client may register or replace
111 // handlers while another goroutine dispatches events.
112 handlersMu sync.Mutex
113 onIdled []func()
114 onResumed []func()
115}
116
117// NewExtIdleNotification returns an unbound ExtIdleNotification.
118func NewExtIdleNotification(ctx *wl.Context) *ExtIdleNotification {
119 obj := &ExtIdleNotification{}
120 obj.SetContext(ctx)
121 ctx.Register(obj)
122 return obj
123}
124
125// Destroy the notification object.
126func (o *ExtIdleNotification) Destroy() error {
127 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_idle_notification_v1.destroy", Destructor: true}); err != nil {
128 return err
129 }
130 return nil
131}
132
133// OnIdled registers a handler for the idled event.
134//
135// Handlers are appended, so a second call adds another handler rather than
136// replacing the first. Registration is safe while another goroutine dispatches.
137func (o *ExtIdleNotification) OnIdled(handler func()) {
138 if handler == nil {
139 return
140 }
141 o.handlersMu.Lock()
142 defer o.handlersMu.Unlock()
143 o.onIdled = append(o.onIdled, handler)
144}
145
146// handlersForIdled returns the handlers registered for idled, taken
147// under the lock so a handler may register another handler while events are
148// being dispatched.
149func (o *ExtIdleNotification) handlersForIdled() []func() {
150 o.handlersMu.Lock()
151 defer o.handlersMu.Unlock()
152 return o.onIdled
153}
154
155// OnResumed registers a handler for the resumed event.
156//
157// Handlers are appended, so a second call adds another handler rather than
158// replacing the first. Registration is safe while another goroutine dispatches.
159func (o *ExtIdleNotification) OnResumed(handler func()) {
160 if handler == nil {
161 return
162 }
163 o.handlersMu.Lock()
164 defer o.handlersMu.Unlock()
165 o.onResumed = append(o.onResumed, handler)
166}
167
168// handlersForResumed returns the handlers registered for resumed, taken
169// under the lock so a handler may register another handler while events are
170// being dispatched.
171func (o *ExtIdleNotification) handlersForResumed() []func() {
172 o.handlersMu.Lock()
173 defer o.handlersMu.Unlock()
174 return o.onResumed
175}
176
177// EventSignature returns the declared event argument types in wire order.
178func (o *ExtIdleNotification) EventSignature(opcode uint16) (string, bool) {
179 switch opcode {
180 case 0:
181 return "", true
182 case 1:
183 return "", true
184 default:
185 return "", false
186 }
187}
188
189// Dispatch decodes one event on ext_idle_notification_v1 and calls the registered handlers.
190func (o *ExtIdleNotification) Dispatch(event *wl.Event) {
191 switch event.Opcode {
192 case 0: // idled
193
194 for i, handler := range o.handlersForIdled() {
195 _ = i
196 handler()
197 }
198 case 1: // resumed
199
200 for i, handler := range o.handlersForResumed() {
201 _ = i
202 handler()
203 }
204 default:
205 }
206}