libadwaita/auto/
window.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::ffi;
7#[cfg(feature = "v1_4")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
9use crate::Breakpoint;
10#[cfg(feature = "v1_5")]
11#[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
12use crate::Dialog;
13use glib::{
14    prelude::*,
15    signal::{connect_raw, SignalHandlerId},
16    translate::*,
17};
18use std::boxed::Box as Box_;
19
20glib::wrapper! {
21    #[doc(alias = "AdwWindow")]
22    pub struct Window(Object<ffi::AdwWindow, ffi::AdwWindowClass>) @extends gtk::Window, gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Native, gtk::Root, gtk::ShortcutManager;
23
24    match fn {
25        type_ => || ffi::adw_window_get_type(),
26    }
27}
28
29impl Window {
30    pub const NONE: Option<&'static Window> = None;
31
32    #[doc(alias = "adw_window_new")]
33    pub fn new() -> Window {
34        assert_initialized_main_thread!();
35        unsafe { gtk::Widget::from_glib_none(ffi::adw_window_new()).unsafe_cast() }
36    }
37
38    // rustdoc-stripper-ignore-next
39    /// Creates a new builder-pattern struct instance to construct [`Window`] objects.
40    ///
41    /// This method returns an instance of [`WindowBuilder`](crate::builders::WindowBuilder) which can be used to create [`Window`] objects.
42    pub fn builder() -> WindowBuilder {
43        WindowBuilder::new()
44    }
45}
46
47impl Default for Window {
48    fn default() -> Self {
49        Self::new()
50    }
51}
52
53// rustdoc-stripper-ignore-next
54/// A [builder-pattern] type to construct [`Window`] objects.
55///
56/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
57#[must_use = "The builder must be built to be used"]
58pub struct WindowBuilder {
59    builder: glib::object::ObjectBuilder<'static, Window>,
60}
61
62impl WindowBuilder {
63    fn new() -> Self {
64        Self {
65            builder: glib::object::Object::builder(),
66        }
67    }
68
69    #[cfg(feature = "v1_7")]
70    #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
71    pub fn adaptive_preview(self, adaptive_preview: bool) -> Self {
72        Self {
73            builder: self.builder.property("adaptive-preview", adaptive_preview),
74        }
75    }
76
77    pub fn content(self, content: &impl IsA<gtk::Widget>) -> Self {
78        Self {
79            builder: self.builder.property("content", content.clone().upcast()),
80        }
81    }
82
83    pub fn application(self, application: &impl IsA<gtk::Application>) -> Self {
84        Self {
85            builder: self
86                .builder
87                .property("application", application.clone().upcast()),
88        }
89    }
90
91    pub fn decorated(self, decorated: bool) -> Self {
92        Self {
93            builder: self.builder.property("decorated", decorated),
94        }
95    }
96
97    pub fn default_height(self, default_height: i32) -> Self {
98        Self {
99            builder: self.builder.property("default-height", default_height),
100        }
101    }
102
103    pub fn default_widget(self, default_widget: &impl IsA<gtk::Widget>) -> Self {
104        Self {
105            builder: self
106                .builder
107                .property("default-widget", default_widget.clone().upcast()),
108        }
109    }
110
111    pub fn default_width(self, default_width: i32) -> Self {
112        Self {
113            builder: self.builder.property("default-width", default_width),
114        }
115    }
116
117    pub fn deletable(self, deletable: bool) -> Self {
118        Self {
119            builder: self.builder.property("deletable", deletable),
120        }
121    }
122
123    pub fn destroy_with_parent(self, destroy_with_parent: bool) -> Self {
124        Self {
125            builder: self
126                .builder
127                .property("destroy-with-parent", destroy_with_parent),
128        }
129    }
130
131    pub fn display(self, display: &gdk::Display) -> Self {
132        Self {
133            builder: self.builder.property("display", display.clone()),
134        }
135    }
136
137    pub fn focus_visible(self, focus_visible: bool) -> Self {
138        Self {
139            builder: self.builder.property("focus-visible", focus_visible),
140        }
141    }
142
143    pub fn focus_widget(self, focus_widget: &impl IsA<gtk::Widget>) -> Self {
144        Self {
145            builder: self
146                .builder
147                .property("focus-widget", focus_widget.clone().upcast()),
148        }
149    }
150
151    pub fn fullscreened(self, fullscreened: bool) -> Self {
152        Self {
153            builder: self.builder.property("fullscreened", fullscreened),
154        }
155    }
156
157    #[cfg(feature = "gtk_v4_20")]
158    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_20")))]
159    pub fn gravity(self, gravity: gtk::WindowGravity) -> Self {
160        Self {
161            builder: self.builder.property("gravity", gravity),
162        }
163    }
164
165    #[cfg(feature = "gtk_v4_2")]
166    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_2")))]
167    pub fn handle_menubar_accel(self, handle_menubar_accel: bool) -> Self {
168        Self {
169            builder: self
170                .builder
171                .property("handle-menubar-accel", handle_menubar_accel),
172        }
173    }
174
175    pub fn hide_on_close(self, hide_on_close: bool) -> Self {
176        Self {
177            builder: self.builder.property("hide-on-close", hide_on_close),
178        }
179    }
180
181    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
182        Self {
183            builder: self.builder.property("icon-name", icon_name.into()),
184        }
185    }
186
187    pub fn maximized(self, maximized: bool) -> Self {
188        Self {
189            builder: self.builder.property("maximized", maximized),
190        }
191    }
192
193    pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
194        Self {
195            builder: self
196                .builder
197                .property("mnemonics-visible", mnemonics_visible),
198        }
199    }
200
201    pub fn modal(self, modal: bool) -> Self {
202        Self {
203            builder: self.builder.property("modal", modal),
204        }
205    }
206
207    pub fn resizable(self, resizable: bool) -> Self {
208        Self {
209            builder: self.builder.property("resizable", resizable),
210        }
211    }
212
213    pub fn startup_id(self, startup_id: impl Into<glib::GString>) -> Self {
214        Self {
215            builder: self.builder.property("startup-id", startup_id.into()),
216        }
217    }
218
219    pub fn title(self, title: impl Into<glib::GString>) -> Self {
220        Self {
221            builder: self.builder.property("title", title.into()),
222        }
223    }
224
225    #[cfg(feature = "gtk_v4_6")]
226    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_6")))]
227    pub fn titlebar(self, titlebar: &impl IsA<gtk::Widget>) -> Self {
228        Self {
229            builder: self.builder.property("titlebar", titlebar.clone().upcast()),
230        }
231    }
232
233    pub fn transient_for(self, transient_for: &impl IsA<gtk::Window>) -> Self {
234        Self {
235            builder: self
236                .builder
237                .property("transient-for", transient_for.clone().upcast()),
238        }
239    }
240
241    pub fn can_focus(self, can_focus: bool) -> Self {
242        Self {
243            builder: self.builder.property("can-focus", can_focus),
244        }
245    }
246
247    pub fn can_target(self, can_target: bool) -> Self {
248        Self {
249            builder: self.builder.property("can-target", can_target),
250        }
251    }
252
253    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
254        Self {
255            builder: self.builder.property("css-classes", css_classes.into()),
256        }
257    }
258
259    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
260        Self {
261            builder: self.builder.property("css-name", css_name.into()),
262        }
263    }
264
265    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
266        Self {
267            builder: self.builder.property("cursor", cursor.clone()),
268        }
269    }
270
271    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
272        Self {
273            builder: self.builder.property("focus-on-click", focus_on_click),
274        }
275    }
276
277    pub fn focusable(self, focusable: bool) -> Self {
278        Self {
279            builder: self.builder.property("focusable", focusable),
280        }
281    }
282
283    pub fn halign(self, halign: gtk::Align) -> Self {
284        Self {
285            builder: self.builder.property("halign", halign),
286        }
287    }
288
289    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
290        Self {
291            builder: self.builder.property("has-tooltip", has_tooltip),
292        }
293    }
294
295    pub fn height_request(self, height_request: i32) -> Self {
296        Self {
297            builder: self.builder.property("height-request", height_request),
298        }
299    }
300
301    pub fn hexpand(self, hexpand: bool) -> Self {
302        Self {
303            builder: self.builder.property("hexpand", hexpand),
304        }
305    }
306
307    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
308        Self {
309            builder: self.builder.property("hexpand-set", hexpand_set),
310        }
311    }
312
313    pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
314        Self {
315            builder: self
316                .builder
317                .property("layout-manager", layout_manager.clone().upcast()),
318        }
319    }
320
321    #[cfg(feature = "gtk_v4_18")]
322    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
323    pub fn limit_events(self, limit_events: bool) -> Self {
324        Self {
325            builder: self.builder.property("limit-events", limit_events),
326        }
327    }
328
329    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
330        Self {
331            builder: self.builder.property("margin-bottom", margin_bottom),
332        }
333    }
334
335    pub fn margin_end(self, margin_end: i32) -> Self {
336        Self {
337            builder: self.builder.property("margin-end", margin_end),
338        }
339    }
340
341    pub fn margin_start(self, margin_start: i32) -> Self {
342        Self {
343            builder: self.builder.property("margin-start", margin_start),
344        }
345    }
346
347    pub fn margin_top(self, margin_top: i32) -> Self {
348        Self {
349            builder: self.builder.property("margin-top", margin_top),
350        }
351    }
352
353    pub fn name(self, name: impl Into<glib::GString>) -> Self {
354        Self {
355            builder: self.builder.property("name", name.into()),
356        }
357    }
358
359    pub fn opacity(self, opacity: f64) -> Self {
360        Self {
361            builder: self.builder.property("opacity", opacity),
362        }
363    }
364
365    pub fn overflow(self, overflow: gtk::Overflow) -> Self {
366        Self {
367            builder: self.builder.property("overflow", overflow),
368        }
369    }
370
371    pub fn receives_default(self, receives_default: bool) -> Self {
372        Self {
373            builder: self.builder.property("receives-default", receives_default),
374        }
375    }
376
377    pub fn sensitive(self, sensitive: bool) -> Self {
378        Self {
379            builder: self.builder.property("sensitive", sensitive),
380        }
381    }
382
383    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
384        Self {
385            builder: self
386                .builder
387                .property("tooltip-markup", tooltip_markup.into()),
388        }
389    }
390
391    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
392        Self {
393            builder: self.builder.property("tooltip-text", tooltip_text.into()),
394        }
395    }
396
397    pub fn valign(self, valign: gtk::Align) -> Self {
398        Self {
399            builder: self.builder.property("valign", valign),
400        }
401    }
402
403    pub fn vexpand(self, vexpand: bool) -> Self {
404        Self {
405            builder: self.builder.property("vexpand", vexpand),
406        }
407    }
408
409    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
410        Self {
411            builder: self.builder.property("vexpand-set", vexpand_set),
412        }
413    }
414
415    pub fn visible(self, visible: bool) -> Self {
416        Self {
417            builder: self.builder.property("visible", visible),
418        }
419    }
420
421    pub fn width_request(self, width_request: i32) -> Self {
422        Self {
423            builder: self.builder.property("width-request", width_request),
424        }
425    }
426
427    pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
428        Self {
429            builder: self.builder.property("accessible-role", accessible_role),
430        }
431    }
432
433    // rustdoc-stripper-ignore-next
434    /// Build the [`Window`].
435    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
436    pub fn build(self) -> Window {
437        assert_initialized_main_thread!();
438        self.builder.build()
439    }
440}
441
442pub trait AdwWindowExt: IsA<Window> + 'static {
443    #[cfg(feature = "v1_4")]
444    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
445    #[doc(alias = "adw_window_add_breakpoint")]
446    fn add_breakpoint(&self, breakpoint: Breakpoint) {
447        unsafe {
448            ffi::adw_window_add_breakpoint(
449                self.as_ref().to_glib_none().0,
450                breakpoint.into_glib_ptr(),
451            );
452        }
453    }
454
455    #[cfg(feature = "v1_7")]
456    #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
457    #[doc(alias = "adw_window_get_adaptive_preview")]
458    #[doc(alias = "get_adaptive_preview")]
459    #[doc(alias = "adaptive-preview")]
460    fn is_adaptive_preview(&self) -> bool {
461        unsafe {
462            from_glib(ffi::adw_window_get_adaptive_preview(
463                self.as_ref().to_glib_none().0,
464            ))
465        }
466    }
467
468    #[doc(alias = "adw_window_get_content")]
469    #[doc(alias = "get_content")]
470    fn content(&self) -> Option<gtk::Widget> {
471        unsafe { from_glib_none(ffi::adw_window_get_content(self.as_ref().to_glib_none().0)) }
472    }
473
474    #[cfg(feature = "v1_4")]
475    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
476    #[doc(alias = "adw_window_get_current_breakpoint")]
477    #[doc(alias = "get_current_breakpoint")]
478    #[doc(alias = "current-breakpoint")]
479    fn current_breakpoint(&self) -> Option<Breakpoint> {
480        unsafe {
481            from_glib_none(ffi::adw_window_get_current_breakpoint(
482                self.as_ref().to_glib_none().0,
483            ))
484        }
485    }
486
487    #[cfg(feature = "v1_5")]
488    #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
489    #[doc(alias = "adw_window_get_dialogs")]
490    #[doc(alias = "get_dialogs")]
491    fn dialogs(&self) -> gio::ListModel {
492        unsafe { from_glib_full(ffi::adw_window_get_dialogs(self.as_ref().to_glib_none().0)) }
493    }
494
495    #[cfg(feature = "v1_5")]
496    #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
497    #[doc(alias = "adw_window_get_visible_dialog")]
498    #[doc(alias = "get_visible_dialog")]
499    #[doc(alias = "visible-dialog")]
500    fn visible_dialog(&self) -> Option<Dialog> {
501        unsafe {
502            from_glib_none(ffi::adw_window_get_visible_dialog(
503                self.as_ref().to_glib_none().0,
504            ))
505        }
506    }
507
508    #[cfg(feature = "v1_7")]
509    #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
510    #[doc(alias = "adw_window_set_adaptive_preview")]
511    #[doc(alias = "adaptive-preview")]
512    fn set_adaptive_preview(&self, adaptive_preview: bool) {
513        unsafe {
514            ffi::adw_window_set_adaptive_preview(
515                self.as_ref().to_glib_none().0,
516                adaptive_preview.into_glib(),
517            );
518        }
519    }
520
521    #[doc(alias = "adw_window_set_content")]
522    #[doc(alias = "content")]
523    fn set_content(&self, content: Option<&impl IsA<gtk::Widget>>) {
524        unsafe {
525            ffi::adw_window_set_content(
526                self.as_ref().to_glib_none().0,
527                content.map(|p| p.as_ref()).to_glib_none().0,
528            );
529        }
530    }
531
532    #[cfg(feature = "v1_7")]
533    #[cfg_attr(docsrs, doc(cfg(feature = "v1_7")))]
534    #[doc(alias = "adaptive-preview")]
535    fn connect_adaptive_preview_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
536        unsafe extern "C" fn notify_adaptive_preview_trampoline<
537            P: IsA<Window>,
538            F: Fn(&P) + 'static,
539        >(
540            this: *mut ffi::AdwWindow,
541            _param_spec: glib::ffi::gpointer,
542            f: glib::ffi::gpointer,
543        ) {
544            let f: &F = &*(f as *const F);
545            f(Window::from_glib_borrow(this).unsafe_cast_ref())
546        }
547        unsafe {
548            let f: Box_<F> = Box_::new(f);
549            connect_raw(
550                self.as_ptr() as *mut _,
551                c"notify::adaptive-preview".as_ptr() as *const _,
552                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
553                    notify_adaptive_preview_trampoline::<Self, F> as *const (),
554                )),
555                Box_::into_raw(f),
556            )
557        }
558    }
559
560    #[doc(alias = "content")]
561    fn connect_content_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
562        unsafe extern "C" fn notify_content_trampoline<P: IsA<Window>, F: Fn(&P) + 'static>(
563            this: *mut ffi::AdwWindow,
564            _param_spec: glib::ffi::gpointer,
565            f: glib::ffi::gpointer,
566        ) {
567            let f: &F = &*(f as *const F);
568            f(Window::from_glib_borrow(this).unsafe_cast_ref())
569        }
570        unsafe {
571            let f: Box_<F> = Box_::new(f);
572            connect_raw(
573                self.as_ptr() as *mut _,
574                c"notify::content".as_ptr() as *const _,
575                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
576                    notify_content_trampoline::<Self, F> as *const (),
577                )),
578                Box_::into_raw(f),
579            )
580        }
581    }
582
583    #[cfg(feature = "v1_4")]
584    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
585    #[doc(alias = "current-breakpoint")]
586    fn connect_current_breakpoint_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
587        unsafe extern "C" fn notify_current_breakpoint_trampoline<
588            P: IsA<Window>,
589            F: Fn(&P) + 'static,
590        >(
591            this: *mut ffi::AdwWindow,
592            _param_spec: glib::ffi::gpointer,
593            f: glib::ffi::gpointer,
594        ) {
595            let f: &F = &*(f as *const F);
596            f(Window::from_glib_borrow(this).unsafe_cast_ref())
597        }
598        unsafe {
599            let f: Box_<F> = Box_::new(f);
600            connect_raw(
601                self.as_ptr() as *mut _,
602                c"notify::current-breakpoint".as_ptr() as *const _,
603                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
604                    notify_current_breakpoint_trampoline::<Self, F> as *const (),
605                )),
606                Box_::into_raw(f),
607            )
608        }
609    }
610
611    #[cfg(feature = "v1_5")]
612    #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
613    #[doc(alias = "dialogs")]
614    fn connect_dialogs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
615        unsafe extern "C" fn notify_dialogs_trampoline<P: IsA<Window>, F: Fn(&P) + 'static>(
616            this: *mut ffi::AdwWindow,
617            _param_spec: glib::ffi::gpointer,
618            f: glib::ffi::gpointer,
619        ) {
620            let f: &F = &*(f as *const F);
621            f(Window::from_glib_borrow(this).unsafe_cast_ref())
622        }
623        unsafe {
624            let f: Box_<F> = Box_::new(f);
625            connect_raw(
626                self.as_ptr() as *mut _,
627                c"notify::dialogs".as_ptr() as *const _,
628                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
629                    notify_dialogs_trampoline::<Self, F> as *const (),
630                )),
631                Box_::into_raw(f),
632            )
633        }
634    }
635
636    #[cfg(feature = "v1_5")]
637    #[cfg_attr(docsrs, doc(cfg(feature = "v1_5")))]
638    #[doc(alias = "visible-dialog")]
639    fn connect_visible_dialog_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
640        unsafe extern "C" fn notify_visible_dialog_trampoline<
641            P: IsA<Window>,
642            F: Fn(&P) + 'static,
643        >(
644            this: *mut ffi::AdwWindow,
645            _param_spec: glib::ffi::gpointer,
646            f: glib::ffi::gpointer,
647        ) {
648            let f: &F = &*(f as *const F);
649            f(Window::from_glib_borrow(this).unsafe_cast_ref())
650        }
651        unsafe {
652            let f: Box_<F> = Box_::new(f);
653            connect_raw(
654                self.as_ptr() as *mut _,
655                c"notify::visible-dialog".as_ptr() as *const _,
656                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
657                    notify_visible_dialog_trampoline::<Self, F> as *const (),
658                )),
659                Box_::into_raw(f),
660            )
661        }
662    }
663}
664
665impl<O: IsA<Window>> AdwWindowExt for O {}