libadwaita/auto/application.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::{StyleManager, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// A base class for Adwaita applications.
16 ///
17 /// [`Application`][crate::Application] handles library initialization by calling [`init()`][crate::init()] in the
18 /// default [`startup`][struct@crate::gio::Application#startup] signal handler, in turn chaining up
19 /// as required by [`gtk::Application`][crate::gtk::Application]. Therefore, any subclass of
20 /// [`Application`][crate::Application] should always chain up its `startup` handler before using
21 /// any Adwaita or GTK API.
22 ///
23 /// ## Automatic Resources
24 ///
25 /// [`Application`][crate::Application] will automatically load certain resources located in the
26 /// application's resource base path (see
27 /// [`ApplicationExtManual::set_resource_base_path()`][crate::gio::prelude::ApplicationExtManual::set_resource_base_path()], if they're present.
28 ///
29 /// ### Shortcuts Dialog
30 ///
31 /// If there's a resource located at `shortcuts-dialog.ui` which defines an
32 /// [`ShortcutsDialog`][crate::ShortcutsDialog] with the ID `shortcuts_dialog`, [`Application`][crate::Application]
33 /// will set up an `app.shortcuts` action that creates and presents this dialog,
34 /// as well as a <kbd>Ctrl</kbd><kbd>?</kbd> accelerator for it.
35 ///
36 /// ### Stylesheet
37 ///
38 /// If there's a resource located at `style.css`, [`Application`][crate::Application] will load
39 /// styles from it. This can be used to add custom styles to the application.
40 ///
41 /// #### Additional styles (deprecated)
42 ///
43 /// [`Application`][crate::Application] will also load the following stylesheets conditionally:
44 ///
45 /// - `style-dark.css` when [`dark`][struct@crate::StyleManager#dark] is `TRUE`.
46 ///
47 /// - `style-hc.css` when the system high contrast preference is enabled.
48 ///
49 /// - `style-hc-dark.css` when the system high contrast preference is enabled and
50 /// [`dark`][struct@crate::StyleManager#dark] is `TRUE`.
51 ///
52 /// :::warning
53 /// These resources are deprecated since 1.9.
54 ///
55 /// Use `style.css` with the following media queries instead:
56 ///
57 /// - `prefers-color-scheme: dark` for styles used only for dark appearance.
58 /// - `prefers-contrast: more` for styles used only when the system high
59 /// contrast preference is enabled.
60 ///
61 /// ## Properties
62 ///
63 ///
64 /// #### `style-manager`
65 /// The style manager for this application.
66 ///
67 /// This is a convenience property allowing to access [`StyleManager`][crate::StyleManager] through
68 /// property bindings or expressions.
69 ///
70 /// Readable
71 /// <details><summary><h4>Application</h4></summary>
72 ///
73 ///
74 /// #### `active-window`
75 /// The currently focused window of the application.
76 ///
77 /// Readable
78 ///
79 ///
80 /// #### `autosave-interval`
81 /// The number of seconds between automatic state saves. Defaults to 15.
82 /// A value of 0 will opt out of automatic state saving.
83 ///
84 /// Readable | Writeable
85 ///
86 ///
87 /// #### `menubar`
88 /// The menu model to be used for the application's menu bar.
89 ///
90 /// Readable | Writeable
91 ///
92 ///
93 /// #### `register-session`
94 /// Set this property to true to register with the session manager.
95 ///
96 /// This will make GTK track the session state (such as the
97 /// [`screensaver-active`][struct@crate::gtk::Application#screensaver-active] property).
98 ///
99 /// Readable | Writeable
100 ///
101 ///
102 /// #### `screensaver-active`
103 /// This property is true if GTK believes that the screensaver
104 /// is currently active.
105 ///
106 /// Tracking the screensaver state is currently only supported on
107 /// Linux.
108 ///
109 /// Readable
110 ///
111 ///
112 /// #### `support-save`
113 /// Set this property to true if the application supports
114 /// state saving and restoring.
115 ///
116 /// Readable | Writeable
117 /// </details>
118 /// <details><summary><h4>Application</h4></summary>
119 ///
120 ///
121 /// #### `action-group`
122 /// The group of actions that the application exports.
123 ///
124 /// Writeable
125 ///
126 ///
127 /// #### `application-id`
128 /// The unique identifier for the application.
129 ///
130 /// Readable | Writeable | Construct
131 ///
132 ///
133 /// #### `flags`
134 /// Flags specifying the behaviour of the application.
135 ///
136 /// Readable | Writeable
137 ///
138 ///
139 /// #### `inactivity-timeout`
140 /// Time (in milliseconds) to stay alive after becoming idle.
141 ///
142 /// Readable | Writeable
143 ///
144 ///
145 /// #### `is-busy`
146 /// Whether the application is currently marked as busy through
147 /// g_application_mark_busy() or g_application_bind_busy_property().
148 ///
149 /// Readable
150 ///
151 ///
152 /// #### `is-registered`
153 /// Whether [`ApplicationExtManual::register()`][crate::gio::prelude::ApplicationExtManual::register()] has been called.
154 ///
155 /// Readable
156 ///
157 ///
158 /// #### `is-remote`
159 /// Whether this application instance is remote.
160 ///
161 /// Readable
162 ///
163 ///
164 /// #### `resource-base-path`
165 /// The base resource path for the application.
166 ///
167 /// Readable | Writeable
168 ///
169 ///
170 /// #### `version`
171 /// The human-readable version number of the application.
172 ///
173 /// Readable | Writeable
174 /// </details>
175 ///
176 /// # Implements
177 ///
178 /// [`AdwApplicationExt`][trait@crate::prelude::AdwApplicationExt], [`trait@gtk::prelude::ApplicationExt`], [`trait@gio::prelude::ApplicationExt`], [`trait@glib::ObjectExt`], [`trait@gio::prelude::ActionGroupExt`], [`trait@gio::prelude::ActionMapExt`]
179 #[doc(alias = "AdwApplication")]
180 pub struct Application(Object<ffi::AdwApplication, ffi::AdwApplicationClass>) @extends gtk::Application, gio::Application, @implements gio::ActionGroup, gio::ActionMap;
181
182 match fn {
183 type_ => || ffi::adw_application_get_type(),
184 }
185}
186
187impl Application {
188 pub const NONE: Option<&'static Application> = None;
189
190 // rustdoc-stripper-ignore-next
191 /// Creates a new builder-pattern struct instance to construct [`Application`] objects.
192 ///
193 /// This method returns an instance of [`ApplicationBuilder`](crate::builders::ApplicationBuilder) which can be used to create [`Application`] objects.
194 pub fn builder() -> ApplicationBuilder {
195 ApplicationBuilder::new()
196 }
197}
198
199// rustdoc-stripper-ignore-next
200/// A [builder-pattern] type to construct [`Application`] objects.
201///
202/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
203#[must_use = "The builder must be built to be used"]
204pub struct ApplicationBuilder {
205 builder: glib::object::ObjectBuilder<'static, Application>,
206}
207
208impl ApplicationBuilder {
209 fn new() -> Self {
210 Self {
211 builder: glib::object::Object::builder(),
212 }
213 }
214
215 /// The number of seconds between automatic state saves. Defaults to 15.
216 /// A value of 0 will opt out of automatic state saving.
217 #[cfg(feature = "gtk_v4_22")]
218 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_22")))]
219 pub fn autosave_interval(self, autosave_interval: u32) -> Self {
220 Self {
221 builder: self
222 .builder
223 .property("autosave-interval", autosave_interval),
224 }
225 }
226
227 /// The menu model to be used for the application's menu bar.
228 pub fn menubar(self, menubar: &impl IsA<gio::MenuModel>) -> Self {
229 Self {
230 builder: self.builder.property("menubar", menubar.clone().upcast()),
231 }
232 }
233
234 /// Set this property to true to register with the session manager.
235 ///
236 /// This will make GTK track the session state (such as the
237 /// [`screensaver-active`][struct@crate::gtk::Application#screensaver-active] property).
238 /// This property is ignored. GTK always registers
239 /// with the session manager
240 #[cfg_attr(feature = "gtk_v4_22", deprecated = "Since 4.22")]
241 pub fn register_session(self, register_session: bool) -> Self {
242 Self {
243 builder: self.builder.property("register-session", register_session),
244 }
245 }
246
247 /// Set this property to true if the application supports
248 /// state saving and restoring.
249 #[cfg(feature = "gtk_v4_22")]
250 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_22")))]
251 pub fn support_save(self, support_save: bool) -> Self {
252 Self {
253 builder: self.builder.property("support-save", support_save),
254 }
255 }
256
257 /// The unique identifier for the application.
258 pub fn application_id(self, application_id: impl Into<glib::GString>) -> Self {
259 Self {
260 builder: self
261 .builder
262 .property("application-id", application_id.into()),
263 }
264 }
265
266 /// Flags specifying the behaviour of the application.
267 pub fn flags(self, flags: gio::ApplicationFlags) -> Self {
268 Self {
269 builder: self.builder.property("flags", flags),
270 }
271 }
272
273 /// Time (in milliseconds) to stay alive after becoming idle.
274 pub fn inactivity_timeout(self, inactivity_timeout: u32) -> Self {
275 Self {
276 builder: self
277 .builder
278 .property("inactivity-timeout", inactivity_timeout),
279 }
280 }
281
282 /// The base resource path for the application.
283 pub fn resource_base_path(self, resource_base_path: impl Into<glib::GString>) -> Self {
284 Self {
285 builder: self
286 .builder
287 .property("resource-base-path", resource_base_path.into()),
288 }
289 }
290
291 /// The human-readable version number of the application.
292 #[cfg(feature = "gio_v2_80")]
293 #[cfg_attr(docsrs, doc(cfg(feature = "gio_v2_80")))]
294 pub fn version(self, version: impl Into<glib::GString>) -> Self {
295 Self {
296 builder: self.builder.property("version", version.into()),
297 }
298 }
299
300 // rustdoc-stripper-ignore-next
301 /// Build the [`Application`].
302 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
303 pub fn build(self) -> Application {
304 let ret = self.builder.build();
305 {
306 Application::register_startup_hook(&ret);
307 }
308 ret
309 }
310}
311
312/// Trait containing all [`struct@Application`] methods.
313///
314/// # Implementors
315///
316/// [`Application`][struct@crate::Application]
317pub trait AdwApplicationExt: IsA<Application> + 'static {
318 /// Gets the style manager for @self.
319 ///
320 /// This is a convenience property allowing to access [`StyleManager`][crate::StyleManager] through
321 /// property bindings or expressions.
322 ///
323 /// # Returns
324 ///
325 /// the style manager
326 #[doc(alias = "adw_application_get_style_manager")]
327 #[doc(alias = "get_style_manager")]
328 #[doc(alias = "style-manager")]
329 fn style_manager(&self) -> StyleManager {
330 unsafe {
331 from_glib_none(ffi::adw_application_get_style_manager(
332 self.as_ref().to_glib_none().0,
333 ))
334 }
335 }
336
337 #[doc(alias = "style-manager")]
338 fn connect_style_manager_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
339 unsafe extern "C" fn notify_style_manager_trampoline<
340 P: IsA<Application>,
341 F: Fn(&P) + 'static,
342 >(
343 this: *mut ffi::AdwApplication,
344 _param_spec: glib::ffi::gpointer,
345 f: glib::ffi::gpointer,
346 ) {
347 unsafe {
348 let f: &F = &*(f as *const F);
349 f(Application::from_glib_borrow(this).unsafe_cast_ref())
350 }
351 }
352 unsafe {
353 let f: Box_<F> = Box_::new(f);
354 connect_raw(
355 self.as_ptr() as *mut _,
356 c"notify::style-manager".as_ptr() as *const _,
357 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
358 notify_style_manager_trampoline::<Self, F> as *const (),
359 )),
360 Box_::into_raw(f),
361 )
362 }
363 }
364}
365
366impl<O: IsA<Application>> AdwApplicationExt for O {}