get_registry/common/protocols_data/wayland/wl_subsurface.rs
1//! sub-surface interface to a wl_surface
2//!
3//! An additional interface to a wl_surface object, which has been
4//! made a sub-surface. A sub-surface has one parent surface. A
5//! sub-surface's size and position are not limited to that of the parent.
6//! Particularly, a sub-surface is not automatically clipped to its
7//! parent's area.
8//!
9//! A sub-surface becomes mapped, when a non-NULL wl_buffer is applied
10//! and the parent surface is mapped. The order of which one happens
11//! first is irrelevant. A sub-surface is hidden if the parent becomes
12//! hidden, or if a NULL wl_buffer is applied. These rules apply
13//! recursively through the tree of surfaces.
14//!
15//! The behaviour of a wl_surface.commit request on a sub-surface
16//! depends on the sub-surface's mode. The possible modes are
17//! synchronized and desynchronized, see methods
18//! wl_subsurface.set_sync and wl_subsurface.set_desync. Synchronized
19//! mode caches the wl_surface state to be applied when the parent's
20//! state gets applied, and desynchronized mode applies the pending
21//! wl_surface state directly. A sub-surface is initially in the
22//! synchronized mode.
23//!
24//! Sub-surfaces also have another kind of state, which is managed by
25//! wl_subsurface requests, as opposed to wl_surface requests. This
26//! state includes the sub-surface position relative to the parent
27//! surface (wl_subsurface.set_position), and the stacking order of
28//! the parent and its sub-surfaces (wl_subsurface.place_above and
29//! .place_below). This state is applied when the parent surface's
30//! wl_surface state is applied, regardless of the sub-surface's mode.
31//! As the exception, set_sync and set_desync are effective immediately.
32//!
33//! The main surface can be thought to be always in desynchronized mode,
34//! since it does not have a parent in the sub-surfaces sense.
35//!
36//! Even if a sub-surface is in desynchronized mode, it will behave as
37//! in synchronized mode, if its parent surface behaves as in
38//! synchronized mode. This rule is applied recursively throughout the
39//! tree of surfaces. This means, that one can set a sub-surface into
40//! synchronized mode, and then assume that all its child and grand-child
41//! sub-surfaces are synchronized, too, without explicitly setting them.
42//!
43//! Destroying a sub-surface takes effect immediately. If you need to
44//! synchronize the removal of a sub-surface to the parent surface update,
45//! unmap the sub-surface first by attaching a NULL wl_buffer, update parent,
46//! and then destroy the sub-surface.
47//!
48//! If the parent wl_surface object is destroyed, the sub-surface is
49//! unmapped.
50//!
51//! A sub-surface never has the keyboard focus of any seat.
52//!
53//! The wl_surface.offset request is ignored: clients must use set_position
54//! instead to move the sub-surface.
55
56use super::super::all_types::*;
57use ::wl_client::builder::prelude::*;
58
59static INTERFACE: wl_interface = wl_interface {
60 name: c"wl_subsurface".as_ptr(),
61 version: 1,
62 method_count: 6,
63 methods: {
64 static MESSAGES: [wl_message; 6] = [
65 wl_message {
66 name: c"destroy".as_ptr(),
67 signature: c"".as_ptr(),
68 types: {
69 static TYPES: [Option<&'static wl_interface>; 0] = [];
70 TYPES.as_ptr().cast()
71 },
72 },
73 wl_message {
74 name: c"set_position".as_ptr(),
75 signature: c"ii".as_ptr(),
76 types: {
77 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
78 TYPES.as_ptr().cast()
79 },
80 },
81 wl_message {
82 name: c"place_above".as_ptr(),
83 signature: c"o".as_ptr(),
84 types: {
85 static TYPES: [Option<&'static wl_interface>; 1] =
86 [Some(WlSurface::WL_INTERFACE)];
87 TYPES.as_ptr().cast()
88 },
89 },
90 wl_message {
91 name: c"place_below".as_ptr(),
92 signature: c"o".as_ptr(),
93 types: {
94 static TYPES: [Option<&'static wl_interface>; 1] =
95 [Some(WlSurface::WL_INTERFACE)];
96 TYPES.as_ptr().cast()
97 },
98 },
99 wl_message {
100 name: c"set_sync".as_ptr(),
101 signature: c"".as_ptr(),
102 types: {
103 static TYPES: [Option<&'static wl_interface>; 0] = [];
104 TYPES.as_ptr().cast()
105 },
106 },
107 wl_message {
108 name: c"set_desync".as_ptr(),
109 signature: c"".as_ptr(),
110 types: {
111 static TYPES: [Option<&'static wl_interface>; 0] = [];
112 TYPES.as_ptr().cast()
113 },
114 },
115 ];
116 MESSAGES.as_ptr()
117 },
118 event_count: 0,
119 events: ptr::null(),
120};
121
122/// An owned wl_subsurface proxy.
123///
124/// See the documentation of [the module][self] for the interface description.
125#[derive(Clone, Eq, PartialEq)]
126#[repr(transparent)]
127pub struct WlSubsurface {
128 /// This proxy has the interface INTERFACE.
129 proxy: UntypedOwnedProxy,
130}
131
132/// A borrowed wl_subsurface proxy.
133///
134/// See the documentation of [the module][self] for the interface description.
135#[derive(Eq, PartialEq)]
136#[repr(transparent)]
137pub struct WlSubsurfaceRef {
138 /// This proxy has the interface INTERFACE.
139 proxy: UntypedBorrowedProxy,
140}
141
142// SAFETY: WlSubsurface is a transparent wrapper around UntypedOwnedProxy
143unsafe impl UntypedOwnedProxyWrapper for WlSubsurface {}
144
145// SAFETY: - INTERFACE is a valid wl_interface
146// - The only invariant is that self.proxy has a compatible interface
147unsafe impl OwnedProxy for WlSubsurface {
148 const INTERFACE: &'static str = "wl_subsurface";
149 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
150 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
151 private::EventHandler(private::NoOpEventHandler);
152 const MAX_VERSION: u32 = 1;
153
154 type Borrowed = WlSubsurfaceRef;
155 type Api = private::ProxyApi;
156 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
157}
158
159// SAFETY: WlSubsurfaceRef is a transparent wrapper around UntypedBorrowedProxy
160unsafe impl UntypedBorrowedProxyWrapper for WlSubsurfaceRef {}
161
162// SAFETY: - The only invariant is that self.proxy has a compatible interface
163unsafe impl BorrowedProxy for WlSubsurfaceRef {
164 type Owned = WlSubsurface;
165}
166
167impl Deref for WlSubsurface {
168 type Target = WlSubsurfaceRef;
169
170 fn deref(&self) -> &Self::Target {
171 proxy::low_level::deref(self)
172 }
173}
174
175mod private {
176 pub struct ProxyApi;
177
178 #[allow(dead_code)]
179 pub struct EventHandler<H>(pub(super) H);
180
181 #[allow(dead_code)]
182 pub struct NoOpEventHandler;
183}
184
185impl Debug for WlSubsurface {
186 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
187 write!(f, "wl_subsurface#{}", self.proxy.id())
188 }
189}
190
191impl Debug for WlSubsurfaceRef {
192 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
193 write!(f, "wl_subsurface#{}", self.proxy.id())
194 }
195}
196
197impl PartialEq<WlSubsurfaceRef> for WlSubsurface {
198 fn eq(&self, other: &WlSubsurfaceRef) -> bool {
199 self.proxy == other.proxy
200 }
201}
202
203impl PartialEq<WlSubsurface> for WlSubsurfaceRef {
204 fn eq(&self, other: &WlSubsurface) -> bool {
205 self.proxy == other.proxy
206 }
207}
208
209#[allow(dead_code)]
210impl WlSubsurface {
211 /// Since when the destroy request is available.
212 #[allow(dead_code)]
213 pub const REQ__DESTROY__SINCE: u32 = 1;
214
215 /// Since when the set_position request is available.
216 #[allow(dead_code)]
217 pub const REQ__SET_POSITION__SINCE: u32 = 1;
218
219 /// Since when the place_above request is available.
220 #[allow(dead_code)]
221 pub const REQ__PLACE_ABOVE__SINCE: u32 = 1;
222
223 /// Since when the place_below request is available.
224 #[allow(dead_code)]
225 pub const REQ__PLACE_BELOW__SINCE: u32 = 1;
226
227 /// Since when the set_sync request is available.
228 #[allow(dead_code)]
229 pub const REQ__SET_SYNC__SINCE: u32 = 1;
230
231 /// Since when the set_desync request is available.
232 #[allow(dead_code)]
233 pub const REQ__SET_DESYNC__SINCE: u32 = 1;
234}
235
236#[allow(dead_code)]
237impl WlSubsurface {
238 /// remove sub-surface interface
239 ///
240 /// The sub-surface interface is removed from the wl_surface object
241 /// that was turned into a sub-surface with a
242 /// wl_subcompositor.get_subsurface request. The wl_surface's association
243 /// to the parent is deleted. The wl_surface is unmapped immediately.
244 #[inline]
245 pub fn destroy(&self) {
246 let mut args = [];
247 // SAFETY: - self.proxy has the interface INTERFACE
248 // - 0 < INTERFACE.method_count = 6
249 // - the request signature is ``
250 unsafe {
251 self.proxy.send_destructor(0, &mut args);
252 }
253 }
254}
255
256#[allow(dead_code)]
257impl WlSubsurfaceRef {
258 /// reposition the sub-surface
259 ///
260 /// This schedules a sub-surface position change.
261 /// The sub-surface will be moved so that its origin (top left
262 /// corner pixel) will be at the location x, y of the parent surface
263 /// coordinate system. The coordinates are not restricted to the parent
264 /// surface area. Negative values are allowed.
265 ///
266 /// The scheduled coordinates will take effect whenever the state of the
267 /// parent surface is applied.
268 ///
269 /// If more than one set_position request is invoked by the client before
270 /// the commit of the parent surface, the position of a new request always
271 /// replaces the scheduled position from any previous request.
272 ///
273 /// The initial position is 0, 0.
274 ///
275 /// # Arguments
276 ///
277 /// - `x`: x coordinate in the parent surface
278 /// - `y`: y coordinate in the parent surface
279 #[inline]
280 pub fn set_position(&self, x: i32, y: i32) {
281 let (arg0, arg1) = (x, y);
282 let mut args = [wl_argument { i: arg0 }, wl_argument { i: arg1 }];
283 // SAFETY: - self.proxy has the interface INTERFACE
284 // - 1 < INTERFACE.method_count = 6
285 // - the request signature is `ii`
286 unsafe {
287 self.proxy.send_request(1, &mut args);
288 }
289 }
290
291 /// restack the sub-surface
292 ///
293 /// This sub-surface is taken from the stack, and put back just
294 /// above the reference surface, changing the z-order of the sub-surfaces.
295 /// The reference surface must be one of the sibling surfaces, or the
296 /// parent surface. Using any other surface, including this sub-surface,
297 /// will cause a protocol error.
298 ///
299 /// The z-order is double-buffered. Requests are handled in order and
300 /// applied immediately to a pending state. The final pending state is
301 /// copied to the active state the next time the state of the parent
302 /// surface is applied.
303 ///
304 /// A new sub-surface is initially added as the top-most in the stack
305 /// of its siblings and parent.
306 ///
307 /// # Arguments
308 ///
309 /// - `sibling`: the reference surface
310 #[inline]
311 pub fn place_above(&self, sibling: &WlSurfaceRef) {
312 let (arg0,) = (sibling,);
313 let obj0_lock = proxy::lock(arg0);
314 let obj0 = check_argument_proxy("sibling", obj0_lock.wl_proxy());
315 let mut args = [wl_argument { o: obj0 }];
316 // SAFETY: - self.proxy has the interface INTERFACE
317 // - 2 < INTERFACE.method_count = 6
318 // - the request signature is `o`
319 unsafe {
320 self.proxy.send_request(2, &mut args);
321 }
322 }
323
324 /// restack the sub-surface
325 ///
326 /// The sub-surface is placed just below the reference surface.
327 /// See wl_subsurface.place_above.
328 ///
329 /// # Arguments
330 ///
331 /// - `sibling`: the reference surface
332 #[inline]
333 pub fn place_below(&self, sibling: &WlSurfaceRef) {
334 let (arg0,) = (sibling,);
335 let obj0_lock = proxy::lock(arg0);
336 let obj0 = check_argument_proxy("sibling", obj0_lock.wl_proxy());
337 let mut args = [wl_argument { o: obj0 }];
338 // SAFETY: - self.proxy has the interface INTERFACE
339 // - 3 < INTERFACE.method_count = 6
340 // - the request signature is `o`
341 unsafe {
342 self.proxy.send_request(3, &mut args);
343 }
344 }
345
346 /// set sub-surface to synchronized mode
347 ///
348 /// Change the commit behaviour of the sub-surface to synchronized
349 /// mode, also described as the parent dependent mode.
350 ///
351 /// In synchronized mode, wl_surface.commit on a sub-surface will
352 /// accumulate the committed state in a cache, but the state will
353 /// not be applied and hence will not change the compositor output.
354 /// The cached state is applied to the sub-surface immediately after
355 /// the parent surface's state is applied. This ensures atomic
356 /// updates of the parent and all its synchronized sub-surfaces.
357 /// Applying the cached state will invalidate the cache, so further
358 /// parent surface commits do not (re-)apply old state.
359 ///
360 /// See wl_subsurface for the recursive effect of this mode.
361 #[inline]
362 pub fn set_sync(&self) {
363 let mut args = [];
364 // SAFETY: - self.proxy has the interface INTERFACE
365 // - 4 < INTERFACE.method_count = 6
366 // - the request signature is ``
367 unsafe {
368 self.proxy.send_request(4, &mut args);
369 }
370 }
371
372 /// set sub-surface to desynchronized mode
373 ///
374 /// Change the commit behaviour of the sub-surface to desynchronized
375 /// mode, also described as independent or freely running mode.
376 ///
377 /// In desynchronized mode, wl_surface.commit on a sub-surface will
378 /// apply the pending state directly, without caching, as happens
379 /// normally with a wl_surface. Calling wl_surface.commit on the
380 /// parent surface has no effect on the sub-surface's wl_surface
381 /// state. This mode allows a sub-surface to be updated on its own.
382 ///
383 /// If cached state exists when wl_surface.commit is called in
384 /// desynchronized mode, the pending state is added to the cached
385 /// state, and applied as a whole. This invalidates the cache.
386 ///
387 /// Note: even if a sub-surface is set to desynchronized, a parent
388 /// sub-surface may override it to behave as synchronized. For details,
389 /// see wl_subsurface.
390 ///
391 /// If a surface's parent surface behaves as desynchronized, then
392 /// the cached state is applied on set_desync.
393 #[inline]
394 pub fn set_desync(&self) {
395 let mut args = [];
396 // SAFETY: - self.proxy has the interface INTERFACE
397 // - 5 < INTERFACE.method_count = 6
398 // - the request signature is ``
399 unsafe {
400 self.proxy.send_request(5, &mut args);
401 }
402 }
403}
404
405/// An event handler for [WlSubsurface] proxies.
406#[allow(dead_code)]
407pub trait WlSubsurfaceEventHandler {
408 type Data: 'static;
409}
410
411impl WlSubsurfaceEventHandler for private::NoOpEventHandler {
412 type Data = ();
413}
414
415// SAFETY: - INTERFACE is a valid wl_interface
416// - mutable_type always returns the same value
417unsafe impl<H> EventHandler for private::EventHandler<H>
418where
419 H: WlSubsurfaceEventHandler,
420{
421 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
422
423 #[inline]
424 fn mutable_type() -> Option<(TypeId, &'static str)> {
425 let id = TypeId::of::<H::Data>();
426 let name = std::any::type_name::<H::Data>();
427 Some((id, name))
428 }
429
430 #[allow(unused_variables)]
431 unsafe fn handle_event(
432 &self,
433 queue: &Queue,
434 data: *mut u8,
435 slf: &UntypedBorrowedProxy,
436 opcode: u32,
437 args: *mut wl_argument,
438 ) {
439 invalid_opcode("wl_subsurface", opcode);
440 }
441}
442
443impl<H> CreateEventHandler<H> for private::ProxyApi
444where
445 H: WlSubsurfaceEventHandler,
446{
447 type EventHandler = private::EventHandler<H>;
448
449 #[inline]
450 fn create_event_handler(handler: H) -> Self::EventHandler {
451 private::EventHandler(handler)
452 }
453}
454
455impl WlSubsurface {
456 /// Since when the error.bad_surface enum variant is available.
457 #[allow(dead_code)]
458 pub const ENM__ERROR_BAD_SURFACE__SINCE: u32 = 1;
459}
460
461#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
462#[allow(dead_code)]
463pub struct WlSubsurfaceError(pub u32);
464
465impl WlSubsurfaceError {
466 /// wl_surface is not a sibling or the parent
467 #[allow(dead_code)]
468 pub const BAD_SURFACE: Self = Self(0);
469}
470
471impl Debug for WlSubsurfaceError {
472 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
473 let name = match *self {
474 Self::BAD_SURFACE => "BAD_SURFACE",
475 _ => return Debug::fmt(&self.0, f),
476 };
477 f.write_str(name)
478 }
479}
480
481/// Functional event handlers.
482pub mod event_handlers {
483 use super::*;
484
485 impl WlSubsurface {}
486}