1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: xdg_decoration_unstable_v1
3// Source: xdg-decoration-unstable-v1.xml
4
5// Upstream protocol copyright and license:
6// Copyright © 2018 Simon Ser
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 xdgdecoration
28
29import (
30 "sync"
31
32 cross_xdg_toplevel "github.com/bnema/go-wayland-bindings/client/xdgshell"
33 "github.com/bnema/wlturbo/wl"
34)
35
36// ERROR_UNCONFIGURED_BUFFER is the error unconfigured_buffer value.
37const ERROR_UNCONFIGURED_BUFFER = 0
38
39// ERROR_ALREADY_CONSTRUCTED is the error already_constructed value.
40const ERROR_ALREADY_CONSTRUCTED = 1
41
42// ERROR_ORPHANED is the error orphaned value.
43const ERROR_ORPHANED = 2
44
45// ERROR_INVALID_MODE is the error invalid_mode value.
46const ERROR_INVALID_MODE = 3
47
48// MODE_CLIENT_SIDE is the mode client_side value.
49const MODE_CLIENT_SIDE = 1
50
51// MODE_SERVER_SIDE is the mode server_side value.
52const MODE_SERVER_SIDE = 2
53
54// ZxdgDecorationManagerInterface is the protocol interface name.
55const ZxdgDecorationManagerInterface = "zxdg_decoration_manager_v1"
56
57// ZxdgDecorationManager is the generated binding for zxdg_decoration_manager_v1 version 2.
58type ZxdgDecorationManager struct {
59 wl.BaseProxy
60}
61
62// NewZxdgDecorationManager returns an unbound ZxdgDecorationManager.
63func NewZxdgDecorationManager(ctx *wl.Context) *ZxdgDecorationManager {
64 obj := &ZxdgDecorationManager{}
65 obj.SetContext(ctx)
66 ctx.Register(obj)
67 return obj
68}
69
70// Destroy the decoration manager. This doesn't destroy objects created with the manager.
71func (o *ZxdgDecorationManager) Destroy() error {
72 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zxdg_decoration_manager_v1.destroy", Destructor: true}); err != nil {
73 return err
74 }
75 return nil
76}
77
78// Create a new decoration object associated with the given toplevel. For objects of version 1, creating an xdg_toplevel_decoration from an xdg_toplevel which has a buffer attached or committed is a client error, and any attempts by a client to attach or manipulate a buffer prior to the first xdg_toplevel_decoration.configure event must also be treated as errors. For objects of version 2 or newer, creating an xdg_toplevel_decoration from an xdg_toplevel which has a buffer attached or committed is allowed. The initial decoration mode of the surface if a buffer is already attached depends on whether a xdg_toplevel_decoration object has been associated with the surface or not prior to this request. If an xdg_toplevel_decoration was associated with the surface, then destroyed without a surface commit, the previous decoration mode is retained. If no xdg_toplevel_decoration was associated with the surface prior to this request, or if a surface commit has been performed after a previous xdg_toplevel_decoration object associated with the surface was destroyed, the decoration mode is assumed to be client-side.
79func (o *ZxdgDecorationManager) GetToplevelDecoration(toplevel *cross_xdg_toplevel.XdgToplevel) (*ZxdgToplevelDecoration, error) {
80 var arg1 wl.Object
81 if toplevel != nil {
82 arg1 = toplevel
83 }
84 child := &ZxdgToplevelDecoration{}
85 child.SetContext(o.Context())
86 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zxdg_decoration_manager_v1.get_toplevel_decoration", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil {
87 return nil, err
88 }
89 return child, nil
90}
91
92// EventSignature returns the declared event argument types in wire order.
93func (o *ZxdgDecorationManager) EventSignature(opcode uint16) (string, bool) {
94 switch opcode {
95 default:
96 return "", false
97 }
98}
99
100// Dispatch decodes one event on zxdg_decoration_manager_v1 and calls the registered handlers.
101func (o *ZxdgDecorationManager) Dispatch(event *wl.Event) {
102 switch event.Opcode {
103 default:
104 }
105}
106
107// ZxdgToplevelDecorationInterface is the protocol interface name.
108const ZxdgToplevelDecorationInterface = "zxdg_toplevel_decoration_v1"
109
110// ZxdgToplevelDecoration is the generated binding for zxdg_toplevel_decoration_v1 version 2.
111type ZxdgToplevelDecoration struct {
112 wl.BaseProxy
113 // handlersMu guards the handler slices: a client may register or replace
114 // handlers while another goroutine dispatches events.
115 handlersMu sync.Mutex
116 onConfigure []func(mode uint32)
117}
118
119// NewZxdgToplevelDecoration returns an unbound ZxdgToplevelDecoration.
120func NewZxdgToplevelDecoration(ctx *wl.Context) *ZxdgToplevelDecoration {
121 obj := &ZxdgToplevelDecoration{}
122 obj.SetContext(ctx)
123 ctx.Register(obj)
124 return obj
125}
126
127// Switch back to a mode without any server-side decorations at the next commit, unless a new xdg_toplevel_decoration is created for the surface first.
128func (o *ZxdgToplevelDecoration) Destroy() error {
129 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zxdg_toplevel_decoration_v1.destroy", Destructor: true}); err != nil {
130 return err
131 }
132 return nil
133}
134
135// Set the toplevel surface decoration mode. This informs the compositor that the client prefers the provided decoration mode. After requesting a decoration mode, the compositor will respond by emitting an xdg_surface.configure event. The client should then update its content, drawing it without decorations if the received mode is server-side decorations. The client must also acknowledge the configure when committing the new content (see xdg_surface.ack_configure). The compositor can decide not to use the client's mode and enforce a different mode instead. Clients whose decoration mode depend on the xdg_toplevel state may send a set_mode request in response to an xdg_surface.configure event and wait for the next xdg_surface.configure event to prevent unwanted state. Such clients are responsible for preventing configure loops and must make sure not to send multiple successive set_mode requests with the same decoration mode. If an invalid mode is supplied by the client, the invalid_mode protocol error is raised by the compositor.
136func (o *ZxdgToplevelDecoration) SetMode(mode uint32) error {
137 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zxdg_toplevel_decoration_v1.set_mode"}, wl.ArgUint(mode)); err != nil {
138 return err
139 }
140 return nil
141}
142
143// Unset the toplevel surface decoration mode. This informs the compositor that the client doesn't prefer a particular decoration mode. This request has the same semantics as set_mode.
144func (o *ZxdgToplevelDecoration) UnsetMode() error {
145 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "zxdg_toplevel_decoration_v1.unset_mode"}); err != nil {
146 return err
147 }
148 return nil
149}
150
151// OnConfigure registers a handler for the configure event.
152//
153// Handlers are appended, so a second call adds another handler rather than
154// replacing the first. Registration is safe while another goroutine dispatches.
155func (o *ZxdgToplevelDecoration) OnConfigure(handler func(mode uint32)) {
156 if handler == nil {
157 return
158 }
159 o.handlersMu.Lock()
160 defer o.handlersMu.Unlock()
161 o.onConfigure = append(o.onConfigure, handler)
162}
163
164// handlersForConfigure returns the handlers registered for configure, taken
165// under the lock so a handler may register another handler while events are
166// being dispatched.
167func (o *ZxdgToplevelDecoration) handlersForConfigure() []func(mode uint32) {
168 o.handlersMu.Lock()
169 defer o.handlersMu.Unlock()
170 return o.onConfigure
171}
172
173// EventSignature returns the declared event argument types in wire order.
174func (o *ZxdgToplevelDecoration) EventSignature(opcode uint16) (string, bool) {
175 switch opcode {
176 case 0:
177 return "uint,", true
178 default:
179 return "", false
180 }
181}
182
183// Dispatch decodes one event on zxdg_toplevel_decoration_v1 and calls the registered handlers.
184func (o *ZxdgToplevelDecoration) Dispatch(event *wl.Event) {
185 switch event.Opcode {
186 case 0: // configure
187 mode := event.Uint32()
188
189 for i, handler := range o.handlersForConfigure() {
190 _ = i
191 handler(mode)
192 }
193 default:
194 }
195}