libadwaita/auto/
application.rs1use crate::{ffi, StyleManager};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "AdwApplication")]
16 pub struct Application(Object<ffi::AdwApplication, ffi::AdwApplicationClass>) @extends gtk::Application, gio::Application, @implements gio::ActionGroup, gio::ActionMap;
17
18 match fn {
19 type_ => || ffi::adw_application_get_type(),
20 }
21}
22
23impl Application {
24 pub const NONE: Option<&'static Application> = None;
25
26 pub fn builder() -> ApplicationBuilder {
31 ApplicationBuilder::new()
32 }
33}
34
35#[must_use = "The builder must be built to be used"]
40pub struct ApplicationBuilder {
41 builder: glib::object::ObjectBuilder<'static, Application>,
42}
43
44impl ApplicationBuilder {
45 fn new() -> Self {
46 Self {
47 builder: glib::object::Object::builder(),
48 }
49 }
50
51 pub fn menubar(self, menubar: &impl IsA<gio::MenuModel>) -> Self {
52 Self {
53 builder: self.builder.property("menubar", menubar.clone().upcast()),
54 }
55 }
56
57 pub fn register_session(self, register_session: bool) -> Self {
58 Self {
59 builder: self.builder.property("register-session", register_session),
60 }
61 }
62
63 pub fn application_id(self, application_id: impl Into<glib::GString>) -> Self {
64 Self {
65 builder: self
66 .builder
67 .property("application-id", application_id.into()),
68 }
69 }
70
71 pub fn flags(self, flags: gio::ApplicationFlags) -> Self {
72 Self {
73 builder: self.builder.property("flags", flags),
74 }
75 }
76
77 pub fn inactivity_timeout(self, inactivity_timeout: u32) -> Self {
78 Self {
79 builder: self
80 .builder
81 .property("inactivity-timeout", inactivity_timeout),
82 }
83 }
84
85 pub fn resource_base_path(self, resource_base_path: impl Into<glib::GString>) -> Self {
86 Self {
87 builder: self
88 .builder
89 .property("resource-base-path", resource_base_path.into()),
90 }
91 }
92
93 #[cfg(feature = "gio_v2_80")]
94 #[cfg_attr(docsrs, doc(cfg(feature = "gio_v2_80")))]
95 pub fn version(self, version: impl Into<glib::GString>) -> Self {
96 Self {
97 builder: self.builder.property("version", version.into()),
98 }
99 }
100
101 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
104 pub fn build(self) -> Application {
105 let ret = self.builder.build();
106 {
107 Application::register_startup_hook(&ret);
108 }
109 ret
110 }
111}
112
113pub trait AdwApplicationExt: IsA<Application> + 'static {
114 #[doc(alias = "adw_application_get_style_manager")]
115 #[doc(alias = "get_style_manager")]
116 #[doc(alias = "style-manager")]
117 fn style_manager(&self) -> StyleManager {
118 unsafe {
119 from_glib_none(ffi::adw_application_get_style_manager(
120 self.as_ref().to_glib_none().0,
121 ))
122 }
123 }
124
125 #[doc(alias = "style-manager")]
126 fn connect_style_manager_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
127 unsafe extern "C" fn notify_style_manager_trampoline<
128 P: IsA<Application>,
129 F: Fn(&P) + 'static,
130 >(
131 this: *mut ffi::AdwApplication,
132 _param_spec: glib::ffi::gpointer,
133 f: glib::ffi::gpointer,
134 ) {
135 let f: &F = &*(f as *const F);
136 f(Application::from_glib_borrow(this).unsafe_cast_ref())
137 }
138 unsafe {
139 let f: Box_<F> = Box_::new(f);
140 connect_raw(
141 self.as_ptr() as *mut _,
142 c"notify::style-manager".as_ptr() as *const _,
143 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
144 notify_style_manager_trampoline::<Self, F> as *const (),
145 )),
146 Box_::into_raw(f),
147 )
148 }
149 }
150}
151
152impl<O: IsA<Application>> AdwApplicationExt for O {}