gtk4/auto/window_group.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Window};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// [`WindowGroup`][crate::WindowGroup] makes group of windows behave like separate applications.
10 ///
11 /// It achieves this by limiting the effect of GTK grabs and modality
12 /// to windows in the same group.
13 ///
14 /// A window can be a member in at most one window group at a time.
15 /// Windows that have not been explicitly assigned to a group are
16 /// implicitly treated like windows of the default window group.
17 ///
18 /// [`WindowGroup`][crate::WindowGroup] objects are referenced by each window in the group,
19 /// so once you have added all windows to a [`WindowGroup`][crate::WindowGroup], you can drop
20 /// the initial reference to the window group with g_object_unref(). If the
21 /// windows in the window group are subsequently destroyed, then they will
22 /// be removed from the window group and drop their references on the window
23 /// group; when all window have been removed, the window group will be
24 /// freed.
25 ///
26 /// # Implements
27 ///
28 /// [`WindowGroupExt`][trait@crate::prelude::WindowGroupExt], [`trait@glib::ObjectExt`]
29 #[doc(alias = "GtkWindowGroup")]
30 pub struct WindowGroup(Object<ffi::GtkWindowGroup, ffi::GtkWindowGroupClass>);
31
32 match fn {
33 type_ => || ffi::gtk_window_group_get_type(),
34 }
35}
36
37impl WindowGroup {
38 pub const NONE: Option<&'static WindowGroup> = None;
39
40 /// Creates a new [`WindowGroup`][crate::WindowGroup] object.
41 ///
42 /// Modality of windows only affects windows
43 /// within the same [`WindowGroup`][crate::WindowGroup].
44 ///
45 /// # Returns
46 ///
47 /// a new [`WindowGroup`][crate::WindowGroup].
48 #[doc(alias = "gtk_window_group_new")]
49 pub fn new() -> WindowGroup {
50 assert_initialized_main_thread!();
51 unsafe { from_glib_full(ffi::gtk_window_group_new()) }
52 }
53}
54
55impl Default for WindowGroup {
56 fn default() -> Self {
57 Self::new()
58 }
59}
60
61mod sealed {
62 pub trait Sealed {}
63 impl<T: super::IsA<super::WindowGroup>> Sealed for T {}
64}
65
66/// Trait containing all [`struct@WindowGroup`] methods.
67///
68/// # Implementors
69///
70/// [`WindowGroup`][struct@crate::WindowGroup]
71pub trait WindowGroupExt: IsA<WindowGroup> + sealed::Sealed + 'static {
72 /// Adds a window to a [`WindowGroup`][crate::WindowGroup].
73 /// ## `window`
74 /// the [`Window`][crate::Window] to add
75 #[doc(alias = "gtk_window_group_add_window")]
76 fn add_window(&self, window: &impl IsA<Window>) {
77 unsafe {
78 ffi::gtk_window_group_add_window(
79 self.as_ref().to_glib_none().0,
80 window.as_ref().to_glib_none().0,
81 );
82 }
83 }
84
85 /// Returns a list of the `GtkWindows` that belong to @self.
86 ///
87 /// # Returns
88 ///
89 /// A
90 /// newly-allocated list of windows inside the group.
91 #[doc(alias = "gtk_window_group_list_windows")]
92 fn list_windows(&self) -> Vec<Window> {
93 unsafe {
94 FromGlibPtrContainer::from_glib_container(ffi::gtk_window_group_list_windows(
95 self.as_ref().to_glib_none().0,
96 ))
97 }
98 }
99
100 /// Removes a window from a [`WindowGroup`][crate::WindowGroup].
101 /// ## `window`
102 /// the [`Window`][crate::Window] to remove
103 #[doc(alias = "gtk_window_group_remove_window")]
104 fn remove_window(&self, window: &impl IsA<Window>) {
105 unsafe {
106 ffi::gtk_window_group_remove_window(
107 self.as_ref().to_glib_none().0,
108 window.as_ref().to_glib_none().0,
109 );
110 }
111 }
112}
113
114impl<O: IsA<WindowGroup>> WindowGroupExt for O {}