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