clutter/auto/
stage_manager.rs

1use crate::Stage;
2use glib::{
3    object::{Cast, IsA},
4    signal::{connect_raw, SignalHandlerId},
5    translate::*,
6};
7use std::boxed::Box as Box_;
8use std::{fmt, mem::transmute};
9
10glib_wrapper! {
11    pub struct StageManager(Object<ffi::ClutterStageManager, ffi::ClutterStageManagerClass, StageManagerClass>);
12
13    match fn {
14        get_type => || ffi::clutter_stage_manager_get_type(),
15    }
16}
17
18impl StageManager {
19    /// Returns the default `StageManager`.
20    ///
21    /// # Returns
22    ///
23    /// the default stage manager instance. The returned
24    ///  object is owned by Clutter and you should not reference or unreference it.
25    pub fn get_default() -> Option<StageManager> {
26        unsafe { from_glib_none(ffi::clutter_stage_manager_get_default()) }
27    }
28}
29
30pub const NONE_STAGE_MANAGER: Option<&StageManager> = None;
31
32/// Trait containing all `StageManager` methods.
33///
34/// # Implementors
35///
36/// [`StageManager`](struct.StageManager.html)
37pub trait StageManagerExt: 'static {
38    /// Returns the default `Stage`.
39    ///
40    /// # Returns
41    ///
42    /// the default stage. The returned object
43    ///  is owned by Clutter and you should never reference or unreference it
44    fn get_default_stage(&self) -> Option<Stage>;
45
46    /// Lists all currently used stages.
47    ///
48    /// # Returns
49    ///
50    /// a newly
51    ///  allocated list of `Stage` objects. Use `glib::SList::free` to
52    ///  deallocate it when done.
53    fn list_stages(&self) -> Vec<Stage>;
54
55    /// Lists all currently used stages.
56    ///
57    /// # Returns
58    ///
59    /// a pointer
60    ///  to the internal list of `Stage` objects. The returned list
61    ///  is owned by the `StageManager` and should never be modified
62    ///  or freed
63    fn peek_stages(&self) -> Vec<Stage>;
64
65    /// The ::stage-added signal is emitted each time a new `Stage`
66    /// has been added to the stage manager.
67    /// ## `stage`
68    /// the added stage
69    fn connect_stage_added<F: Fn(&Self, &Stage) + 'static>(&self, f: F) -> SignalHandlerId;
70
71    /// The ::stage-removed signal is emitted each time a `Stage`
72    /// has been removed from the stage manager.
73    /// ## `stage`
74    /// the removed stage
75    fn connect_stage_removed<F: Fn(&Self, &Stage) + 'static>(&self, f: F) -> SignalHandlerId;
76
77    fn connect_property_default_stage_notify<F: Fn(&Self) + 'static>(
78        &self,
79        f: F,
80    ) -> SignalHandlerId;
81}
82
83impl<O: IsA<StageManager>> StageManagerExt for O {
84    fn get_default_stage(&self) -> Option<Stage> {
85        unsafe {
86            from_glib_none(ffi::clutter_stage_manager_get_default_stage(
87                self.as_ref().to_glib_none().0,
88            ))
89        }
90    }
91
92    fn list_stages(&self) -> Vec<Stage> {
93        unsafe {
94            FromGlibPtrContainer::from_glib_container(ffi::clutter_stage_manager_list_stages(
95                self.as_ref().to_glib_none().0,
96            ))
97        }
98    }
99
100    fn peek_stages(&self) -> Vec<Stage> {
101        unsafe {
102            FromGlibPtrContainer::from_glib_none(ffi::clutter_stage_manager_peek_stages(
103                self.as_ref().to_glib_none().0,
104            ))
105        }
106    }
107
108    fn connect_stage_added<F: Fn(&Self, &Stage) + 'static>(&self, f: F) -> SignalHandlerId {
109        unsafe extern "C" fn stage_added_trampoline<P, F: Fn(&P, &Stage) + 'static>(
110            this: *mut ffi::ClutterStageManager,
111            stage: *mut ffi::ClutterStage,
112            f: glib_sys::gpointer,
113        ) where
114            P: IsA<StageManager>,
115        {
116            let f: &F = &*(f as *const F);
117            f(
118                &StageManager::from_glib_borrow(this).unsafe_cast_ref(),
119                &from_glib_borrow(stage),
120            )
121        }
122        unsafe {
123            let f: Box_<F> = Box_::new(f);
124            connect_raw(
125                self.as_ptr() as *mut _,
126                b"stage-added\0".as_ptr() as *const _,
127                Some(transmute::<_, unsafe extern "C" fn()>(
128                    stage_added_trampoline::<Self, F> as *const (),
129                )),
130                Box_::into_raw(f),
131            )
132        }
133    }
134
135    fn connect_stage_removed<F: Fn(&Self, &Stage) + 'static>(&self, f: F) -> SignalHandlerId {
136        unsafe extern "C" fn stage_removed_trampoline<P, F: Fn(&P, &Stage) + 'static>(
137            this: *mut ffi::ClutterStageManager,
138            stage: *mut ffi::ClutterStage,
139            f: glib_sys::gpointer,
140        ) where
141            P: IsA<StageManager>,
142        {
143            let f: &F = &*(f as *const F);
144            f(
145                &StageManager::from_glib_borrow(this).unsafe_cast_ref(),
146                &from_glib_borrow(stage),
147            )
148        }
149        unsafe {
150            let f: Box_<F> = Box_::new(f);
151            connect_raw(
152                self.as_ptr() as *mut _,
153                b"stage-removed\0".as_ptr() as *const _,
154                Some(transmute::<_, unsafe extern "C" fn()>(
155                    stage_removed_trampoline::<Self, F> as *const (),
156                )),
157                Box_::into_raw(f),
158            )
159        }
160    }
161
162    fn connect_property_default_stage_notify<F: Fn(&Self) + 'static>(
163        &self,
164        f: F,
165    ) -> SignalHandlerId {
166        unsafe extern "C" fn notify_default_stage_trampoline<P, F: Fn(&P) + 'static>(
167            this: *mut ffi::ClutterStageManager,
168            _param_spec: glib_sys::gpointer,
169            f: glib_sys::gpointer,
170        ) where
171            P: IsA<StageManager>,
172        {
173            let f: &F = &*(f as *const F);
174            f(&StageManager::from_glib_borrow(this).unsafe_cast_ref())
175        }
176        unsafe {
177            let f: Box_<F> = Box_::new(f);
178            connect_raw(
179                self.as_ptr() as *mut _,
180                b"notify::default-stage\0".as_ptr() as *const _,
181                Some(transmute::<_, unsafe extern "C" fn()>(
182                    notify_default_stage_trampoline::<Self, F> as *const (),
183                )),
184                Box_::into_raw(f),
185            )
186        }
187    }
188}
189
190impl fmt::Display for StageManager {
191    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
192        write!(f, "StageManager")
193    }
194}