[go: up one dir, main page]

gtk4/auto/
application.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, ApplicationInhibitFlags, Window};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GtkApplication")]
16    pub struct Application(Object<ffi::GtkApplication, ffi::GtkApplicationClass>) @extends gio::Application, @implements gio::ActionGroup, gio::ActionMap;
17
18    match fn {
19        type_ => || ffi::gtk_application_get_type(),
20    }
21}
22
23impl Application {
24    pub const NONE: Option<&'static Application> = None;
25
26    // rustdoc-stripper-ignore-next
27    /// Creates a new builder-pattern struct instance to construct [`Application`] objects.
28    ///
29    /// This method returns an instance of [`ApplicationBuilder`](crate::builders::ApplicationBuilder) which can be used to create [`Application`] objects.
30    pub fn builder() -> ApplicationBuilder {
31        ApplicationBuilder::new()
32    }
33}
34
35// rustdoc-stripper-ignore-next
36/// A [builder-pattern] type to construct [`Application`] objects.
37///
38/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
39#[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    #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
58    pub fn register_session(self, register_session: bool) -> Self {
59        Self {
60            builder: self.builder.property("register-session", register_session),
61        }
62    }
63
64    pub fn application_id(self, application_id: impl Into<glib::GString>) -> Self {
65        Self {
66            builder: self
67                .builder
68                .property("application-id", application_id.into()),
69        }
70    }
71
72    pub fn flags(self, flags: gio::ApplicationFlags) -> Self {
73        Self {
74            builder: self.builder.property("flags", flags),
75        }
76    }
77
78    pub fn inactivity_timeout(self, inactivity_timeout: u32) -> Self {
79        Self {
80            builder: self
81                .builder
82                .property("inactivity-timeout", inactivity_timeout),
83        }
84    }
85
86    pub fn resource_base_path(self, resource_base_path: impl Into<glib::GString>) -> Self {
87        Self {
88            builder: self
89                .builder
90                .property("resource-base-path", resource_base_path.into()),
91        }
92    }
93
94    #[cfg(feature = "gio_v2_80")]
95    #[cfg_attr(docsrs, doc(cfg(feature = "gio_v2_80")))]
96    pub fn version(self, version: impl Into<glib::GString>) -> Self {
97        Self {
98            builder: self.builder.property("version", version.into()),
99        }
100    }
101
102    // rustdoc-stripper-ignore-next
103    /// Build the [`Application`].
104    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
105    pub fn build(self) -> Application {
106        let ret = self.builder.build();
107        {
108            Application::register_startup_hook(&ret);
109        }
110        ret
111    }
112}
113
114pub trait GtkApplicationExt: IsA<Application> + 'static {
115    #[doc(alias = "gtk_application_add_window")]
116    fn add_window(&self, window: &impl IsA<Window>) {
117        unsafe {
118            ffi::gtk_application_add_window(
119                self.as_ref().to_glib_none().0,
120                window.as_ref().to_glib_none().0,
121            );
122        }
123    }
124
125    #[doc(alias = "gtk_application_get_accels_for_action")]
126    #[doc(alias = "get_accels_for_action")]
127    fn accels_for_action(&self, detailed_action_name: &str) -> Vec<glib::GString> {
128        unsafe {
129            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_accels_for_action(
130                self.as_ref().to_glib_none().0,
131                detailed_action_name.to_glib_none().0,
132            ))
133        }
134    }
135
136    #[doc(alias = "gtk_application_get_actions_for_accel")]
137    #[doc(alias = "get_actions_for_accel")]
138    fn actions_for_accel(&self, accel: &str) -> Vec<glib::GString> {
139        unsafe {
140            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_actions_for_accel(
141                self.as_ref().to_glib_none().0,
142                accel.to_glib_none().0,
143            ))
144        }
145    }
146
147    #[doc(alias = "gtk_application_get_active_window")]
148    #[doc(alias = "get_active_window")]
149    #[doc(alias = "active-window")]
150    fn active_window(&self) -> Option<Window> {
151        unsafe {
152            from_glib_none(ffi::gtk_application_get_active_window(
153                self.as_ref().to_glib_none().0,
154            ))
155        }
156    }
157
158    #[doc(alias = "gtk_application_get_menu_by_id")]
159    #[doc(alias = "get_menu_by_id")]
160    fn menu_by_id(&self, id: &str) -> Option<gio::Menu> {
161        unsafe {
162            from_glib_none(ffi::gtk_application_get_menu_by_id(
163                self.as_ref().to_glib_none().0,
164                id.to_glib_none().0,
165            ))
166        }
167    }
168
169    #[doc(alias = "gtk_application_get_menubar")]
170    #[doc(alias = "get_menubar")]
171    fn menubar(&self) -> Option<gio::MenuModel> {
172        unsafe {
173            from_glib_none(ffi::gtk_application_get_menubar(
174                self.as_ref().to_glib_none().0,
175            ))
176        }
177    }
178
179    #[doc(alias = "gtk_application_get_window_by_id")]
180    #[doc(alias = "get_window_by_id")]
181    fn window_by_id(&self, id: u32) -> Option<Window> {
182        unsafe {
183            from_glib_none(ffi::gtk_application_get_window_by_id(
184                self.as_ref().to_glib_none().0,
185                id,
186            ))
187        }
188    }
189
190    #[doc(alias = "gtk_application_get_windows")]
191    #[doc(alias = "get_windows")]
192    fn windows(&self) -> Vec<Window> {
193        unsafe {
194            FromGlibPtrContainer::from_glib_none(ffi::gtk_application_get_windows(
195                self.as_ref().to_glib_none().0,
196            ))
197        }
198    }
199
200    #[doc(alias = "gtk_application_inhibit")]
201    fn inhibit(
202        &self,
203        window: Option<&impl IsA<Window>>,
204        flags: ApplicationInhibitFlags,
205        reason: Option<&str>,
206    ) -> u32 {
207        unsafe {
208            ffi::gtk_application_inhibit(
209                self.as_ref().to_glib_none().0,
210                window.map(|p| p.as_ref()).to_glib_none().0,
211                flags.into_glib(),
212                reason.to_glib_none().0,
213            )
214        }
215    }
216
217    #[doc(alias = "gtk_application_list_action_descriptions")]
218    fn list_action_descriptions(&self) -> Vec<glib::GString> {
219        unsafe {
220            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_list_action_descriptions(
221                self.as_ref().to_glib_none().0,
222            ))
223        }
224    }
225
226    #[doc(alias = "gtk_application_remove_window")]
227    fn remove_window(&self, window: &impl IsA<Window>) {
228        unsafe {
229            ffi::gtk_application_remove_window(
230                self.as_ref().to_glib_none().0,
231                window.as_ref().to_glib_none().0,
232            );
233        }
234    }
235
236    #[doc(alias = "gtk_application_set_accels_for_action")]
237    fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str]) {
238        unsafe {
239            ffi::gtk_application_set_accels_for_action(
240                self.as_ref().to_glib_none().0,
241                detailed_action_name.to_glib_none().0,
242                accels.to_glib_none().0,
243            );
244        }
245    }
246
247    #[doc(alias = "gtk_application_set_menubar")]
248    #[doc(alias = "menubar")]
249    fn set_menubar(&self, menubar: Option<&impl IsA<gio::MenuModel>>) {
250        unsafe {
251            ffi::gtk_application_set_menubar(
252                self.as_ref().to_glib_none().0,
253                menubar.map(|p| p.as_ref()).to_glib_none().0,
254            );
255        }
256    }
257
258    #[doc(alias = "gtk_application_uninhibit")]
259    fn uninhibit(&self, cookie: u32) {
260        unsafe {
261            ffi::gtk_application_uninhibit(self.as_ref().to_glib_none().0, cookie);
262        }
263    }
264
265    #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
266    #[doc(alias = "register-session")]
267    fn is_register_session(&self) -> bool {
268        ObjectExt::property(self.as_ref(), "register-session")
269    }
270
271    #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
272    #[doc(alias = "register-session")]
273    fn set_register_session(&self, register_session: bool) {
274        ObjectExt::set_property(self.as_ref(), "register-session", register_session)
275    }
276
277    #[doc(alias = "screensaver-active")]
278    fn is_screensaver_active(&self) -> bool {
279        ObjectExt::property(self.as_ref(), "screensaver-active")
280    }
281
282    #[doc(alias = "query-end")]
283    fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
284        unsafe extern "C" fn query_end_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
285            this: *mut ffi::GtkApplication,
286            f: glib::ffi::gpointer,
287        ) {
288            let f: &F = &*(f as *const F);
289            f(Application::from_glib_borrow(this).unsafe_cast_ref())
290        }
291        unsafe {
292            let f: Box_<F> = Box_::new(f);
293            connect_raw(
294                self.as_ptr() as *mut _,
295                c"query-end".as_ptr() as *const _,
296                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
297                    query_end_trampoline::<Self, F> as *const (),
298                )),
299                Box_::into_raw(f),
300            )
301        }
302    }
303
304    #[doc(alias = "window-added")]
305    fn connect_window_added<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
306        unsafe extern "C" fn window_added_trampoline<
307            P: IsA<Application>,
308            F: Fn(&P, &Window) + 'static,
309        >(
310            this: *mut ffi::GtkApplication,
311            window: *mut ffi::GtkWindow,
312            f: glib::ffi::gpointer,
313        ) {
314            let f: &F = &*(f as *const F);
315            f(
316                Application::from_glib_borrow(this).unsafe_cast_ref(),
317                &from_glib_borrow(window),
318            )
319        }
320        unsafe {
321            let f: Box_<F> = Box_::new(f);
322            connect_raw(
323                self.as_ptr() as *mut _,
324                c"window-added".as_ptr() as *const _,
325                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
326                    window_added_trampoline::<Self, F> as *const (),
327                )),
328                Box_::into_raw(f),
329            )
330        }
331    }
332
333    #[doc(alias = "window-removed")]
334    fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
335        unsafe extern "C" fn window_removed_trampoline<
336            P: IsA<Application>,
337            F: Fn(&P, &Window) + 'static,
338        >(
339            this: *mut ffi::GtkApplication,
340            window: *mut ffi::GtkWindow,
341            f: glib::ffi::gpointer,
342        ) {
343            let f: &F = &*(f as *const F);
344            f(
345                Application::from_glib_borrow(this).unsafe_cast_ref(),
346                &from_glib_borrow(window),
347            )
348        }
349        unsafe {
350            let f: Box_<F> = Box_::new(f);
351            connect_raw(
352                self.as_ptr() as *mut _,
353                c"window-removed".as_ptr() as *const _,
354                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
355                    window_removed_trampoline::<Self, F> as *const (),
356                )),
357                Box_::into_raw(f),
358            )
359        }
360    }
361
362    #[doc(alias = "active-window")]
363    fn connect_active_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
364        unsafe extern "C" fn notify_active_window_trampoline<
365            P: IsA<Application>,
366            F: Fn(&P) + 'static,
367        >(
368            this: *mut ffi::GtkApplication,
369            _param_spec: glib::ffi::gpointer,
370            f: glib::ffi::gpointer,
371        ) {
372            let f: &F = &*(f as *const F);
373            f(Application::from_glib_borrow(this).unsafe_cast_ref())
374        }
375        unsafe {
376            let f: Box_<F> = Box_::new(f);
377            connect_raw(
378                self.as_ptr() as *mut _,
379                c"notify::active-window".as_ptr() as *const _,
380                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
381                    notify_active_window_trampoline::<Self, F> as *const (),
382                )),
383                Box_::into_raw(f),
384            )
385        }
386    }
387
388    #[doc(alias = "menubar")]
389    fn connect_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
390        unsafe extern "C" fn notify_menubar_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
391            this: *mut ffi::GtkApplication,
392            _param_spec: glib::ffi::gpointer,
393            f: glib::ffi::gpointer,
394        ) {
395            let f: &F = &*(f as *const F);
396            f(Application::from_glib_borrow(this).unsafe_cast_ref())
397        }
398        unsafe {
399            let f: Box_<F> = Box_::new(f);
400            connect_raw(
401                self.as_ptr() as *mut _,
402                c"notify::menubar".as_ptr() as *const _,
403                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
404                    notify_menubar_trampoline::<Self, F> as *const (),
405                )),
406                Box_::into_raw(f),
407            )
408        }
409    }
410
411    #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
412    #[doc(alias = "register-session")]
413    fn connect_register_session_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
414        unsafe extern "C" fn notify_register_session_trampoline<
415            P: IsA<Application>,
416            F: Fn(&P) + 'static,
417        >(
418            this: *mut ffi::GtkApplication,
419            _param_spec: glib::ffi::gpointer,
420            f: glib::ffi::gpointer,
421        ) {
422            let f: &F = &*(f as *const F);
423            f(Application::from_glib_borrow(this).unsafe_cast_ref())
424        }
425        unsafe {
426            let f: Box_<F> = Box_::new(f);
427            connect_raw(
428                self.as_ptr() as *mut _,
429                c"notify::register-session".as_ptr() as *const _,
430                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
431                    notify_register_session_trampoline::<Self, F> as *const (),
432                )),
433                Box_::into_raw(f),
434            )
435        }
436    }
437
438    #[doc(alias = "screensaver-active")]
439    fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
440        unsafe extern "C" fn notify_screensaver_active_trampoline<
441            P: IsA<Application>,
442            F: Fn(&P) + 'static,
443        >(
444            this: *mut ffi::GtkApplication,
445            _param_spec: glib::ffi::gpointer,
446            f: glib::ffi::gpointer,
447        ) {
448            let f: &F = &*(f as *const F);
449            f(Application::from_glib_borrow(this).unsafe_cast_ref())
450        }
451        unsafe {
452            let f: Box_<F> = Box_::new(f);
453            connect_raw(
454                self.as_ptr() as *mut _,
455                c"notify::screensaver-active".as_ptr() as *const _,
456                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
457                    notify_screensaver_active_trampoline::<Self, F> as *const (),
458                )),
459                Box_::into_raw(f),
460            )
461        }
462    }
463}
464
465impl<O: IsA<Application>> GtkApplicationExt for O {}