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    /// Creates groups of windows that 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
61/// Trait containing all [`struct@WindowGroup`] methods.
62///
63/// # Implementors
64///
65/// [`WindowGroup`][struct@crate::WindowGroup]
66pub trait WindowGroupExt: IsA<WindowGroup> + 'static {
67    /// Adds a window to a [`WindowGroup`][crate::WindowGroup].
68    /// ## `window`
69    /// the [`Window`][crate::Window] to add
70    #[doc(alias = "gtk_window_group_add_window")]
71    fn add_window(&self, window: &impl IsA<Window>) {
72        unsafe {
73            ffi::gtk_window_group_add_window(
74                self.as_ref().to_glib_none().0,
75                window.as_ref().to_glib_none().0,
76            );
77        }
78    }
79
80    /// Returns a list of the `GtkWindows` that belong to @self.
81    ///
82    /// # Returns
83    ///
84    /// A
85    ///   newly-allocated list of windows inside the group.
86    #[doc(alias = "gtk_window_group_list_windows")]
87    fn list_windows(&self) -> Vec<Window> {
88        unsafe {
89            FromGlibPtrContainer::from_glib_container(ffi::gtk_window_group_list_windows(
90                self.as_ref().to_glib_none().0,
91            ))
92        }
93    }
94
95    /// Removes a window from a [`WindowGroup`][crate::WindowGroup].
96    /// ## `window`
97    /// the [`Window`][crate::Window] to remove
98    #[doc(alias = "gtk_window_group_remove_window")]
99    fn remove_window(&self, window: &impl IsA<Window>) {
100        unsafe {
101            ffi::gtk_window_group_remove_window(
102                self.as_ref().to_glib_none().0,
103                window.as_ref().to_glib_none().0,
104            );
105        }
106    }
107}
108
109impl<O: IsA<WindowGroup>> WindowGroupExt for O {}