libpanel/auto/
workbench.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, Workspace};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "PanelWorkbench")]
17    pub struct Workbench(Object<ffi::PanelWorkbench, ffi::PanelWorkbenchClass>);
18
19    match fn {
20        type_ => || ffi::panel_workbench_get_type(),
21    }
22}
23
24impl Workbench {
25    pub const NONE: Option<&'static Workbench> = None;
26
27    #[doc(alias = "panel_workbench_new")]
28    pub fn new() -> Workbench {
29        assert_initialized_main_thread!();
30        unsafe { from_glib_full(ffi::panel_workbench_new()) }
31    }
32
33    // rustdoc-stripper-ignore-next
34    /// Creates a new builder-pattern struct instance to construct [`Workbench`] objects.
35    ///
36    /// This method returns an instance of [`WorkbenchBuilder`](crate::builders::WorkbenchBuilder) which can be used to create [`Workbench`] objects.
37    pub fn builder() -> WorkbenchBuilder {
38        WorkbenchBuilder::new()
39    }
40
41    #[cfg(feature = "v1_4")]
42    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
43    #[doc(alias = "panel_workbench_find_from_widget")]
44    pub fn find_from_widget(widget: &impl IsA<gtk::Widget>) -> Option<Workbench> {
45        assert_initialized_main_thread!();
46        unsafe {
47            from_glib_none(ffi::panel_workbench_find_from_widget(
48                widget.as_ref().to_glib_none().0,
49            ))
50        }
51    }
52}
53
54impl Default for Workbench {
55    fn default() -> Self {
56        Self::new()
57    }
58}
59
60// rustdoc-stripper-ignore-next
61/// A [builder-pattern] type to construct [`Workbench`] objects.
62///
63/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
64#[must_use = "The builder must be built to be used"]
65pub struct WorkbenchBuilder {
66    builder: glib::object::ObjectBuilder<'static, Workbench>,
67}
68
69impl WorkbenchBuilder {
70    fn new() -> Self {
71        Self {
72            builder: glib::object::Object::builder(),
73        }
74    }
75
76    #[cfg(feature = "v1_4")]
77    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
78    pub fn id(self, id: impl Into<glib::GString>) -> Self {
79        Self {
80            builder: self.builder.property("id", id.into()),
81        }
82    }
83
84    // rustdoc-stripper-ignore-next
85    /// Build the [`Workbench`].
86    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
87    pub fn build(self) -> Workbench {
88        assert_initialized_main_thread!();
89        self.builder.build()
90    }
91}
92
93pub trait WorkbenchExt: IsA<Workbench> + 'static {
94    #[doc(alias = "panel_workbench_action_set_enabled")]
95    fn action_set_enabled(&self, action_name: &str, enabled: bool) {
96        unsafe {
97            ffi::panel_workbench_action_set_enabled(
98                self.as_ref().to_glib_none().0,
99                action_name.to_glib_none().0,
100                enabled.into_glib(),
101            );
102        }
103    }
104
105    #[doc(alias = "panel_workbench_activate")]
106    fn activate(&self) {
107        unsafe {
108            ffi::panel_workbench_activate(self.as_ref().to_glib_none().0);
109        }
110    }
111
112    #[doc(alias = "panel_workbench_add_workspace")]
113    fn add_workspace(&self, workspace: &impl IsA<Workspace>) {
114        unsafe {
115            ffi::panel_workbench_add_workspace(
116                self.as_ref().to_glib_none().0,
117                workspace.as_ref().to_glib_none().0,
118            );
119        }
120    }
121
122    #[cfg(feature = "v1_4")]
123    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
124    #[doc(alias = "panel_workbench_find_workspace_typed")]
125    fn find_workspace_typed(&self, workspace_type: glib::types::Type) -> Option<Workspace> {
126        unsafe {
127            from_glib_none(ffi::panel_workbench_find_workspace_typed(
128                self.as_ref().to_glib_none().0,
129                workspace_type.into_glib(),
130            ))
131        }
132    }
133
134    #[doc(alias = "panel_workbench_focus_workspace")]
135    fn focus_workspace(&self, workspace: &impl IsA<Workspace>) {
136        unsafe {
137            ffi::panel_workbench_focus_workspace(
138                self.as_ref().to_glib_none().0,
139                workspace.as_ref().to_glib_none().0,
140            );
141        }
142    }
143
144    #[cfg(feature = "v1_4")]
145    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
146    #[doc(alias = "panel_workbench_foreach_workspace")]
147    fn foreach_workspace<P: FnMut(&Workspace)>(&self, foreach_func: P) {
148        let mut foreach_func_data: P = foreach_func;
149        unsafe extern "C" fn foreach_func_func<P: FnMut(&Workspace)>(
150            workspace: *mut ffi::PanelWorkspace,
151            user_data: glib::ffi::gpointer,
152        ) {
153            let workspace = from_glib_borrow(workspace);
154            let callback = user_data as *mut P;
155            (*callback)(&workspace)
156        }
157        let foreach_func = Some(foreach_func_func::<P> as _);
158        let super_callback0: &mut P = &mut foreach_func_data;
159        unsafe {
160            ffi::panel_workbench_foreach_workspace(
161                self.as_ref().to_glib_none().0,
162                foreach_func,
163                super_callback0 as *mut _ as *mut _,
164            );
165        }
166    }
167
168    #[doc(alias = "panel_workbench_get_id")]
169    #[doc(alias = "get_id")]
170    fn id(&self) -> glib::GString {
171        unsafe { from_glib_none(ffi::panel_workbench_get_id(self.as_ref().to_glib_none().0)) }
172    }
173
174    #[doc(alias = "panel_workbench_remove_workspace")]
175    fn remove_workspace(&self, workspace: &impl IsA<Workspace>) {
176        unsafe {
177            ffi::panel_workbench_remove_workspace(
178                self.as_ref().to_glib_none().0,
179                workspace.as_ref().to_glib_none().0,
180            );
181        }
182    }
183
184    #[doc(alias = "panel_workbench_set_id")]
185    #[doc(alias = "id")]
186    fn set_id(&self, id: &str) {
187        unsafe {
188            ffi::panel_workbench_set_id(self.as_ref().to_glib_none().0, id.to_glib_none().0);
189        }
190    }
191
192    #[doc(alias = "activate")]
193    fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
194        unsafe extern "C" fn activate_trampoline<P: IsA<Workbench>, F: Fn(&P) + 'static>(
195            this: *mut ffi::PanelWorkbench,
196            f: glib::ffi::gpointer,
197        ) {
198            let f: &F = &*(f as *const F);
199            f(Workbench::from_glib_borrow(this).unsafe_cast_ref())
200        }
201        unsafe {
202            let f: Box_<F> = Box_::new(f);
203            connect_raw(
204                self.as_ptr() as *mut _,
205                c"activate".as_ptr() as *const _,
206                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
207                    activate_trampoline::<Self, F> as *const (),
208                )),
209                Box_::into_raw(f),
210            )
211        }
212    }
213
214    #[cfg(feature = "v1_4")]
215    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
216    #[doc(alias = "id")]
217    fn connect_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
218        unsafe extern "C" fn notify_id_trampoline<P: IsA<Workbench>, F: Fn(&P) + 'static>(
219            this: *mut ffi::PanelWorkbench,
220            _param_spec: glib::ffi::gpointer,
221            f: glib::ffi::gpointer,
222        ) {
223            let f: &F = &*(f as *const F);
224            f(Workbench::from_glib_borrow(this).unsafe_cast_ref())
225        }
226        unsafe {
227            let f: Box_<F> = Box_::new(f);
228            connect_raw(
229                self.as_ptr() as *mut _,
230                c"notify::id".as_ptr() as *const _,
231                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
232                    notify_id_trampoline::<Self, F> as *const (),
233                )),
234                Box_::into_raw(f),
235            )
236        }
237    }
238}
239
240impl<O: IsA<Workbench>> WorkbenchExt for O {}