xdgsessionmanagement_generated.go RawHistoryFolder
1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: xdg_session_management_v1
3// Source: xdg-session-management-v1.xml
4
5// Upstream protocol copyright and license:
6// Copyright 2018 Mike Blumenkrantz
7// Copyright 2018 Samsung Electronics Co., Ltd
8// Copyright 2018 Red Hat Inc.
9//
10// Permission is hereby granted, free of charge, to any person obtaining a
11// copy of this software and associated documentation files (the "Software"),
12// to deal in the Software without restriction, including without limitation
13// the rights to use, copy, modify, merge, publish, distribute, sublicense,
14// and/or sell copies of the Software, and to permit persons to whom the
15// Software is furnished to do so, subject to the following conditions:
16//
17// The above copyright notice and this permission notice (including the next
18// paragraph) shall be included in all copies or substantial portions of the
19// Software.
20//
21// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27// DEALINGS IN THE SOFTWARE.
28
29package xdgsessionmanagement
30
31import (
32 "sync"
33
34 cross_xdg_toplevel "github.com/bnema/go-wayland-bindings/client/xdgshell"
35 "github.com/bnema/wlturbo/wl"
36)
37
38// ERROR_IN_USE is the error in_use value.
39const ERROR_IN_USE = 1
40
41// ERROR_INVALID_SESSION_ID is the error invalid_session_id value.
42const ERROR_INVALID_SESSION_ID = 2
43
44// ERROR_INVALID_REASON is the error invalid_reason value.
45const ERROR_INVALID_REASON = 3
46
47// REASON_LAUNCH is the reason launch value.
48const REASON_LAUNCH = 1
49
50// REASON_RECOVER is the reason recover value.
51const REASON_RECOVER = 2
52
53// REASON_SESSION_RESTORE is the reason session_restore value.
54const REASON_SESSION_RESTORE = 3
55
56// ERROR_NAME_IN_USE is the error name_in_use value.
57const ERROR_NAME_IN_USE = 1
58
59// ERROR_ALREADY_MAPPED is the error already_mapped value.
60const ERROR_ALREADY_MAPPED = 2
61
62// ERROR_INVALID_NAME is the error invalid_name value.
63const ERROR_INVALID_NAME = 3
64
65// ERROR_ALREADY_ADDED is the error already_added value.
66const ERROR_ALREADY_ADDED = 4
67
68// XdgSessionManagerInterface is the protocol interface name.
69const XdgSessionManagerInterface = "xdg_session_manager_v1"
70
71// XdgSessionManager is the generated binding for xdg_session_manager_v1 version 1.
72type XdgSessionManager struct {
73 wl.BaseProxy
74}
75
76// NewXdgSessionManager returns an unbound XdgSessionManager.
77func NewXdgSessionManager(ctx *wl.Context) *XdgSessionManager {
78 obj := &XdgSessionManager{}
79 obj.SetContext(ctx)
80 ctx.Register(obj)
81 return obj
82}
83
84// Destroy the manager object. The existing session objects will be unaffected.
85func (o *XdgSessionManager) Destroy() error {
86 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "xdg_session_manager_v1.destroy", Destructor: true}); err != nil {
87 return err
88 }
89 return nil
90}
91
92// Create a session object corresponding to either an existing session identified by the given session identifier string or a new session. While the session object exists, the session is considered to be "in use". If an identifier string represents a session that is currently actively in use by the the same client, an 'in_use' error is raised. If some other client is currently using the same session, the new session will replace managing the associated state. If the reason is not a valid enum entry, the 'invalid_reason' protocol error is raised. NULL is passed to initiate a new session. If a session_id is passed which does not represent a valid session, the compositor treats it as if NULL had been passed. The session id string must be UTF-8 encoded. It is also limited by the maximum length of wayland messages (around 4KB). The 'invalid_session_id' protocol error will be raised if an invalid string is provided. A client is allowed to have any number of in use sessions at the same time.
93func (o *XdgSessionManager) GetSession(reason uint32, sessionId string) (*XdgSession, error) {
94 child := &XdgSession{}
95 child.SetContext(o.Context())
96 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "xdg_session_manager_v1.get_session", Child: child}, wl.ArgObject(child), wl.ArgUint(reason), wl.ArgString(sessionId)); err != nil {
97 return nil, err
98 }
99 return child, nil
100}
101
102// EventSignature returns the declared event argument types in wire order.
103func (o *XdgSessionManager) EventSignature(opcode uint16) (string, bool) {
104 switch opcode {
105 default:
106 return "", false
107 }
108}
109
110// Dispatch decodes one event on xdg_session_manager_v1 and calls the registered handlers.
111func (o *XdgSessionManager) Dispatch(event *wl.Event) {
112 switch event.Opcode {
113 default:
114 }
115}
116
117// XdgSessionInterface is the protocol interface name.
118const XdgSessionInterface = "xdg_session_v1"
119
120// XdgSession is the generated binding for xdg_session_v1 version 1.
121type XdgSession struct {
122 wl.BaseProxy
123 // handlersMu guards the handler slices: a client may register or replace
124 // handlers while another goroutine dispatches events.
125 handlersMu sync.Mutex
126 onCreated []func(sessionId string)
127 onRestored []func()
128 onReplaced []func()
129}
130
131// NewXdgSession returns an unbound XdgSession.
132func NewXdgSession(ctx *wl.Context) *XdgSession {
133 obj := &XdgSession{}
134 obj.SetContext(ctx)
135 ctx.Register(obj)
136 return obj
137}
138
139// Destroy a session object, preserving the current state but not continuing to make further updates if state changes occur. This makes the associated xdg_toplevel_session_v1 objects inert.
140func (o *XdgSession) Destroy() error {
141 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "xdg_session_v1.destroy", Destructor: true}); err != nil {
142 return err
143 }
144 return nil
145}
146
147// Remove the session, making it no longer available for restoration. A compositor should in response to this request remove the data related to this session from its storage.
148func (o *XdgSession) Remove() error {
149 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "xdg_session_v1.remove", Destructor: true}); err != nil {
150 return err
151 }
152 return nil
153}
154
155// Attempt to add a given surface to the session. The passed name is used to identify what window is being restored, and may be used to store window specific state within the session. The name given to the toplevel must not correspond to any previously existing toplevel names in the session. If the name matches an already known toplevel name in the session, a 'name_in_use' protocol error will be raised. The toplevel object must not be added more than once to any session created by the client, otherwise the 'already_added' protocol error will be raised. This request will return a xdg_toplevel_session_v1 for later manipulation. As this resource is created from an empty initial state, compositors must not emit a xdg_toplevel_session_v1.restored event for resources created through this request. The name string must be UTF-8 encoded. It is also limited by the maximum length of wayland messages (around 4KB). The 'invalid_name' protocol error will be raised if an invalid string is provided.
156func (o *XdgSession) AddToplevel(toplevel *cross_xdg_toplevel.XdgToplevel, name string) (*XdgToplevelSession, error) {
157 var arg1 wl.Object
158 if toplevel != nil {
159 arg1 = toplevel
160 }
161 child := &XdgToplevelSession{}
162 child.SetContext(o.Context())
163 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "xdg_session_v1.add_toplevel", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1), wl.ArgString(name)); err != nil {
164 return nil, err
165 }
166 return child, nil
167}
168
169// Inform the compositor that the toplevel associated with the passed name should have its window management state restored. If the toplevel name was previously granted to another xdg_toplevel, the 'name_in_use' protocol error will be raised. The toplevel object must not be added more than once to any session created by the client, otherwise the 'already_added' protocol error will be raised. This request must be called prior to the first commit on the associated wl_surface after creating the toplevel, otherwise an 'already_mapped' error is raised. As part of the initial configure sequence, if the toplevel was successfully restored, a xdg_toplevel_session_v1.restored event is emitted. If the toplevel name was not known in the session, this request will be equivalent to the xdg_toplevel_session_v1.add_toplevel request, and no such event will be emitted. See the xdg_toplevel_session_v1.restored event for further details. The name string must be UTF-8 encoded. It is also limited by the maximum length of wayland messages (around 4KB). The 'invalid_name' protocol error will be raised if an invalid string is provided.
170func (o *XdgSession) RestoreToplevel(toplevel *cross_xdg_toplevel.XdgToplevel, name string) (*XdgToplevelSession, error) {
171 var arg1 wl.Object
172 if toplevel != nil {
173 arg1 = toplevel
174 }
175 child := &XdgToplevelSession{}
176 child.SetContext(o.Context())
177 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 3, Name: "xdg_session_v1.restore_toplevel", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1), wl.ArgString(name)); err != nil {
178 return nil, err
179 }
180 return child, nil
181}
182
183// Remove a specified surface from the session and render any related xdg_toplevel_session_v1 object inert. The compositor should remove any data related to the toplevel in the corresponding session from its internal storage. The window is specified by its name in the session. The name string must be encoded in UTF-8, and it is limited in size by the maximum length of wayland messages (around 4KB).
184func (o *XdgSession) RemoveToplevel(name string) error {
185 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 4, Name: "xdg_session_v1.remove_toplevel"}, wl.ArgString(name)); err != nil {
186 return err
187 }
188 return nil
189}
190
191// OnCreated registers a handler for the created event.
192//
193// Handlers are appended, so a second call adds another handler rather than
194// replacing the first. Registration is safe while another goroutine dispatches.
195func (o *XdgSession) OnCreated(handler func(sessionId string)) {
196 if handler == nil {
197 return
198 }
199 o.handlersMu.Lock()
200 defer o.handlersMu.Unlock()
201 o.onCreated = append(o.onCreated, handler)
202}
203
204// handlersForCreated returns the handlers registered for created, taken
205// under the lock so a handler may register another handler while events are
206// being dispatched.
207func (o *XdgSession) handlersForCreated() []func(sessionId string) {
208 o.handlersMu.Lock()
209 defer o.handlersMu.Unlock()
210 return o.onCreated
211}
212
213// OnRestored registers a handler for the restored event.
214//
215// Handlers are appended, so a second call adds another handler rather than
216// replacing the first. Registration is safe while another goroutine dispatches.
217func (o *XdgSession) OnRestored(handler func()) {
218 if handler == nil {
219 return
220 }
221 o.handlersMu.Lock()
222 defer o.handlersMu.Unlock()
223 o.onRestored = append(o.onRestored, handler)
224}
225
226// handlersForRestored returns the handlers registered for restored, taken
227// under the lock so a handler may register another handler while events are
228// being dispatched.
229func (o *XdgSession) handlersForRestored() []func() {
230 o.handlersMu.Lock()
231 defer o.handlersMu.Unlock()
232 return o.onRestored
233}
234
235// OnReplaced registers a handler for the replaced event.
236//
237// Handlers are appended, so a second call adds another handler rather than
238// replacing the first. Registration is safe while another goroutine dispatches.
239func (o *XdgSession) OnReplaced(handler func()) {
240 if handler == nil {
241 return
242 }
243 o.handlersMu.Lock()
244 defer o.handlersMu.Unlock()
245 o.onReplaced = append(o.onReplaced, handler)
246}
247
248// handlersForReplaced returns the handlers registered for replaced, taken
249// under the lock so a handler may register another handler while events are
250// being dispatched.
251func (o *XdgSession) handlersForReplaced() []func() {
252 o.handlersMu.Lock()
253 defer o.handlersMu.Unlock()
254 return o.onReplaced
255}
256
257// EventSignature returns the declared event argument types in wire order.
258func (o *XdgSession) EventSignature(opcode uint16) (string, bool) {
259 switch opcode {
260 case 0:
261 return "string,", true
262 case 1:
263 return "", true
264 case 2:
265 return "", true
266 default:
267 return "", false
268 }
269}
270
271// Dispatch decodes one event on xdg_session_v1 and calls the registered handlers.
272func (o *XdgSession) Dispatch(event *wl.Event) {
273 switch event.Opcode {
274 case 0: // created
275 sessionId := event.String()
276
277 for i, handler := range o.handlersForCreated() {
278 _ = i
279 handler(sessionId)
280 }
281 case 1: // restored
282
283 for i, handler := range o.handlersForRestored() {
284 _ = i
285 handler()
286 }
287 case 2: // replaced
288
289 for i, handler := range o.handlersForReplaced() {
290 _ = i
291 handler()
292 }
293 default:
294 }
295}
296
297// XdgToplevelSessionInterface is the protocol interface name.
298const XdgToplevelSessionInterface = "xdg_toplevel_session_v1"
299
300// XdgToplevelSession is the generated binding for xdg_toplevel_session_v1 version 1.
301type XdgToplevelSession struct {
302 wl.BaseProxy
303 // handlersMu guards the handler slices: a client may register or replace
304 // handlers while another goroutine dispatches events.
305 handlersMu sync.Mutex
306 onRestored []func()
307}
308
309// NewXdgToplevelSession returns an unbound XdgToplevelSession.
310func NewXdgToplevelSession(ctx *wl.Context) *XdgToplevelSession {
311 obj := &XdgToplevelSession{}
312 obj.SetContext(ctx)
313 ctx.Register(obj)
314 return obj
315}
316
317// Destroy the object. This has no effect over window management of the associated toplevel.
318func (o *XdgToplevelSession) Destroy() error {
319 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "xdg_toplevel_session_v1.destroy", Destructor: true}); err != nil {
320 return err
321 }
322 return nil
323}
324
325// Renames the toplevel session. The new name can be used in subsequent requests to identify this session object. The state associated with this toplevel session will be preserved. If the xdg_session_v1 already contains a toplevel with the specified name, the 'name_in_use' protocol error will be raised.
326func (o *XdgToplevelSession) Rename(name string) error {
327 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "xdg_toplevel_session_v1.rename"}, wl.ArgString(name)); err != nil {
328 return err
329 }
330 return nil
331}
332
333// OnRestored registers a handler for the restored event.
334//
335// Handlers are appended, so a second call adds another handler rather than
336// replacing the first. Registration is safe while another goroutine dispatches.
337func (o *XdgToplevelSession) OnRestored(handler func()) {
338 if handler == nil {
339 return
340 }
341 o.handlersMu.Lock()
342 defer o.handlersMu.Unlock()
343 o.onRestored = append(o.onRestored, handler)
344}
345
346// handlersForRestored returns the handlers registered for restored, taken
347// under the lock so a handler may register another handler while events are
348// being dispatched.
349func (o *XdgToplevelSession) handlersForRestored() []func() {
350 o.handlersMu.Lock()
351 defer o.handlersMu.Unlock()
352 return o.onRestored
353}
354
355// EventSignature returns the declared event argument types in wire order.
356func (o *XdgToplevelSession) EventSignature(opcode uint16) (string, bool) {
357 switch opcode {
358 case 0:
359 return "", true
360 default:
361 return "", false
362 }
363}
364
365// Dispatch decodes one event on xdg_toplevel_session_v1 and calls the registered handlers.
366func (o *XdgToplevelSession) Dispatch(event *wl.Event) {
367 switch event.Opcode {
368 case 0: // restored
369
370 for i, handler := range o.handlersForRestored() {
371 _ = i
372 handler()
373 }
374 default:
375 }
376}