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};
6use glib::{prelude::*, translate::*};
7use std::fmt;
8
9glib::wrapper! {
10 /// A [`WindowGroup`][crate::WindowGroup] restricts the effect of grabs to windows
11 /// in the same group, thereby making window groups almost behave
12 /// like separate applications.
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 /// GtkWindowGroup objects are referenced by each window in the group,
19 /// so once you have added all windows to a GtkWindowGroup, 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. Grabs added with
41 /// [`WidgetExt::grab_add()`][crate::prelude::WidgetExt::grab_add()] only affect windows within the same [`WindowGroup`][crate::WindowGroup].
42 ///
43 /// # Returns
44 ///
45 /// a new [`WindowGroup`][crate::WindowGroup].
46 #[doc(alias = "gtk_window_group_new")]
47 pub fn new() -> WindowGroup {
48 assert_initialized_main_thread!();
49 unsafe { from_glib_full(ffi::gtk_window_group_new()) }
50 }
51}
52
53impl Default for WindowGroup {
54 fn default() -> Self {
55 Self::new()
56 }
57}
58
59mod sealed {
60 pub trait Sealed {}
61 impl<T: super::IsA<super::WindowGroup>> Sealed for T {}
62}
63
64/// Trait containing all [`struct@WindowGroup`] methods.
65///
66/// # Implementors
67///
68/// [`WindowGroup`][struct@crate::WindowGroup]
69pub trait WindowGroupExt: IsA<WindowGroup> + sealed::Sealed + 'static {
70 /// Adds a window to a [`WindowGroup`][crate::WindowGroup].
71 /// ## `window`
72 /// the [`Window`][crate::Window] to add
73 #[doc(alias = "gtk_window_group_add_window")]
74 fn add_window(&self, window: &impl IsA<Window>) {
75 unsafe {
76 ffi::gtk_window_group_add_window(
77 self.as_ref().to_glib_none().0,
78 window.as_ref().to_glib_none().0,
79 );
80 }
81 }
82
83 /// Returns the current grab widget for `device`, or [`None`] if none.
84 /// ## `device`
85 /// a [`gdk::Device`][crate::gdk::Device]
86 ///
87 /// # Returns
88 ///
89 /// The grab widget, or [`None`]
90 #[doc(alias = "gtk_window_group_get_current_device_grab")]
91 #[doc(alias = "get_current_device_grab")]
92 fn current_device_grab(&self, device: &gdk::Device) -> Option<Widget> {
93 unsafe {
94 from_glib_none(ffi::gtk_window_group_get_current_device_grab(
95 self.as_ref().to_glib_none().0,
96 device.to_glib_none().0,
97 ))
98 }
99 }
100
101 /// Gets the current grab widget of the given group,
102 /// see [`WidgetExt::grab_add()`][crate::prelude::WidgetExt::grab_add()].
103 ///
104 /// # Returns
105 ///
106 /// the current grab widget of the group
107 #[doc(alias = "gtk_window_group_get_current_grab")]
108 #[doc(alias = "get_current_grab")]
109 fn current_grab(&self) -> Option<Widget> {
110 unsafe {
111 from_glib_none(ffi::gtk_window_group_get_current_grab(
112 self.as_ref().to_glib_none().0,
113 ))
114 }
115 }
116
117 /// Returns a list of the `GtkWindows` that belong to `self`.
118 ///
119 /// # Returns
120 ///
121 /// A
122 /// newly-allocated list of windows inside the group.
123 #[doc(alias = "gtk_window_group_list_windows")]
124 fn list_windows(&self) -> Vec<Window> {
125 unsafe {
126 FromGlibPtrContainer::from_glib_container(ffi::gtk_window_group_list_windows(
127 self.as_ref().to_glib_none().0,
128 ))
129 }
130 }
131
132 /// Removes a window from a [`WindowGroup`][crate::WindowGroup].
133 /// ## `window`
134 /// the [`Window`][crate::Window] to remove
135 #[doc(alias = "gtk_window_group_remove_window")]
136 fn remove_window(&self, window: &impl IsA<Window>) {
137 unsafe {
138 ffi::gtk_window_group_remove_window(
139 self.as_ref().to_glib_none().0,
140 window.as_ref().to_glib_none().0,
141 );
142 }
143 }
144}
145
146impl<O: IsA<WindowGroup>> WindowGroupExt for O {}
147
148impl fmt::Display for WindowGroup {
149 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
150 f.write_str("WindowGroup")
151 }
152}