Skip to main content

gtk/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::{Widget, Window, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// A [`WindowGroup`][crate::WindowGroup] restricts the effect of grabs to windows
10    /// in the same group, thereby making window groups almost behave
11    /// like separate applications.
12    ///
13    /// A window can be a member in at most one window group at a time.
14    /// Windows that have not been explicitly assigned to a group are
15    /// implicitly treated like windows of the default window group.
16    ///
17    /// GtkWindowGroup objects are referenced by each window in the group,
18    /// so once you have added all windows to a GtkWindowGroup, you can drop
19    /// the initial reference to the window group with `g_object_unref()`. If the
20    /// windows in the window group are subsequently destroyed, then they will
21    /// be removed from the window group and drop their references on the window
22    /// group; when all window have been removed, the window group will be
23    /// freed.
24    ///
25    /// # Implements
26    ///
27    /// [`WindowGroupExt`][trait@crate::prelude::WindowGroupExt], [`trait@glib::ObjectExt`]
28    #[doc(alias = "GtkWindowGroup")]
29    pub struct WindowGroup(Object<ffi::GtkWindowGroup, ffi::GtkWindowGroupClass>);
30
31    match fn {
32        type_ => || ffi::gtk_window_group_get_type(),
33    }
34}
35
36impl WindowGroup {
37    pub const NONE: Option<&'static WindowGroup> = None;
38
39    /// Creates a new [`WindowGroup`][crate::WindowGroup] object. Grabs added with
40    /// [`WidgetExt::grab_add()`][crate::prelude::WidgetExt::grab_add()] only affect windows within the same [`WindowGroup`][crate::WindowGroup].
41    ///
42    /// # Returns
43    ///
44    /// a new [`WindowGroup`][crate::WindowGroup].
45    #[doc(alias = "gtk_window_group_new")]
46    pub fn new() -> WindowGroup {
47        assert_initialized_main_thread!();
48        unsafe { from_glib_full(ffi::gtk_window_group_new()) }
49    }
50}
51
52impl Default for WindowGroup {
53    fn default() -> Self {
54        Self::new()
55    }
56}
57
58/// Trait containing all [`struct@WindowGroup`] methods.
59///
60/// # Implementors
61///
62/// [`WindowGroup`][struct@crate::WindowGroup]
63pub trait WindowGroupExt: IsA<WindowGroup> + 'static {
64    /// Adds a window to a [`WindowGroup`][crate::WindowGroup].
65    /// ## `window`
66    /// the [`Window`][crate::Window] to add
67    #[doc(alias = "gtk_window_group_add_window")]
68    fn add_window(&self, window: &impl IsA<Window>) {
69        unsafe {
70            ffi::gtk_window_group_add_window(
71                self.as_ref().to_glib_none().0,
72                window.as_ref().to_glib_none().0,
73            );
74        }
75    }
76
77    /// Returns the current grab widget for `device`, or [`None`] if none.
78    /// ## `device`
79    /// a [`gdk::Device`][crate::gdk::Device]
80    ///
81    /// # Returns
82    ///
83    /// The grab widget, or [`None`]
84    #[doc(alias = "gtk_window_group_get_current_device_grab")]
85    #[doc(alias = "get_current_device_grab")]
86    fn current_device_grab(&self, device: &gdk::Device) -> Option<Widget> {
87        unsafe {
88            from_glib_none(ffi::gtk_window_group_get_current_device_grab(
89                self.as_ref().to_glib_none().0,
90                device.to_glib_none().0,
91            ))
92        }
93    }
94
95    /// Gets the current grab widget of the given group,
96    /// see [`WidgetExt::grab_add()`][crate::prelude::WidgetExt::grab_add()].
97    ///
98    /// # Returns
99    ///
100    /// the current grab widget of the group
101    #[doc(alias = "gtk_window_group_get_current_grab")]
102    #[doc(alias = "get_current_grab")]
103    fn current_grab(&self) -> Option<Widget> {
104        unsafe {
105            from_glib_none(ffi::gtk_window_group_get_current_grab(
106                self.as_ref().to_glib_none().0,
107            ))
108        }
109    }
110
111    /// Returns a list of the `GtkWindows` that belong to `self`.
112    ///
113    /// # Returns
114    ///
115    /// A
116    ///  newly-allocated list of windows inside the group.
117    #[doc(alias = "gtk_window_group_list_windows")]
118    fn list_windows(&self) -> Vec<Window> {
119        unsafe {
120            FromGlibPtrContainer::from_glib_container(ffi::gtk_window_group_list_windows(
121                self.as_ref().to_glib_none().0,
122            ))
123        }
124    }
125
126    /// Removes a window from a [`WindowGroup`][crate::WindowGroup].
127    /// ## `window`
128    /// the [`Window`][crate::Window] to remove
129    #[doc(alias = "gtk_window_group_remove_window")]
130    fn remove_window(&self, window: &impl IsA<Window>) {
131        unsafe {
132            ffi::gtk_window_group_remove_window(
133                self.as_ref().to_glib_none().0,
134                window.as_ref().to_glib_none().0,
135            );
136        }
137    }
138}
139
140impl<O: IsA<WindowGroup>> WindowGroupExt for O {}