get_registry/common/protocols/xdg_shell/xdg_toplevel.rs
1//! toplevel surface
2//!
3//! This interface defines an xdg_surface role which allows a surface to,
4//! among other things, set window-like properties such as maximize,
5//! fullscreen, and minimize, set application-specific metadata like title and
6//! id, and well as trigger user interactive operations such as interactive
7//! resize and move.
8//!
9//! A xdg_toplevel by default is responsible for providing the full intended
10//! visual representation of the toplevel, which depending on the window
11//! state, may mean things like a title bar, window controls and drop shadow.
12//!
13//! Unmapping an xdg_toplevel means that the surface cannot be shown
14//! by the compositor until it is explicitly mapped again.
15//! All active operations (e.g., move, resize) are canceled and all
16//! attributes (e.g. title, state, stacking, ...) are discarded for
17//! an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to
18//! the state it had right after xdg_surface.get_toplevel. The client
19//! can re-map the toplevel by performing a commit without any buffer
20//! attached, waiting for a configure event and handling it as usual (see
21//! xdg_surface description).
22//!
23//! Attaching a null buffer to a toplevel unmaps the surface.
24
25use super::super::all_types::*;
26use ::wl_client::builder::prelude::*;
27
28static INTERFACE: wl_interface = wl_interface {
29 name: c"xdg_toplevel".as_ptr(),
30 version: 6,
31 method_count: 14,
32 methods: {
33 static MESSAGES: [wl_message; 14] = [
34 wl_message {
35 name: c"destroy".as_ptr(),
36 signature: c"".as_ptr(),
37 types: {
38 static TYPES: [Option<&'static wl_interface>; 0] = [];
39 TYPES.as_ptr().cast()
40 },
41 },
42 wl_message {
43 name: c"set_parent".as_ptr(),
44 signature: c"?o".as_ptr(),
45 types: {
46 static TYPES: [Option<&'static wl_interface>; 1] =
47 [Some(XdgToplevel::WL_INTERFACE)];
48 TYPES.as_ptr().cast()
49 },
50 },
51 wl_message {
52 name: c"set_title".as_ptr(),
53 signature: c"s".as_ptr(),
54 types: {
55 static TYPES: [Option<&'static wl_interface>; 1] = [None];
56 TYPES.as_ptr().cast()
57 },
58 },
59 wl_message {
60 name: c"set_app_id".as_ptr(),
61 signature: c"s".as_ptr(),
62 types: {
63 static TYPES: [Option<&'static wl_interface>; 1] = [None];
64 TYPES.as_ptr().cast()
65 },
66 },
67 wl_message {
68 name: c"show_window_menu".as_ptr(),
69 signature: c"ouii".as_ptr(),
70 types: {
71 static TYPES: [Option<&'static wl_interface>; 4] =
72 [Some(WlSeat::WL_INTERFACE), None, None, None];
73 TYPES.as_ptr().cast()
74 },
75 },
76 wl_message {
77 name: c"move".as_ptr(),
78 signature: c"ou".as_ptr(),
79 types: {
80 static TYPES: [Option<&'static wl_interface>; 2] =
81 [Some(WlSeat::WL_INTERFACE), None];
82 TYPES.as_ptr().cast()
83 },
84 },
85 wl_message {
86 name: c"resize".as_ptr(),
87 signature: c"ouu".as_ptr(),
88 types: {
89 static TYPES: [Option<&'static wl_interface>; 3] =
90 [Some(WlSeat::WL_INTERFACE), None, None];
91 TYPES.as_ptr().cast()
92 },
93 },
94 wl_message {
95 name: c"set_max_size".as_ptr(),
96 signature: c"ii".as_ptr(),
97 types: {
98 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
99 TYPES.as_ptr().cast()
100 },
101 },
102 wl_message {
103 name: c"set_min_size".as_ptr(),
104 signature: c"ii".as_ptr(),
105 types: {
106 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
107 TYPES.as_ptr().cast()
108 },
109 },
110 wl_message {
111 name: c"set_maximized".as_ptr(),
112 signature: c"".as_ptr(),
113 types: {
114 static TYPES: [Option<&'static wl_interface>; 0] = [];
115 TYPES.as_ptr().cast()
116 },
117 },
118 wl_message {
119 name: c"unset_maximized".as_ptr(),
120 signature: c"".as_ptr(),
121 types: {
122 static TYPES: [Option<&'static wl_interface>; 0] = [];
123 TYPES.as_ptr().cast()
124 },
125 },
126 wl_message {
127 name: c"set_fullscreen".as_ptr(),
128 signature: c"?o".as_ptr(),
129 types: {
130 static TYPES: [Option<&'static wl_interface>; 1] =
131 [Some(WlOutput::WL_INTERFACE)];
132 TYPES.as_ptr().cast()
133 },
134 },
135 wl_message {
136 name: c"unset_fullscreen".as_ptr(),
137 signature: c"".as_ptr(),
138 types: {
139 static TYPES: [Option<&'static wl_interface>; 0] = [];
140 TYPES.as_ptr().cast()
141 },
142 },
143 wl_message {
144 name: c"set_minimized".as_ptr(),
145 signature: c"".as_ptr(),
146 types: {
147 static TYPES: [Option<&'static wl_interface>; 0] = [];
148 TYPES.as_ptr().cast()
149 },
150 },
151 ];
152 MESSAGES.as_ptr()
153 },
154 event_count: 4,
155 events: {
156 static MESSAGES: [wl_message; 4] = [
157 wl_message {
158 name: c"configure".as_ptr(),
159 signature: c"iia".as_ptr(),
160 types: {
161 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
162 TYPES.as_ptr().cast()
163 },
164 },
165 wl_message {
166 name: c"close".as_ptr(),
167 signature: c"".as_ptr(),
168 types: {
169 static TYPES: [Option<&'static wl_interface>; 0] = [];
170 TYPES.as_ptr().cast()
171 },
172 },
173 wl_message {
174 name: c"configure_bounds".as_ptr(),
175 signature: c"ii".as_ptr(),
176 types: {
177 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
178 TYPES.as_ptr().cast()
179 },
180 },
181 wl_message {
182 name: c"wm_capabilities".as_ptr(),
183 signature: c"a".as_ptr(),
184 types: {
185 static TYPES: [Option<&'static wl_interface>; 1] = [None];
186 TYPES.as_ptr().cast()
187 },
188 },
189 ];
190 MESSAGES.as_ptr()
191 },
192};
193
194/// An owned xdg_toplevel proxy.
195///
196/// See the documentation of [the module][self] for the interface description.
197#[derive(Clone, Eq, PartialEq)]
198#[repr(transparent)]
199pub struct XdgToplevel {
200 /// This proxy has the interface INTERFACE.
201 proxy: UntypedOwnedProxy,
202}
203
204/// A borrowed xdg_toplevel proxy.
205///
206/// See the documentation of [the module][self] for the interface description.
207#[derive(Eq, PartialEq)]
208#[repr(transparent)]
209pub struct XdgToplevelRef {
210 /// This proxy has the interface INTERFACE.
211 proxy: UntypedBorrowedProxy,
212}
213
214// SAFETY: XdgToplevel is a transparent wrapper around UntypedOwnedProxy
215unsafe impl UntypedOwnedProxyWrapper for XdgToplevel {}
216
217// SAFETY: - INTERFACE is a valid wl_interface
218// - The only invariant is that self.proxy has a compatible interface
219unsafe impl OwnedProxy for XdgToplevel {
220 const INTERFACE: &'static str = "xdg_toplevel";
221 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
222 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
223 private::EventHandler(private::NoOpEventHandler);
224 const MAX_VERSION: u32 = 6;
225
226 type Borrowed = XdgToplevelRef;
227 type Api = private::ProxyApi;
228 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
229}
230
231// SAFETY: XdgToplevelRef is a transparent wrapper around UntypedBorrowedProxy
232unsafe impl UntypedBorrowedProxyWrapper for XdgToplevelRef {}
233
234// SAFETY: - The only invariant is that self.proxy has a compatible interface
235unsafe impl BorrowedProxy for XdgToplevelRef {
236 type Owned = XdgToplevel;
237}
238
239impl Deref for XdgToplevel {
240 type Target = XdgToplevelRef;
241
242 fn deref(&self) -> &Self::Target {
243 proxy::low_level::deref(self)
244 }
245}
246
247mod private {
248 pub struct ProxyApi;
249
250 #[allow(dead_code)]
251 pub struct EventHandler<H>(pub(super) H);
252
253 #[allow(dead_code)]
254 pub struct NoOpEventHandler;
255}
256
257impl Debug for XdgToplevel {
258 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
259 write!(f, "xdg_toplevel#{}", self.proxy.id())
260 }
261}
262
263impl Debug for XdgToplevelRef {
264 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
265 write!(f, "xdg_toplevel#{}", self.proxy.id())
266 }
267}
268
269impl PartialEq<XdgToplevelRef> for XdgToplevel {
270 fn eq(&self, other: &XdgToplevelRef) -> bool {
271 self.proxy == other.proxy
272 }
273}
274
275impl PartialEq<XdgToplevel> for XdgToplevelRef {
276 fn eq(&self, other: &XdgToplevel) -> bool {
277 self.proxy == other.proxy
278 }
279}
280
281#[allow(dead_code)]
282impl XdgToplevel {
283 /// Since when the destroy request is available.
284 #[allow(dead_code)]
285 pub const REQ__DESTROY__SINCE: u32 = 1;
286
287 /// Since when the set_parent request is available.
288 #[allow(dead_code)]
289 pub const REQ__SET_PARENT__SINCE: u32 = 1;
290
291 /// Since when the set_title request is available.
292 #[allow(dead_code)]
293 pub const REQ__SET_TITLE__SINCE: u32 = 1;
294
295 /// Since when the set_app_id request is available.
296 #[allow(dead_code)]
297 pub const REQ__SET_APP_ID__SINCE: u32 = 1;
298
299 /// Since when the show_window_menu request is available.
300 #[allow(dead_code)]
301 pub const REQ__SHOW_WINDOW_MENU__SINCE: u32 = 1;
302
303 /// Since when the move request is available.
304 #[allow(dead_code)]
305 pub const REQ__MOVE__SINCE: u32 = 1;
306
307 /// Since when the resize request is available.
308 #[allow(dead_code)]
309 pub const REQ__RESIZE__SINCE: u32 = 1;
310
311 /// Since when the set_max_size request is available.
312 #[allow(dead_code)]
313 pub const REQ__SET_MAX_SIZE__SINCE: u32 = 1;
314
315 /// Since when the set_min_size request is available.
316 #[allow(dead_code)]
317 pub const REQ__SET_MIN_SIZE__SINCE: u32 = 1;
318
319 /// Since when the set_maximized request is available.
320 #[allow(dead_code)]
321 pub const REQ__SET_MAXIMIZED__SINCE: u32 = 1;
322
323 /// Since when the unset_maximized request is available.
324 #[allow(dead_code)]
325 pub const REQ__UNSET_MAXIMIZED__SINCE: u32 = 1;
326
327 /// Since when the set_fullscreen request is available.
328 #[allow(dead_code)]
329 pub const REQ__SET_FULLSCREEN__SINCE: u32 = 1;
330
331 /// Since when the unset_fullscreen request is available.
332 #[allow(dead_code)]
333 pub const REQ__UNSET_FULLSCREEN__SINCE: u32 = 1;
334
335 /// Since when the set_minimized request is available.
336 #[allow(dead_code)]
337 pub const REQ__SET_MINIMIZED__SINCE: u32 = 1;
338}
339
340#[allow(dead_code)]
341impl XdgToplevel {
342 /// destroy the xdg_toplevel
343 ///
344 /// This request destroys the role surface and unmaps the surface;
345 /// see "Unmapping" behavior in interface section for details.
346 #[inline]
347 pub fn destroy(&self) {
348 let mut args = [];
349 // SAFETY: - self.proxy has the interface INTERFACE
350 // - 0 < INTERFACE.method_count = 14
351 // - the request signature is ``
352 unsafe {
353 self.proxy.send_destructor(0, &mut args);
354 }
355 }
356}
357
358#[allow(dead_code)]
359impl XdgToplevelRef {
360 /// set the parent of this surface
361 ///
362 /// Set the "parent" of this surface. This surface should be stacked
363 /// above the parent surface and all other ancestor surfaces.
364 ///
365 /// Parent surfaces should be set on dialogs, toolboxes, or other
366 /// "auxiliary" surfaces, so that the parent is raised when the dialog
367 /// is raised.
368 ///
369 /// Setting a null parent for a child surface unsets its parent. Setting
370 /// a null parent for a surface which currently has no parent is a no-op.
371 ///
372 /// Only mapped surfaces can have child surfaces. Setting a parent which
373 /// is not mapped is equivalent to setting a null parent. If a surface
374 /// becomes unmapped, its children's parent is set to the parent of
375 /// the now-unmapped surface. If the now-unmapped surface has no parent,
376 /// its children's parent is unset. If the now-unmapped surface becomes
377 /// mapped again, its parent-child relationship is not restored.
378 ///
379 /// The parent toplevel must not be one of the child toplevel's
380 /// descendants, and the parent must be different from the child toplevel,
381 /// otherwise the invalid_parent protocol error is raised.
382 ///
383 /// # Arguments
384 ///
385 /// - `parent`:
386 #[inline]
387 pub fn set_parent(&self, parent: Option<&XdgToplevelRef>) {
388 let (arg0,) = (parent,);
389 let obj0_lock = arg0.map(|arg0| proxy::lock(arg0));
390 let obj0 = obj0_lock
391 .map(|obj0_lock| check_argument_proxy("parent", obj0_lock.wl_proxy()))
392 .unwrap_or(ptr::null_mut());
393 let mut args = [wl_argument { o: obj0 }];
394 // SAFETY: - self.proxy has the interface INTERFACE
395 // - 1 < INTERFACE.method_count = 14
396 // - the request signature is `?o`
397 unsafe {
398 self.proxy.send_request(1, &mut args);
399 }
400 }
401
402 /// set surface title
403 ///
404 /// Set a short title for the surface.
405 ///
406 /// This string may be used to identify the surface in a task bar,
407 /// window list, or other user interface elements provided by the
408 /// compositor.
409 ///
410 /// The string must be encoded in UTF-8.
411 ///
412 /// # Arguments
413 ///
414 /// - `title`:
415 #[inline]
416 pub fn set_title(&self, title: &str) {
417 let (arg0,) = (title,);
418 with_cstr_cache(|cache| {
419 let str0_offset = cache.len();
420 cache.extend_from_slice(arg0.as_bytes());
421 cache.push(0);
422 let str0 = cache[str0_offset..].as_ptr().cast();
423 let mut args = [wl_argument { s: str0 }];
424 // SAFETY: - self.proxy has the interface INTERFACE
425 // - 2 < INTERFACE.method_count = 14
426 // - the request signature is `s`
427 unsafe {
428 self.proxy.send_request(2, &mut args);
429 }
430 })
431 }
432
433 /// set application ID
434 ///
435 /// Set an application identifier for the surface.
436 ///
437 /// The app ID identifies the general class of applications to which
438 /// the surface belongs. The compositor can use this to group multiple
439 /// surfaces together, or to determine how to launch a new application.
440 ///
441 /// For D-Bus activatable applications, the app ID is used as the D-Bus
442 /// service name.
443 ///
444 /// The compositor shell will try to group application surfaces together
445 /// by their app ID. As a best practice, it is suggested to select app
446 /// ID's that match the basename of the application's .desktop file.
447 /// For example, "org.freedesktop.FooViewer" where the .desktop file is
448 /// "org.freedesktop.FooViewer.desktop".
449 ///
450 /// Like other properties, a set_app_id request can be sent after the
451 /// xdg_toplevel has been mapped to update the property.
452 ///
453 /// See the desktop-entry specification [0] for more details on
454 /// application identifiers and how they relate to well-known D-Bus
455 /// names and .desktop files.
456 ///
457 /// [0] https://standards.freedesktop.org/desktop-entry-spec/
458 ///
459 /// # Arguments
460 ///
461 /// - `app_id`:
462 #[inline]
463 pub fn set_app_id(&self, app_id: &str) {
464 let (arg0,) = (app_id,);
465 with_cstr_cache(|cache| {
466 let str0_offset = cache.len();
467 cache.extend_from_slice(arg0.as_bytes());
468 cache.push(0);
469 let str0 = cache[str0_offset..].as_ptr().cast();
470 let mut args = [wl_argument { s: str0 }];
471 // SAFETY: - self.proxy has the interface INTERFACE
472 // - 3 < INTERFACE.method_count = 14
473 // - the request signature is `s`
474 unsafe {
475 self.proxy.send_request(3, &mut args);
476 }
477 })
478 }
479
480 /// show the window menu
481 ///
482 /// Clients implementing client-side decorations might want to show
483 /// a context menu when right-clicking on the decorations, giving the
484 /// user a menu that they can use to maximize or minimize the window.
485 ///
486 /// This request asks the compositor to pop up such a window menu at
487 /// the given position, relative to the local surface coordinates of
488 /// the parent surface. There are no guarantees as to what menu items
489 /// the window menu contains, or even if a window menu will be drawn
490 /// at all.
491 ///
492 /// This request must be used in response to some sort of user action
493 /// like a button press, key press, or touch down event.
494 ///
495 /// # Arguments
496 ///
497 /// - `seat`: the wl_seat of the user event
498 /// - `serial`: the serial of the user event
499 /// - `x`: the x position to pop up the window menu at
500 /// - `y`: the y position to pop up the window menu at
501 #[inline]
502 pub fn show_window_menu(&self, seat: &WlSeatRef, serial: u32, x: i32, y: i32) {
503 let (arg0, arg1, arg2, arg3) = (seat, serial, x, y);
504 let obj0_lock = proxy::lock(arg0);
505 let obj0 = check_argument_proxy("seat", obj0_lock.wl_proxy());
506 let mut args = [
507 wl_argument { o: obj0 },
508 wl_argument { u: arg1 },
509 wl_argument { i: arg2 },
510 wl_argument { i: arg3 },
511 ];
512 // SAFETY: - self.proxy has the interface INTERFACE
513 // - 4 < INTERFACE.method_count = 14
514 // - the request signature is `ouii`
515 unsafe {
516 self.proxy.send_request(4, &mut args);
517 }
518 }
519
520 /// start an interactive move
521 ///
522 /// Start an interactive, user-driven move of the surface.
523 ///
524 /// This request must be used in response to some sort of user action
525 /// like a button press, key press, or touch down event. The passed
526 /// serial is used to determine the type of interactive move (touch,
527 /// pointer, etc).
528 ///
529 /// The server may ignore move requests depending on the state of
530 /// the surface (e.g. fullscreen or maximized), or if the passed serial
531 /// is no longer valid.
532 ///
533 /// If triggered, the surface will lose the focus of the device
534 /// (wl_pointer, wl_touch, etc) used for the move. It is up to the
535 /// compositor to visually indicate that the move is taking place, such as
536 /// updating a pointer cursor, during the move. There is no guarantee
537 /// that the device focus will return when the move is completed.
538 ///
539 /// # Arguments
540 ///
541 /// - `seat`: the wl_seat of the user event
542 /// - `serial`: the serial of the user event
543 #[inline]
544 pub fn r#move(&self, seat: &WlSeatRef, serial: u32) {
545 let (arg0, arg1) = (seat, serial);
546 let obj0_lock = proxy::lock(arg0);
547 let obj0 = check_argument_proxy("seat", obj0_lock.wl_proxy());
548 let mut args = [wl_argument { o: obj0 }, wl_argument { u: arg1 }];
549 // SAFETY: - self.proxy has the interface INTERFACE
550 // - 5 < INTERFACE.method_count = 14
551 // - the request signature is `ou`
552 unsafe {
553 self.proxy.send_request(5, &mut args);
554 }
555 }
556
557 /// start an interactive resize
558 ///
559 /// Start a user-driven, interactive resize of the surface.
560 ///
561 /// This request must be used in response to some sort of user action
562 /// like a button press, key press, or touch down event. The passed
563 /// serial is used to determine the type of interactive resize (touch,
564 /// pointer, etc).
565 ///
566 /// The server may ignore resize requests depending on the state of
567 /// the surface (e.g. fullscreen or maximized).
568 ///
569 /// If triggered, the client will receive configure events with the
570 /// "resize" state enum value and the expected sizes. See the "resize"
571 /// enum value for more details about what is required. The client
572 /// must also acknowledge configure events using "ack_configure". After
573 /// the resize is completed, the client will receive another "configure"
574 /// event without the resize state.
575 ///
576 /// If triggered, the surface also will lose the focus of the device
577 /// (wl_pointer, wl_touch, etc) used for the resize. It is up to the
578 /// compositor to visually indicate that the resize is taking place,
579 /// such as updating a pointer cursor, during the resize. There is no
580 /// guarantee that the device focus will return when the resize is
581 /// completed.
582 ///
583 /// The edges parameter specifies how the surface should be resized, and
584 /// is one of the values of the resize_edge enum. Values not matching
585 /// a variant of the enum will cause the invalid_resize_edge protocol error.
586 /// The compositor may use this information to update the surface position
587 /// for example when dragging the top left corner. The compositor may also
588 /// use this information to adapt its behavior, e.g. choose an appropriate
589 /// cursor image.
590 ///
591 /// # Arguments
592 ///
593 /// - `seat`: the wl_seat of the user event
594 /// - `serial`: the serial of the user event
595 /// - `edges`: which edge or corner is being dragged
596 #[inline]
597 pub fn resize(&self, seat: &WlSeatRef, serial: u32, edges: XdgToplevelResizeEdge) {
598 let (arg0, arg1, arg2) = (seat, serial, edges);
599 let obj0_lock = proxy::lock(arg0);
600 let obj0 = check_argument_proxy("seat", obj0_lock.wl_proxy());
601 let mut args = [
602 wl_argument { o: obj0 },
603 wl_argument { u: arg1 },
604 wl_argument { u: arg2.0 },
605 ];
606 // SAFETY: - self.proxy has the interface INTERFACE
607 // - 6 < INTERFACE.method_count = 14
608 // - the request signature is `ouu`
609 unsafe {
610 self.proxy.send_request(6, &mut args);
611 }
612 }
613
614 /// set the maximum size
615 ///
616 /// Set a maximum size for the window.
617 ///
618 /// The client can specify a maximum size so that the compositor does
619 /// not try to configure the window beyond this size.
620 ///
621 /// The width and height arguments are in window geometry coordinates.
622 /// See xdg_surface.set_window_geometry.
623 ///
624 /// Values set in this way are double-buffered, see wl_surface.commit.
625 ///
626 /// The compositor can use this information to allow or disallow
627 /// different states like maximize or fullscreen and draw accurate
628 /// animations.
629 ///
630 /// Similarly, a tiling window manager may use this information to
631 /// place and resize client windows in a more effective way.
632 ///
633 /// The client should not rely on the compositor to obey the maximum
634 /// size. The compositor may decide to ignore the values set by the
635 /// client and request a larger size.
636 ///
637 /// If never set, or a value of zero in the request, means that the
638 /// client has no expected maximum size in the given dimension.
639 /// As a result, a client wishing to reset the maximum size
640 /// to an unspecified state can use zero for width and height in the
641 /// request.
642 ///
643 /// Requesting a maximum size to be smaller than the minimum size of
644 /// a surface is illegal and will result in an invalid_size error.
645 ///
646 /// The width and height must be greater than or equal to zero. Using
647 /// strictly negative values for width or height will result in a
648 /// invalid_size error.
649 ///
650 /// # Arguments
651 ///
652 /// - `width`:
653 /// - `height`:
654 #[inline]
655 pub fn set_max_size(&self, width: i32, height: i32) {
656 let (arg0, arg1) = (width, height);
657 let mut args = [wl_argument { i: arg0 }, wl_argument { i: arg1 }];
658 // SAFETY: - self.proxy has the interface INTERFACE
659 // - 7 < INTERFACE.method_count = 14
660 // - the request signature is `ii`
661 unsafe {
662 self.proxy.send_request(7, &mut args);
663 }
664 }
665
666 /// set the minimum size
667 ///
668 /// Set a minimum size for the window.
669 ///
670 /// The client can specify a minimum size so that the compositor does
671 /// not try to configure the window below this size.
672 ///
673 /// The width and height arguments are in window geometry coordinates.
674 /// See xdg_surface.set_window_geometry.
675 ///
676 /// Values set in this way are double-buffered, see wl_surface.commit.
677 ///
678 /// The compositor can use this information to allow or disallow
679 /// different states like maximize or fullscreen and draw accurate
680 /// animations.
681 ///
682 /// Similarly, a tiling window manager may use this information to
683 /// place and resize client windows in a more effective way.
684 ///
685 /// The client should not rely on the compositor to obey the minimum
686 /// size. The compositor may decide to ignore the values set by the
687 /// client and request a smaller size.
688 ///
689 /// If never set, or a value of zero in the request, means that the
690 /// client has no expected minimum size in the given dimension.
691 /// As a result, a client wishing to reset the minimum size
692 /// to an unspecified state can use zero for width and height in the
693 /// request.
694 ///
695 /// Requesting a minimum size to be larger than the maximum size of
696 /// a surface is illegal and will result in an invalid_size error.
697 ///
698 /// The width and height must be greater than or equal to zero. Using
699 /// strictly negative values for width and height will result in a
700 /// invalid_size error.
701 ///
702 /// # Arguments
703 ///
704 /// - `width`:
705 /// - `height`:
706 #[inline]
707 pub fn set_min_size(&self, width: i32, height: i32) {
708 let (arg0, arg1) = (width, height);
709 let mut args = [wl_argument { i: arg0 }, wl_argument { i: arg1 }];
710 // SAFETY: - self.proxy has the interface INTERFACE
711 // - 8 < INTERFACE.method_count = 14
712 // - the request signature is `ii`
713 unsafe {
714 self.proxy.send_request(8, &mut args);
715 }
716 }
717
718 /// maximize the window
719 ///
720 /// Maximize the surface.
721 ///
722 /// After requesting that the surface should be maximized, the compositor
723 /// will respond by emitting a configure event. Whether this configure
724 /// actually sets the window maximized is subject to compositor policies.
725 /// The client must then update its content, drawing in the configured
726 /// state. The client must also acknowledge the configure when committing
727 /// the new content (see ack_configure).
728 ///
729 /// It is up to the compositor to decide how and where to maximize the
730 /// surface, for example which output and what region of the screen should
731 /// be used.
732 ///
733 /// If the surface was already maximized, the compositor will still emit
734 /// a configure event with the "maximized" state.
735 ///
736 /// If the surface is in a fullscreen state, this request has no direct
737 /// effect. It may alter the state the surface is returned to when
738 /// unmaximized unless overridden by the compositor.
739 #[inline]
740 pub fn set_maximized(&self) {
741 let mut args = [];
742 // SAFETY: - self.proxy has the interface INTERFACE
743 // - 9 < INTERFACE.method_count = 14
744 // - the request signature is ``
745 unsafe {
746 self.proxy.send_request(9, &mut args);
747 }
748 }
749
750 /// unmaximize the window
751 ///
752 /// Unmaximize the surface.
753 ///
754 /// After requesting that the surface should be unmaximized, the compositor
755 /// will respond by emitting a configure event. Whether this actually
756 /// un-maximizes the window is subject to compositor policies.
757 /// If available and applicable, the compositor will include the window
758 /// geometry dimensions the window had prior to being maximized in the
759 /// configure event. The client must then update its content, drawing it in
760 /// the configured state. The client must also acknowledge the configure
761 /// when committing the new content (see ack_configure).
762 ///
763 /// It is up to the compositor to position the surface after it was
764 /// unmaximized; usually the position the surface had before maximizing, if
765 /// applicable.
766 ///
767 /// If the surface was already not maximized, the compositor will still
768 /// emit a configure event without the "maximized" state.
769 ///
770 /// If the surface is in a fullscreen state, this request has no direct
771 /// effect. It may alter the state the surface is returned to when
772 /// unmaximized unless overridden by the compositor.
773 #[inline]
774 pub fn unset_maximized(&self) {
775 let mut args = [];
776 // SAFETY: - self.proxy has the interface INTERFACE
777 // - 10 < INTERFACE.method_count = 14
778 // - the request signature is ``
779 unsafe {
780 self.proxy.send_request(10, &mut args);
781 }
782 }
783
784 /// set the window as fullscreen on an output
785 ///
786 /// Make the surface fullscreen.
787 ///
788 /// After requesting that the surface should be fullscreened, the
789 /// compositor will respond by emitting a configure event. Whether the
790 /// client is actually put into a fullscreen state is subject to compositor
791 /// policies. The client must also acknowledge the configure when
792 /// committing the new content (see ack_configure).
793 ///
794 /// The output passed by the request indicates the client's preference as
795 /// to which display it should be set fullscreen on. If this value is NULL,
796 /// it's up to the compositor to choose which display will be used to map
797 /// this surface.
798 ///
799 /// If the surface doesn't cover the whole output, the compositor will
800 /// position the surface in the center of the output and compensate with
801 /// with border fill covering the rest of the output. The content of the
802 /// border fill is undefined, but should be assumed to be in some way that
803 /// attempts to blend into the surrounding area (e.g. solid black).
804 ///
805 /// If the fullscreened surface is not opaque, the compositor must make
806 /// sure that other screen content not part of the same surface tree (made
807 /// up of subsurfaces, popups or similarly coupled surfaces) are not
808 /// visible below the fullscreened surface.
809 ///
810 /// # Arguments
811 ///
812 /// - `output`:
813 #[inline]
814 pub fn set_fullscreen(&self, output: Option<&WlOutputRef>) {
815 let (arg0,) = (output,);
816 let obj0_lock = arg0.map(|arg0| proxy::lock(arg0));
817 let obj0 = obj0_lock
818 .map(|obj0_lock| check_argument_proxy("output", obj0_lock.wl_proxy()))
819 .unwrap_or(ptr::null_mut());
820 let mut args = [wl_argument { o: obj0 }];
821 // SAFETY: - self.proxy has the interface INTERFACE
822 // - 11 < INTERFACE.method_count = 14
823 // - the request signature is `?o`
824 unsafe {
825 self.proxy.send_request(11, &mut args);
826 }
827 }
828
829 /// unset the window as fullscreen
830 ///
831 /// Make the surface no longer fullscreen.
832 ///
833 /// After requesting that the surface should be unfullscreened, the
834 /// compositor will respond by emitting a configure event.
835 /// Whether this actually removes the fullscreen state of the client is
836 /// subject to compositor policies.
837 ///
838 /// Making a surface unfullscreen sets states for the surface based on the following:
839 /// * the state(s) it may have had before becoming fullscreen
840 /// * any state(s) decided by the compositor
841 /// * any state(s) requested by the client while the surface was fullscreen
842 ///
843 /// The compositor may include the previous window geometry dimensions in
844 /// the configure event, if applicable.
845 ///
846 /// The client must also acknowledge the configure when committing the new
847 /// content (see ack_configure).
848 #[inline]
849 pub fn unset_fullscreen(&self) {
850 let mut args = [];
851 // SAFETY: - self.proxy has the interface INTERFACE
852 // - 12 < INTERFACE.method_count = 14
853 // - the request signature is ``
854 unsafe {
855 self.proxy.send_request(12, &mut args);
856 }
857 }
858
859 /// set the window as minimized
860 ///
861 /// Request that the compositor minimize your surface. There is no
862 /// way to know if the surface is currently minimized, nor is there
863 /// any way to unset minimization on this surface.
864 ///
865 /// If you are looking to throttle redrawing when minimized, please
866 /// instead use the wl_surface.frame event for this, as this will
867 /// also work with live previews on windows in Alt-Tab, Expose or
868 /// similar compositor features.
869 #[inline]
870 pub fn set_minimized(&self) {
871 let mut args = [];
872 // SAFETY: - self.proxy has the interface INTERFACE
873 // - 13 < INTERFACE.method_count = 14
874 // - the request signature is ``
875 unsafe {
876 self.proxy.send_request(13, &mut args);
877 }
878 }
879}
880
881impl XdgToplevel {
882 /// Since when the configure event is available.
883 #[allow(dead_code)]
884 pub const EVT__CONFIGURE__SINCE: u32 = 1;
885
886 /// Since when the close event is available.
887 #[allow(dead_code)]
888 pub const EVT__CLOSE__SINCE: u32 = 1;
889
890 /// Since when the configure_bounds event is available.
891 #[allow(dead_code)]
892 pub const EVT__CONFIGURE_BOUNDS__SINCE: u32 = 4;
893
894 /// Since when the wm_capabilities event is available.
895 #[allow(dead_code)]
896 pub const EVT__WM_CAPABILITIES__SINCE: u32 = 5;
897}
898
899/// An event handler for [XdgToplevel] proxies.
900#[allow(dead_code)]
901pub trait XdgToplevelEventHandler {
902 /// suggest a surface change
903 ///
904 /// This configure event asks the client to resize its toplevel surface or
905 /// to change its state. The configured state should not be applied
906 /// immediately. See xdg_surface.configure for details.
907 ///
908 /// The width and height arguments specify a hint to the window
909 /// about how its surface should be resized in window geometry
910 /// coordinates. See set_window_geometry.
911 ///
912 /// If the width or height arguments are zero, it means the client
913 /// should decide its own window dimension. This may happen when the
914 /// compositor needs to configure the state of the surface but doesn't
915 /// have any information about any previous or expected dimension.
916 ///
917 /// The states listed in the event specify how the width/height
918 /// arguments should be interpreted, and possibly how it should be
919 /// drawn.
920 ///
921 /// Clients must send an ack_configure in response to this event. See
922 /// xdg_surface.configure and xdg_surface.ack_configure for details.
923 ///
924 /// # Arguments
925 ///
926 /// - `width`:
927 /// - `height`:
928 /// - `states`:
929 #[inline]
930 fn configure(&self, _slf: &XdgToplevelRef, width: i32, height: i32, states: &[u8]) {
931 let _ = width;
932 let _ = height;
933 let _ = states;
934 }
935
936 /// surface wants to be closed
937 ///
938 /// The close event is sent by the compositor when the user
939 /// wants the surface to be closed. This should be equivalent to
940 /// the user clicking the close button in client-side decorations,
941 /// if your application has any.
942 ///
943 /// This is only a request that the user intends to close the
944 /// window. The client may choose to ignore this request, or show
945 /// a dialog to ask the user to save their data, etc.
946 #[inline]
947 fn close(&self, _slf: &XdgToplevelRef) {}
948
949 /// recommended window geometry bounds
950 ///
951 /// The configure_bounds event may be sent prior to a xdg_toplevel.configure
952 /// event to communicate the bounds a window geometry size is recommended
953 /// to constrain to.
954 ///
955 /// The passed width and height are in surface coordinate space. If width
956 /// and height are 0, it means bounds is unknown and equivalent to as if no
957 /// configure_bounds event was ever sent for this surface.
958 ///
959 /// The bounds can for example correspond to the size of a monitor excluding
960 /// any panels or other shell components, so that a surface isn't created in
961 /// a way that it cannot fit.
962 ///
963 /// The bounds may change at any point, and in such a case, a new
964 /// xdg_toplevel.configure_bounds will be sent, followed by
965 /// xdg_toplevel.configure and xdg_surface.configure.
966 ///
967 /// # Arguments
968 ///
969 /// - `width`:
970 /// - `height`:
971 #[inline]
972 fn configure_bounds(&self, _slf: &XdgToplevelRef, width: i32, height: i32) {
973 let _ = width;
974 let _ = height;
975 }
976
977 /// compositor capabilities
978 ///
979 /// This event advertises the capabilities supported by the compositor. If
980 /// a capability isn't supported, clients should hide or disable the UI
981 /// elements that expose this functionality. For instance, if the
982 /// compositor doesn't advertise support for minimized toplevels, a button
983 /// triggering the set_minimized request should not be displayed.
984 ///
985 /// The compositor will ignore requests it doesn't support. For instance,
986 /// a compositor which doesn't advertise support for minimized will ignore
987 /// set_minimized requests.
988 ///
989 /// Compositors must send this event once before the first
990 /// xdg_surface.configure event. When the capabilities change, compositors
991 /// must send this event again and then send an xdg_surface.configure
992 /// event.
993 ///
994 /// The configured state should not be applied immediately. See
995 /// xdg_surface.configure for details.
996 ///
997 /// The capabilities are sent as an array of 32-bit unsigned integers in
998 /// native endianness.
999 ///
1000 /// # Arguments
1001 ///
1002 /// - `capabilities`: array of 32-bit capabilities
1003 #[inline]
1004 fn wm_capabilities(&self, _slf: &XdgToplevelRef, capabilities: &[u8]) {
1005 let _ = capabilities;
1006 }
1007}
1008
1009impl XdgToplevelEventHandler for private::NoOpEventHandler {}
1010
1011// SAFETY: - INTERFACE is a valid wl_interface
1012unsafe impl<H> EventHandler for private::EventHandler<H>
1013where
1014 H: XdgToplevelEventHandler,
1015{
1016 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
1017
1018 #[allow(unused_variables)]
1019 unsafe fn handle_event(
1020 &self,
1021 queue: &Queue,
1022 data: *mut u8,
1023 slf: &UntypedBorrowedProxy,
1024 opcode: u32,
1025 args: *mut wl_argument,
1026 ) {
1027 // SAFETY: This function requires that slf has the interface INTERFACE
1028 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<XdgToplevelRef>(slf) };
1029 match opcode {
1030 0 => {
1031 // SAFETY: INTERFACE requires that there are 3 arguments
1032 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
1033 // SAFETY: - INTERFACE requires that args[0] contains an int
1034 let arg0 = unsafe { args[0].i };
1035 // SAFETY: - INTERFACE requires that args[1] contains an int
1036 let arg1 = unsafe { args[1].i };
1037 // SAFETY: - INTERFACE requires that args[2] contains an array
1038 let arg2 = unsafe {
1039 let a = &*args[2].a;
1040 std::slice::from_raw_parts(a.data.cast(), a.size)
1041 };
1042 self.0.configure(slf, arg0, arg1, arg2);
1043 }
1044 1 => {
1045 self.0.close(slf);
1046 }
1047 2 => {
1048 // SAFETY: INTERFACE requires that there are 2 arguments
1049 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
1050 // SAFETY: - INTERFACE requires that args[0] contains an int
1051 let arg0 = unsafe { args[0].i };
1052 // SAFETY: - INTERFACE requires that args[1] contains an int
1053 let arg1 = unsafe { args[1].i };
1054 self.0.configure_bounds(slf, arg0, arg1);
1055 }
1056 3 => {
1057 // SAFETY: INTERFACE requires that there are 1 arguments
1058 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
1059 // SAFETY: - INTERFACE requires that args[0] contains an array
1060 let arg0 = unsafe {
1061 let a = &*args[0].a;
1062 std::slice::from_raw_parts(a.data.cast(), a.size)
1063 };
1064 self.0.wm_capabilities(slf, arg0);
1065 }
1066 _ => {
1067 invalid_opcode("xdg_toplevel", opcode);
1068 }
1069 }
1070 }
1071}
1072
1073impl<H> CreateEventHandler<H> for private::ProxyApi
1074where
1075 H: XdgToplevelEventHandler,
1076{
1077 type EventHandler = private::EventHandler<H>;
1078
1079 #[inline]
1080 fn create_event_handler(handler: H) -> Self::EventHandler {
1081 private::EventHandler(handler)
1082 }
1083}
1084
1085impl XdgToplevel {
1086 /// Since when the error.invalid_resize_edge enum variant is available.
1087 #[allow(dead_code)]
1088 pub const ENM__ERROR_INVALID_RESIZE_EDGE__SINCE: u32 = 1;
1089 /// Since when the error.invalid_parent enum variant is available.
1090 #[allow(dead_code)]
1091 pub const ENM__ERROR_INVALID_PARENT__SINCE: u32 = 1;
1092 /// Since when the error.invalid_size enum variant is available.
1093 #[allow(dead_code)]
1094 pub const ENM__ERROR_INVALID_SIZE__SINCE: u32 = 1;
1095
1096 /// Since when the resize_edge.none enum variant is available.
1097 #[allow(dead_code)]
1098 pub const ENM__RESIZE_EDGE_NONE__SINCE: u32 = 1;
1099 /// Since when the resize_edge.top enum variant is available.
1100 #[allow(dead_code)]
1101 pub const ENM__RESIZE_EDGE_TOP__SINCE: u32 = 1;
1102 /// Since when the resize_edge.bottom enum variant is available.
1103 #[allow(dead_code)]
1104 pub const ENM__RESIZE_EDGE_BOTTOM__SINCE: u32 = 1;
1105 /// Since when the resize_edge.left enum variant is available.
1106 #[allow(dead_code)]
1107 pub const ENM__RESIZE_EDGE_LEFT__SINCE: u32 = 1;
1108 /// Since when the resize_edge.top_left enum variant is available.
1109 #[allow(dead_code)]
1110 pub const ENM__RESIZE_EDGE_TOP_LEFT__SINCE: u32 = 1;
1111 /// Since when the resize_edge.bottom_left enum variant is available.
1112 #[allow(dead_code)]
1113 pub const ENM__RESIZE_EDGE_BOTTOM_LEFT__SINCE: u32 = 1;
1114 /// Since when the resize_edge.right enum variant is available.
1115 #[allow(dead_code)]
1116 pub const ENM__RESIZE_EDGE_RIGHT__SINCE: u32 = 1;
1117 /// Since when the resize_edge.top_right enum variant is available.
1118 #[allow(dead_code)]
1119 pub const ENM__RESIZE_EDGE_TOP_RIGHT__SINCE: u32 = 1;
1120 /// Since when the resize_edge.bottom_right enum variant is available.
1121 #[allow(dead_code)]
1122 pub const ENM__RESIZE_EDGE_BOTTOM_RIGHT__SINCE: u32 = 1;
1123
1124 /// Since when the state.maximized enum variant is available.
1125 #[allow(dead_code)]
1126 pub const ENM__STATE_MAXIMIZED__SINCE: u32 = 1;
1127 /// Since when the state.fullscreen enum variant is available.
1128 #[allow(dead_code)]
1129 pub const ENM__STATE_FULLSCREEN__SINCE: u32 = 1;
1130 /// Since when the state.resizing enum variant is available.
1131 #[allow(dead_code)]
1132 pub const ENM__STATE_RESIZING__SINCE: u32 = 1;
1133 /// Since when the state.activated enum variant is available.
1134 #[allow(dead_code)]
1135 pub const ENM__STATE_ACTIVATED__SINCE: u32 = 1;
1136 /// Since when the state.tiled_left enum variant is available.
1137 #[allow(dead_code)]
1138 pub const ENM__STATE_TILED_LEFT__SINCE: u32 = 2;
1139 /// Since when the state.tiled_right enum variant is available.
1140 #[allow(dead_code)]
1141 pub const ENM__STATE_TILED_RIGHT__SINCE: u32 = 2;
1142 /// Since when the state.tiled_top enum variant is available.
1143 #[allow(dead_code)]
1144 pub const ENM__STATE_TILED_TOP__SINCE: u32 = 2;
1145 /// Since when the state.tiled_bottom enum variant is available.
1146 #[allow(dead_code)]
1147 pub const ENM__STATE_TILED_BOTTOM__SINCE: u32 = 2;
1148 /// Since when the state.suspended enum variant is available.
1149 #[allow(dead_code)]
1150 pub const ENM__STATE_SUSPENDED__SINCE: u32 = 6;
1151
1152 /// Since when the wm_capabilities.window_menu enum variant is available.
1153 #[allow(dead_code)]
1154 pub const ENM__WM_CAPABILITIES_WINDOW_MENU__SINCE: u32 = 1;
1155 /// Since when the wm_capabilities.maximize enum variant is available.
1156 #[allow(dead_code)]
1157 pub const ENM__WM_CAPABILITIES_MAXIMIZE__SINCE: u32 = 1;
1158 /// Since when the wm_capabilities.fullscreen enum variant is available.
1159 #[allow(dead_code)]
1160 pub const ENM__WM_CAPABILITIES_FULLSCREEN__SINCE: u32 = 1;
1161 /// Since when the wm_capabilities.minimize enum variant is available.
1162 #[allow(dead_code)]
1163 pub const ENM__WM_CAPABILITIES_MINIMIZE__SINCE: u32 = 1;
1164}
1165
1166#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1167#[allow(dead_code)]
1168pub struct XdgToplevelError(pub u32);
1169
1170impl XdgToplevelError {
1171 /// provided value is not a valid variant of the resize_edge enum
1172 #[allow(dead_code)]
1173 pub const INVALID_RESIZE_EDGE: Self = Self(0);
1174
1175 /// invalid parent toplevel
1176 #[allow(dead_code)]
1177 pub const INVALID_PARENT: Self = Self(1);
1178
1179 /// client provided an invalid min or max size
1180 #[allow(dead_code)]
1181 pub const INVALID_SIZE: Self = Self(2);
1182}
1183
1184impl Debug for XdgToplevelError {
1185 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1186 let name = match *self {
1187 Self::INVALID_RESIZE_EDGE => "INVALID_RESIZE_EDGE",
1188 Self::INVALID_PARENT => "INVALID_PARENT",
1189 Self::INVALID_SIZE => "INVALID_SIZE",
1190 _ => return Debug::fmt(&self.0, f),
1191 };
1192 f.write_str(name)
1193 }
1194}
1195
1196/// edge values for resizing
1197///
1198/// These values are used to indicate which edge of a surface
1199/// is being dragged in a resize operation.
1200#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1201#[allow(dead_code)]
1202pub struct XdgToplevelResizeEdge(pub u32);
1203
1204impl XdgToplevelResizeEdge {
1205 #[allow(dead_code)]
1206 pub const NONE: Self = Self(0);
1207
1208 #[allow(dead_code)]
1209 pub const TOP: Self = Self(1);
1210
1211 #[allow(dead_code)]
1212 pub const BOTTOM: Self = Self(2);
1213
1214 #[allow(dead_code)]
1215 pub const LEFT: Self = Self(4);
1216
1217 #[allow(dead_code)]
1218 pub const TOP_LEFT: Self = Self(5);
1219
1220 #[allow(dead_code)]
1221 pub const BOTTOM_LEFT: Self = Self(6);
1222
1223 #[allow(dead_code)]
1224 pub const RIGHT: Self = Self(8);
1225
1226 #[allow(dead_code)]
1227 pub const TOP_RIGHT: Self = Self(9);
1228
1229 #[allow(dead_code)]
1230 pub const BOTTOM_RIGHT: Self = Self(10);
1231}
1232
1233impl Debug for XdgToplevelResizeEdge {
1234 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1235 let name = match *self {
1236 Self::NONE => "NONE",
1237 Self::TOP => "TOP",
1238 Self::BOTTOM => "BOTTOM",
1239 Self::LEFT => "LEFT",
1240 Self::TOP_LEFT => "TOP_LEFT",
1241 Self::BOTTOM_LEFT => "BOTTOM_LEFT",
1242 Self::RIGHT => "RIGHT",
1243 Self::TOP_RIGHT => "TOP_RIGHT",
1244 Self::BOTTOM_RIGHT => "BOTTOM_RIGHT",
1245 _ => return Debug::fmt(&self.0, f),
1246 };
1247 f.write_str(name)
1248 }
1249}
1250
1251/// types of state on the surface
1252///
1253/// The different state values used on the surface. This is designed for
1254/// state values like maximized, fullscreen. It is paired with the
1255/// configure event to ensure that both the client and the compositor
1256/// setting the state can be synchronized.
1257///
1258/// States set in this way are double-buffered, see wl_surface.commit.
1259#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1260#[allow(dead_code)]
1261pub struct XdgToplevelState(pub u32);
1262
1263impl XdgToplevelState {
1264 /// the surface is maximized
1265 ///
1266 /// the surface is maximized
1267 ///
1268 /// The surface is maximized. The window geometry specified in the configure
1269 /// event must be obeyed by the client, or the xdg_wm_base.invalid_surface_state
1270 /// error is raised.
1271 ///
1272 /// The client should draw without shadow or other
1273 /// decoration outside of the window geometry.
1274 #[allow(dead_code)]
1275 pub const MAXIMIZED: Self = Self(1);
1276
1277 /// the surface is fullscreen
1278 ///
1279 /// the surface is fullscreen
1280 ///
1281 /// The surface is fullscreen. The window geometry specified in the
1282 /// configure event is a maximum; the client cannot resize beyond it. For
1283 /// a surface to cover the whole fullscreened area, the geometry
1284 /// dimensions must be obeyed by the client. For more details, see
1285 /// xdg_toplevel.set_fullscreen.
1286 #[allow(dead_code)]
1287 pub const FULLSCREEN: Self = Self(2);
1288
1289 /// the surface is being resized
1290 ///
1291 /// the surface is being resized
1292 ///
1293 /// The surface is being resized. The window geometry specified in the
1294 /// configure event is a maximum; the client cannot resize beyond it.
1295 /// Clients that have aspect ratio or cell sizing configuration can use
1296 /// a smaller size, however.
1297 #[allow(dead_code)]
1298 pub const RESIZING: Self = Self(3);
1299
1300 /// the surface is now activated
1301 ///
1302 /// the surface is now activated
1303 ///
1304 /// Client window decorations should be painted as if the window is
1305 /// active. Do not assume this means that the window actually has
1306 /// keyboard or pointer focus.
1307 #[allow(dead_code)]
1308 pub const ACTIVATED: Self = Self(4);
1309
1310 /// the surface’s left edge is tiled
1311 ///
1312 /// The window is currently in a tiled layout and the left edge is
1313 /// considered to be adjacent to another part of the tiling grid.
1314 ///
1315 /// The client should draw without shadow or other decoration outside of
1316 /// the window geometry on the left edge.
1317 #[allow(dead_code)]
1318 pub const TILED_LEFT: Self = Self(5);
1319
1320 /// the surface’s right edge is tiled
1321 ///
1322 /// The window is currently in a tiled layout and the right edge is
1323 /// considered to be adjacent to another part of the tiling grid.
1324 ///
1325 /// The client should draw without shadow or other decoration outside of
1326 /// the window geometry on the right edge.
1327 #[allow(dead_code)]
1328 pub const TILED_RIGHT: Self = Self(6);
1329
1330 /// the surface’s top edge is tiled
1331 ///
1332 /// The window is currently in a tiled layout and the top edge is
1333 /// considered to be adjacent to another part of the tiling grid.
1334 ///
1335 /// The client should draw without shadow or other decoration outside of
1336 /// the window geometry on the top edge.
1337 #[allow(dead_code)]
1338 pub const TILED_TOP: Self = Self(7);
1339
1340 /// the surface’s bottom edge is tiled
1341 ///
1342 /// The window is currently in a tiled layout and the bottom edge is
1343 /// considered to be adjacent to another part of the tiling grid.
1344 ///
1345 /// The client should draw without shadow or other decoration outside of
1346 /// the window geometry on the bottom edge.
1347 #[allow(dead_code)]
1348 pub const TILED_BOTTOM: Self = Self(8);
1349
1350 /// surface repaint is suspended
1351 ///
1352 /// The surface is currently not ordinarily being repainted; for
1353 /// example because its content is occluded by another window, or its
1354 /// outputs are switched off due to screen locking.
1355 #[allow(dead_code)]
1356 pub const SUSPENDED: Self = Self(9);
1357}
1358
1359impl Debug for XdgToplevelState {
1360 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1361 let name = match *self {
1362 Self::MAXIMIZED => "MAXIMIZED",
1363 Self::FULLSCREEN => "FULLSCREEN",
1364 Self::RESIZING => "RESIZING",
1365 Self::ACTIVATED => "ACTIVATED",
1366 Self::TILED_LEFT => "TILED_LEFT",
1367 Self::TILED_RIGHT => "TILED_RIGHT",
1368 Self::TILED_TOP => "TILED_TOP",
1369 Self::TILED_BOTTOM => "TILED_BOTTOM",
1370 Self::SUSPENDED => "SUSPENDED",
1371 _ => return Debug::fmt(&self.0, f),
1372 };
1373 f.write_str(name)
1374 }
1375}
1376
1377#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1378#[allow(dead_code)]
1379pub struct XdgToplevelWmCapabilities(pub u32);
1380
1381impl XdgToplevelWmCapabilities {
1382 /// show_window_menu is available
1383 #[allow(dead_code)]
1384 pub const WINDOW_MENU: Self = Self(1);
1385
1386 /// set_maximized and unset_maximized are available
1387 #[allow(dead_code)]
1388 pub const MAXIMIZE: Self = Self(2);
1389
1390 /// set_fullscreen and unset_fullscreen are available
1391 #[allow(dead_code)]
1392 pub const FULLSCREEN: Self = Self(3);
1393
1394 /// set_minimized is available
1395 #[allow(dead_code)]
1396 pub const MINIMIZE: Self = Self(4);
1397}
1398
1399impl Debug for XdgToplevelWmCapabilities {
1400 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1401 let name = match *self {
1402 Self::WINDOW_MENU => "WINDOW_MENU",
1403 Self::MAXIMIZE => "MAXIMIZE",
1404 Self::FULLSCREEN => "FULLSCREEN",
1405 Self::MINIMIZE => "MINIMIZE",
1406 _ => return Debug::fmt(&self.0, f),
1407 };
1408 f.write_str(name)
1409 }
1410}
1411
1412/// Functional event handlers.
1413pub mod event_handlers {
1414 use super::*;
1415
1416 /// Event handler for configure events.
1417 pub struct Configure<F>(F);
1418 impl<F> XdgToplevelEventHandler for Configure<F>
1419 where
1420 F: Fn(&XdgToplevelRef, i32, i32, &[u8]),
1421 {
1422 #[inline]
1423 fn configure(&self, _slf: &XdgToplevelRef, width: i32, height: i32, states: &[u8]) {
1424 self.0(_slf, width, height, states)
1425 }
1426 }
1427
1428 /// Event handler for close events.
1429 pub struct Close<F>(F);
1430 impl<F> XdgToplevelEventHandler for Close<F>
1431 where
1432 F: Fn(&XdgToplevelRef),
1433 {
1434 #[inline]
1435 fn close(&self, _slf: &XdgToplevelRef) {
1436 self.0(_slf)
1437 }
1438 }
1439
1440 /// Event handler for configure_bounds events.
1441 pub struct ConfigureBounds<F>(F);
1442 impl<F> XdgToplevelEventHandler for ConfigureBounds<F>
1443 where
1444 F: Fn(&XdgToplevelRef, i32, i32),
1445 {
1446 #[inline]
1447 fn configure_bounds(&self, _slf: &XdgToplevelRef, width: i32, height: i32) {
1448 self.0(_slf, width, height)
1449 }
1450 }
1451
1452 /// Event handler for wm_capabilities events.
1453 pub struct WmCapabilities<F>(F);
1454 impl<F> XdgToplevelEventHandler for WmCapabilities<F>
1455 where
1456 F: Fn(&XdgToplevelRef, &[u8]),
1457 {
1458 #[inline]
1459 fn wm_capabilities(&self, _slf: &XdgToplevelRef, capabilities: &[u8]) {
1460 self.0(_slf, capabilities)
1461 }
1462 }
1463
1464 impl XdgToplevel {
1465 /// Creates an event handler for configure events.
1466 ///
1467 /// The event handler ignores all other events.
1468 #[allow(dead_code)]
1469 pub fn on_configure<F>(f: F) -> Configure<F>
1470 where
1471 F: Fn(&XdgToplevelRef, i32, i32, &[u8]),
1472 {
1473 Configure(f)
1474 }
1475
1476 /// Creates an event handler for close events.
1477 ///
1478 /// The event handler ignores all other events.
1479 #[allow(dead_code)]
1480 pub fn on_close<F>(f: F) -> Close<F>
1481 where
1482 F: Fn(&XdgToplevelRef),
1483 {
1484 Close(f)
1485 }
1486
1487 /// Creates an event handler for configure_bounds events.
1488 ///
1489 /// The event handler ignores all other events.
1490 #[allow(dead_code)]
1491 pub fn on_configure_bounds<F>(f: F) -> ConfigureBounds<F>
1492 where
1493 F: Fn(&XdgToplevelRef, i32, i32),
1494 {
1495 ConfigureBounds(f)
1496 }
1497
1498 /// Creates an event handler for wm_capabilities events.
1499 ///
1500 /// The event handler ignores all other events.
1501 #[allow(dead_code)]
1502 pub fn on_wm_capabilities<F>(f: F) -> WmCapabilities<F>
1503 where
1504 F: Fn(&XdgToplevelRef, &[u8]),
1505 {
1506 WmCapabilities(f)
1507 }
1508 }
1509}