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    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    // rustdoc-stripper-ignore-next
102    /// Build the [`Application`].
103    #[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
113mod sealed {
114    pub trait Sealed {}
115    impl<T: super::IsA<super::Application>> Sealed for T {}
116}
117
118pub trait GtkApplicationExt: IsA<Application> + sealed::Sealed + 'static {
119    #[doc(alias = "gtk_application_add_window")]
120    fn add_window(&self, window: &impl IsA<Window>) {
121        unsafe {
122            ffi::gtk_application_add_window(
123                self.as_ref().to_glib_none().0,
124                window.as_ref().to_glib_none().0,
125            );
126        }
127    }
128
129    #[doc(alias = "gtk_application_get_accels_for_action")]
130    #[doc(alias = "get_accels_for_action")]
131    fn accels_for_action(&self, detailed_action_name: &str) -> Vec<glib::GString> {
132        unsafe {
133            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_accels_for_action(
134                self.as_ref().to_glib_none().0,
135                detailed_action_name.to_glib_none().0,
136            ))
137        }
138    }
139
140    #[doc(alias = "gtk_application_get_actions_for_accel")]
141    #[doc(alias = "get_actions_for_accel")]
142    fn actions_for_accel(&self, accel: &str) -> Vec<glib::GString> {
143        unsafe {
144            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_get_actions_for_accel(
145                self.as_ref().to_glib_none().0,
146                accel.to_glib_none().0,
147            ))
148        }
149    }
150
151    #[doc(alias = "gtk_application_get_active_window")]
152    #[doc(alias = "get_active_window")]
153    #[doc(alias = "active-window")]
154    fn active_window(&self) -> Option<Window> {
155        unsafe {
156            from_glib_none(ffi::gtk_application_get_active_window(
157                self.as_ref().to_glib_none().0,
158            ))
159        }
160    }
161
162    #[doc(alias = "gtk_application_get_menu_by_id")]
163    #[doc(alias = "get_menu_by_id")]
164    fn menu_by_id(&self, id: &str) -> Option<gio::Menu> {
165        unsafe {
166            from_glib_none(ffi::gtk_application_get_menu_by_id(
167                self.as_ref().to_glib_none().0,
168                id.to_glib_none().0,
169            ))
170        }
171    }
172
173    #[doc(alias = "gtk_application_get_menubar")]
174    #[doc(alias = "get_menubar")]
175    fn menubar(&self) -> Option<gio::MenuModel> {
176        unsafe {
177            from_glib_none(ffi::gtk_application_get_menubar(
178                self.as_ref().to_glib_none().0,
179            ))
180        }
181    }
182
183    #[doc(alias = "gtk_application_get_window_by_id")]
184    #[doc(alias = "get_window_by_id")]
185    fn window_by_id(&self, id: u32) -> Option<Window> {
186        unsafe {
187            from_glib_none(ffi::gtk_application_get_window_by_id(
188                self.as_ref().to_glib_none().0,
189                id,
190            ))
191        }
192    }
193
194    #[doc(alias = "gtk_application_get_windows")]
195    #[doc(alias = "get_windows")]
196    fn windows(&self) -> Vec<Window> {
197        unsafe {
198            FromGlibPtrContainer::from_glib_none(ffi::gtk_application_get_windows(
199                self.as_ref().to_glib_none().0,
200            ))
201        }
202    }
203
204    #[doc(alias = "gtk_application_inhibit")]
205    fn inhibit(
206        &self,
207        window: Option<&impl IsA<Window>>,
208        flags: ApplicationInhibitFlags,
209        reason: Option<&str>,
210    ) -> u32 {
211        unsafe {
212            ffi::gtk_application_inhibit(
213                self.as_ref().to_glib_none().0,
214                window.map(|p| p.as_ref()).to_glib_none().0,
215                flags.into_glib(),
216                reason.to_glib_none().0,
217            )
218        }
219    }
220
221    #[doc(alias = "gtk_application_list_action_descriptions")]
222    fn list_action_descriptions(&self) -> Vec<glib::GString> {
223        unsafe {
224            FromGlibPtrContainer::from_glib_full(ffi::gtk_application_list_action_descriptions(
225                self.as_ref().to_glib_none().0,
226            ))
227        }
228    }
229
230    #[doc(alias = "gtk_application_remove_window")]
231    fn remove_window(&self, window: &impl IsA<Window>) {
232        unsafe {
233            ffi::gtk_application_remove_window(
234                self.as_ref().to_glib_none().0,
235                window.as_ref().to_glib_none().0,
236            );
237        }
238    }
239
240    #[doc(alias = "gtk_application_set_accels_for_action")]
241    fn set_accels_for_action(&self, detailed_action_name: &str, accels: &[&str]) {
242        unsafe {
243            ffi::gtk_application_set_accels_for_action(
244                self.as_ref().to_glib_none().0,
245                detailed_action_name.to_glib_none().0,
246                accels.to_glib_none().0,
247            );
248        }
249    }
250
251    #[doc(alias = "gtk_application_set_menubar")]
252    #[doc(alias = "menubar")]
253    fn set_menubar(&self, menubar: Option<&impl IsA<gio::MenuModel>>) {
254        unsafe {
255            ffi::gtk_application_set_menubar(
256                self.as_ref().to_glib_none().0,
257                menubar.map(|p| p.as_ref()).to_glib_none().0,
258            );
259        }
260    }
261
262    #[doc(alias = "gtk_application_uninhibit")]
263    fn uninhibit(&self, cookie: u32) {
264        unsafe {
265            ffi::gtk_application_uninhibit(self.as_ref().to_glib_none().0, cookie);
266        }
267    }
268
269    #[doc(alias = "register-session")]
270    fn is_register_session(&self) -> bool {
271        ObjectExt::property(self.as_ref(), "register-session")
272    }
273
274    #[doc(alias = "register-session")]
275    fn set_register_session(&self, register_session: bool) {
276        ObjectExt::set_property(self.as_ref(), "register-session", register_session)
277    }
278
279    #[doc(alias = "screensaver-active")]
280    fn is_screensaver_active(&self) -> bool {
281        ObjectExt::property(self.as_ref(), "screensaver-active")
282    }
283
284    #[doc(alias = "query-end")]
285    fn connect_query_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
286        unsafe extern "C" fn query_end_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
287            this: *mut ffi::GtkApplication,
288            f: glib::ffi::gpointer,
289        ) {
290            let f: &F = &*(f as *const F);
291            f(Application::from_glib_borrow(this).unsafe_cast_ref())
292        }
293        unsafe {
294            let f: Box_<F> = Box_::new(f);
295            connect_raw(
296                self.as_ptr() as *mut _,
297                b"query-end\0".as_ptr() as *const _,
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            let f: &F = &*(f as *const F);
317            f(
318                Application::from_glib_borrow(this).unsafe_cast_ref(),
319                &from_glib_borrow(window),
320            )
321        }
322        unsafe {
323            let f: Box_<F> = Box_::new(f);
324            connect_raw(
325                self.as_ptr() as *mut _,
326                b"window-added\0".as_ptr() as *const _,
327                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
328                    window_added_trampoline::<Self, F> as *const (),
329                )),
330                Box_::into_raw(f),
331            )
332        }
333    }
334
335    #[doc(alias = "window-removed")]
336    fn connect_window_removed<F: Fn(&Self, &Window) + 'static>(&self, f: F) -> SignalHandlerId {
337        unsafe extern "C" fn window_removed_trampoline<
338            P: IsA<Application>,
339            F: Fn(&P, &Window) + 'static,
340        >(
341            this: *mut ffi::GtkApplication,
342            window: *mut ffi::GtkWindow,
343            f: glib::ffi::gpointer,
344        ) {
345            let f: &F = &*(f as *const F);
346            f(
347                Application::from_glib_borrow(this).unsafe_cast_ref(),
348                &from_glib_borrow(window),
349            )
350        }
351        unsafe {
352            let f: Box_<F> = Box_::new(f);
353            connect_raw(
354                self.as_ptr() as *mut _,
355                b"window-removed\0".as_ptr() as *const _,
356                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
357                    window_removed_trampoline::<Self, F> as *const (),
358                )),
359                Box_::into_raw(f),
360            )
361        }
362    }
363
364    #[doc(alias = "active-window")]
365    fn connect_active_window_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
366        unsafe extern "C" fn notify_active_window_trampoline<
367            P: IsA<Application>,
368            F: Fn(&P) + 'static,
369        >(
370            this: *mut ffi::GtkApplication,
371            _param_spec: glib::ffi::gpointer,
372            f: glib::ffi::gpointer,
373        ) {
374            let f: &F = &*(f as *const F);
375            f(Application::from_glib_borrow(this).unsafe_cast_ref())
376        }
377        unsafe {
378            let f: Box_<F> = Box_::new(f);
379            connect_raw(
380                self.as_ptr() as *mut _,
381                b"notify::active-window\0".as_ptr() as *const _,
382                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
383                    notify_active_window_trampoline::<Self, F> as *const (),
384                )),
385                Box_::into_raw(f),
386            )
387        }
388    }
389
390    #[doc(alias = "menubar")]
391    fn connect_menubar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
392        unsafe extern "C" fn notify_menubar_trampoline<P: IsA<Application>, F: Fn(&P) + 'static>(
393            this: *mut ffi::GtkApplication,
394            _param_spec: glib::ffi::gpointer,
395            f: glib::ffi::gpointer,
396        ) {
397            let f: &F = &*(f as *const F);
398            f(Application::from_glib_borrow(this).unsafe_cast_ref())
399        }
400        unsafe {
401            let f: Box_<F> = Box_::new(f);
402            connect_raw(
403                self.as_ptr() as *mut _,
404                b"notify::menubar\0".as_ptr() as *const _,
405                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
406                    notify_menubar_trampoline::<Self, F> as *const (),
407                )),
408                Box_::into_raw(f),
409            )
410        }
411    }
412
413    #[doc(alias = "register-session")]
414    fn connect_register_session_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
415        unsafe extern "C" fn notify_register_session_trampoline<
416            P: IsA<Application>,
417            F: Fn(&P) + 'static,
418        >(
419            this: *mut ffi::GtkApplication,
420            _param_spec: glib::ffi::gpointer,
421            f: glib::ffi::gpointer,
422        ) {
423            let f: &F = &*(f as *const F);
424            f(Application::from_glib_borrow(this).unsafe_cast_ref())
425        }
426        unsafe {
427            let f: Box_<F> = Box_::new(f);
428            connect_raw(
429                self.as_ptr() as *mut _,
430                b"notify::register-session\0".as_ptr() as *const _,
431                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
432                    notify_register_session_trampoline::<Self, F> as *const (),
433                )),
434                Box_::into_raw(f),
435            )
436        }
437    }
438
439    #[doc(alias = "screensaver-active")]
440    fn connect_screensaver_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
441        unsafe extern "C" fn notify_screensaver_active_trampoline<
442            P: IsA<Application>,
443            F: Fn(&P) + 'static,
444        >(
445            this: *mut ffi::GtkApplication,
446            _param_spec: glib::ffi::gpointer,
447            f: glib::ffi::gpointer,
448        ) {
449            let f: &F = &*(f as *const F);
450            f(Application::from_glib_borrow(this).unsafe_cast_ref())
451        }
452        unsafe {
453            let f: Box_<F> = Box_::new(f);
454            connect_raw(
455                self.as_ptr() as *mut _,
456                b"notify::screensaver-active\0".as_ptr() as *const _,
457                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
458                    notify_screensaver_active_trampoline::<Self, F> as *const (),
459                )),
460                Box_::into_raw(f),
461            )
462        }
463    }
464}
465
466impl<O: IsA<Application>> GtkApplicationExt for O {}