Skip to main content

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::{ApplicationInhibitFlags, Window, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
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_22", deprecated = "Since 4.22")]
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_22", deprecated = "Since 4.22")]
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_22", deprecated = "Since 4.22")]
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            unsafe {
289                let f: &F = &*(f as *const F);
290                f(Application::from_glib_borrow(this).unsafe_cast_ref())
291            }
292        }
293        unsafe {
294            let f: Box_<F> = Box_::new(f);
295            connect_raw(
296                self.as_ptr() as *mut _,
297                c"query-end".as_ptr(),
298                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
299                    query_end_trampoline::<Self, F> as *const (),
300                )),
301                Box_::into_raw(f),
302            )
303        }
304    }
305
306    #[doc(alias = "window-added")]
307    fn connect_window_added<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
308        unsafe extern "C" fn window_added_trampoline<
309            P: IsA<Application>,
310            F: Fn(&P, &Window) + 'static,
311        >(
312            this: *mut ffi::GtkApplication,
313            window: *mut ffi::GtkWindow,
314            f: glib::ffi::gpointer,
315        ) {
316            unsafe {
317                let f: &F = &*(f as *const F);
318                f(
319                    Application::from_glib_borrow(this).unsafe_cast_ref(),
320                    &from_glib_borrow(window),
321                )
322            }
323        }
324        unsafe {
325            let f: Box_<F> = Box_::new(f);
326            connect_raw(
327                self.as_ptr() as *mut _,
328                c"window-added".as_ptr(),
329                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
330                    window_added_trampoline::<Self, F> as *const (),
331                )),
332                Box_::into_raw(f),
333            )
334        }
335    }
336
337    #[doc(alias = "window-removed")]
338    fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
339        unsafe extern "C" fn window_removed_trampoline<
340            P: IsA<Application>,
341            F: Fn(&P, &Window) + 'static,
342        >(
343            this: *mut ffi::GtkApplication,
344            window: *mut ffi::GtkWindow,
345            f: glib::ffi::gpointer,
346        ) {
347            unsafe {
348                let f: &F = &*(f as *const F);
349                f(
350                    Application::from_glib_borrow(this).unsafe_cast_ref(),
351                    &from_glib_borrow(window),
352                )
353            }
354        }
355        unsafe {
356            let f: Box_<F> = Box_::new(f);
357            connect_raw(
358                self.as_ptr() as *mut _,
359                c"window-removed".as_ptr(),
360                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
361                    window_removed_trampoline::<Self, F> as *const (),
362                )),
363                Box_::into_raw(f),
364            )
365        }
366    }
367
368    #[doc(alias = "active-window")]
369    fn connect_active_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
370        unsafe extern "C" fn notify_active_window_trampoline<
371            P: IsA<Application>,
372            F: Fn(&P) + 'static,
373        >(
374            this: *mut ffi::GtkApplication,
375            _param_spec: glib::ffi::gpointer,
376            f: glib::ffi::gpointer,
377        ) {
378            unsafe {
379                let f: &F = &*(f as *const F);
380                f(Application::from_glib_borrow(this).unsafe_cast_ref())
381            }
382        }
383        unsafe {
384            let f: Box_<F> = Box_::new(f);
385            connect_raw(
386                self.as_ptr() as *mut _,
387                c"notify::active-window".as_ptr(),
388                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
389                    notify_active_window_trampoline::<Self, F> as *const (),
390                )),
391                Box_::into_raw(f),
392            )
393        }
394    }
395
396    #[doc(alias = "menubar")]
397    fn connect_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
398        unsafe extern "C" fn notify_menubar_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
399            this: *mut ffi::GtkApplication,
400            _param_spec: glib::ffi::gpointer,
401            f: glib::ffi::gpointer,
402        ) {
403            unsafe {
404                let f: &F = &*(f as *const F);
405                f(Application::from_glib_borrow(this).unsafe_cast_ref())
406            }
407        }
408        unsafe {
409            let f: Box_<F> = Box_::new(f);
410            connect_raw(
411                self.as_ptr() as *mut _,
412                c"notify::menubar".as_ptr(),
413                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
414                    notify_menubar_trampoline::<Self, F> as *const (),
415                )),
416                Box_::into_raw(f),
417            )
418        }
419    }
420
421    #[cfg_attr(feature = "v4_22", deprecated = "Since 4.22")]
422    #[doc(alias = "register-session")]
423    fn connect_register_session_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
424        unsafe extern "C" fn notify_register_session_trampoline<
425            P: IsA<Application>,
426            F: Fn(&P) + 'static,
427        >(
428            this: *mut ffi::GtkApplication,
429            _param_spec: glib::ffi::gpointer,
430            f: glib::ffi::gpointer,
431        ) {
432            unsafe {
433                let f: &F = &*(f as *const F);
434                f(Application::from_glib_borrow(this).unsafe_cast_ref())
435            }
436        }
437        unsafe {
438            let f: Box_<F> = Box_::new(f);
439            connect_raw(
440                self.as_ptr() as *mut _,
441                c"notify::register-session".as_ptr(),
442                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
443                    notify_register_session_trampoline::<Self, F> as *const (),
444                )),
445                Box_::into_raw(f),
446            )
447        }
448    }
449
450    #[doc(alias = "screensaver-active")]
451    fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
452        unsafe extern "C" fn notify_screensaver_active_trampoline<
453            P: IsA<Application>,
454            F: Fn(&P) + 'static,
455        >(
456            this: *mut ffi::GtkApplication,
457            _param_spec: glib::ffi::gpointer,
458            f: glib::ffi::gpointer,
459        ) {
460            unsafe {
461                let f: &F = &*(f as *const F);
462                f(Application::from_glib_borrow(this).unsafe_cast_ref())
463            }
464        }
465        unsafe {
466            let f: Box_<F> = Box_::new(f);
467            connect_raw(
468                self.as_ptr() as *mut _,
469                c"notify::screensaver-active".as_ptr(),
470                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
471                    notify_screensaver_active_trampoline::<Self, F> as *const (),
472                )),
473                Box_::into_raw(f),
474            )
475        }
476    }
477}
478
479impl<O: IsA<Application>> GtkApplicationExt for O {}