clutter/auto/
stage_manager.rs1use 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 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
32pub trait StageManagerExt: 'static {
38 fn get_default_stage(&self) -> Option<Stage>;
45
46 fn list_stages(&self) -> Vec<Stage>;
54
55 fn peek_stages(&self) -> Vec<Stage>;
64
65 fn connect_stage_added<F: Fn(&Self, &Stage) + 'static>(&self, f: F) -> SignalHandlerId;
70
71 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}