1use crate::{Action, Actor, ActorMeta, LongPressState, ModifierType};
2use glib::{
3 object as gobject,
4 object::{Cast, IsA},
5 signal::{connect_raw, SignalHandlerId},
6 translate::*,
7 StaticType, Value,
8};
9use std::boxed::Box as Box_;
10use std::{fmt, mem, mem::transmute};
11
12glib_wrapper! {
13 pub struct ClickAction(Object<ffi::ClutterClickAction, ffi::ClutterClickActionClass, ClickActionClass>) @extends Action, ActorMeta, gobject::InitiallyUnowned;
14
15 match fn {
16 get_type => || ffi::clutter_click_action_get_type(),
17 }
18}
19
20impl ClickAction {
21 pub fn new() -> ClickAction {
27 unsafe { Action::from_glib_none(ffi::clutter_click_action_new()).unsafe_cast() }
28 }
29}
30
31impl Default for ClickAction {
32 fn default() -> Self {
33 Self::new()
34 }
35}
36
37pub trait ClickActionExt: 'static {
43 fn get_button(&self) -> u32;
53
54 fn get_coords(&self) -> (f32, f32);
60
61 fn get_state(&self) -> ModifierType;
67
68 fn release(&self);
77
78 fn get_property_held(&self) -> bool;
80
81 fn get_property_long_press_duration(&self) -> i32;
87
88 fn set_property_long_press_duration(&self, long_press_duration: i32);
94
95 fn get_property_long_press_threshold(&self) -> i32;
101
102 fn set_property_long_press_threshold(&self, long_press_threshold: i32);
108
109 fn get_property_pressed(&self) -> bool;
111
112 fn connect_clicked<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId;
118
119 fn connect_long_press<F: Fn(&Self, &Actor, LongPressState) -> bool + 'static>(
144 &self,
145 f: F,
146 ) -> SignalHandlerId;
147
148 fn connect_property_held_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
149
150 fn connect_property_long_press_duration_notify<F: Fn(&Self) + 'static>(
151 &self,
152 f: F,
153 ) -> SignalHandlerId;
154
155 fn connect_property_long_press_threshold_notify<F: Fn(&Self) + 'static>(
156 &self,
157 f: F,
158 ) -> SignalHandlerId;
159
160 fn connect_property_pressed_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
161}
162
163impl<O: IsA<ClickAction>> ClickActionExt for O {
164 fn get_button(&self) -> u32 {
165 unsafe { ffi::clutter_click_action_get_button(self.as_ref().to_glib_none().0) }
166 }
167
168 fn get_coords(&self) -> (f32, f32) {
169 unsafe {
170 let mut press_x = mem::MaybeUninit::uninit();
171 let mut press_y = mem::MaybeUninit::uninit();
172 ffi::clutter_click_action_get_coords(
173 self.as_ref().to_glib_none().0,
174 press_x.as_mut_ptr(),
175 press_y.as_mut_ptr(),
176 );
177 let press_x = press_x.assume_init();
178 let press_y = press_y.assume_init();
179 (press_x, press_y)
180 }
181 }
182
183 fn get_state(&self) -> ModifierType {
184 unsafe {
185 from_glib(ffi::clutter_click_action_get_state(
186 self.as_ref().to_glib_none().0,
187 ))
188 }
189 }
190
191 fn release(&self) {
192 unsafe {
193 ffi::clutter_click_action_release(self.as_ref().to_glib_none().0);
194 }
195 }
196
197 fn get_property_held(&self) -> bool {
198 unsafe {
199 let mut value = Value::from_type(<bool as StaticType>::static_type());
200 gobject_sys::g_object_get_property(
201 self.to_glib_none().0 as *mut gobject_sys::GObject,
202 b"held\0".as_ptr() as *const _,
203 value.to_glib_none_mut().0,
204 );
205 value
206 .get()
207 .expect("Return Value for property `held` getter")
208 .unwrap()
209 }
210 }
211
212 fn get_property_long_press_duration(&self) -> i32 {
213 unsafe {
214 let mut value = Value::from_type(<i32 as StaticType>::static_type());
215 gobject_sys::g_object_get_property(
216 self.to_glib_none().0 as *mut gobject_sys::GObject,
217 b"long-press-duration\0".as_ptr() as *const _,
218 value.to_glib_none_mut().0,
219 );
220 value
221 .get()
222 .expect("Return Value for property `long-press-duration` getter")
223 .unwrap()
224 }
225 }
226
227 fn set_property_long_press_duration(&self, long_press_duration: i32) {
228 unsafe {
229 gobject_sys::g_object_set_property(
230 self.to_glib_none().0 as *mut gobject_sys::GObject,
231 b"long-press-duration\0".as_ptr() as *const _,
232 Value::from(&long_press_duration).to_glib_none().0,
233 );
234 }
235 }
236
237 fn get_property_long_press_threshold(&self) -> i32 {
238 unsafe {
239 let mut value = Value::from_type(<i32 as StaticType>::static_type());
240 gobject_sys::g_object_get_property(
241 self.to_glib_none().0 as *mut gobject_sys::GObject,
242 b"long-press-threshold\0".as_ptr() as *const _,
243 value.to_glib_none_mut().0,
244 );
245 value
246 .get()
247 .expect("Return Value for property `long-press-threshold` getter")
248 .unwrap()
249 }
250 }
251
252 fn set_property_long_press_threshold(&self, long_press_threshold: i32) {
253 unsafe {
254 gobject_sys::g_object_set_property(
255 self.to_glib_none().0 as *mut gobject_sys::GObject,
256 b"long-press-threshold\0".as_ptr() as *const _,
257 Value::from(&long_press_threshold).to_glib_none().0,
258 );
259 }
260 }
261
262 fn get_property_pressed(&self) -> bool {
263 unsafe {
264 let mut value = Value::from_type(<bool as StaticType>::static_type());
265 gobject_sys::g_object_get_property(
266 self.to_glib_none().0 as *mut gobject_sys::GObject,
267 b"pressed\0".as_ptr() as *const _,
268 value.to_glib_none_mut().0,
269 );
270 value
271 .get()
272 .expect("Return Value for property `pressed` getter")
273 .unwrap()
274 }
275 }
276
277 fn connect_clicked<F: Fn(&Self, &Actor) + 'static>(&self, f: F) -> SignalHandlerId {
278 unsafe extern "C" fn clicked_trampoline<P, F: Fn(&P, &Actor) + 'static>(
279 this: *mut ffi::ClutterClickAction,
280 actor: *mut ffi::ClutterActor,
281 f: glib_sys::gpointer,
282 ) where
283 P: IsA<ClickAction>,
284 {
285 let f: &F = &*(f as *const F);
286 f(
287 &ClickAction::from_glib_borrow(this).unsafe_cast_ref(),
288 &from_glib_borrow(actor),
289 )
290 }
291 unsafe {
292 let f: Box_<F> = Box_::new(f);
293 connect_raw(
294 self.as_ptr() as *mut _,
295 b"clicked\0".as_ptr() as *const _,
296 Some(transmute::<_, unsafe extern "C" fn()>(
297 clicked_trampoline::<Self, F> as *const (),
298 )),
299 Box_::into_raw(f),
300 )
301 }
302 }
303
304 fn connect_long_press<F: Fn(&Self, &Actor, LongPressState) -> bool + 'static>(
305 &self,
306 f: F,
307 ) -> SignalHandlerId {
308 unsafe extern "C" fn long_press_trampoline<
309 P,
310 F: Fn(&P, &Actor, LongPressState) -> bool + 'static,
311 >(
312 this: *mut ffi::ClutterClickAction,
313 actor: *mut ffi::ClutterActor,
314 state: ffi::ClutterLongPressState,
315 f: glib_sys::gpointer,
316 ) -> glib_sys::gboolean
317 where
318 P: IsA<ClickAction>,
319 {
320 let f: &F = &*(f as *const F);
321 f(
322 &ClickAction::from_glib_borrow(this).unsafe_cast_ref(),
323 &from_glib_borrow(actor),
324 from_glib(state),
325 )
326 .to_glib()
327 }
328 unsafe {
329 let f: Box_<F> = Box_::new(f);
330 connect_raw(
331 self.as_ptr() as *mut _,
332 b"long-press\0".as_ptr() as *const _,
333 Some(transmute::<_, unsafe extern "C" fn()>(
334 long_press_trampoline::<Self, F> as *const (),
335 )),
336 Box_::into_raw(f),
337 )
338 }
339 }
340
341 fn connect_property_held_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
342 unsafe extern "C" fn notify_held_trampoline<P, F: Fn(&P) + 'static>(
343 this: *mut ffi::ClutterClickAction,
344 _param_spec: glib_sys::gpointer,
345 f: glib_sys::gpointer,
346 ) where
347 P: IsA<ClickAction>,
348 {
349 let f: &F = &*(f as *const F);
350 f(&ClickAction::from_glib_borrow(this).unsafe_cast_ref())
351 }
352 unsafe {
353 let f: Box_<F> = Box_::new(f);
354 connect_raw(
355 self.as_ptr() as *mut _,
356 b"notify::held\0".as_ptr() as *const _,
357 Some(transmute::<_, unsafe extern "C" fn()>(
358 notify_held_trampoline::<Self, F> as *const (),
359 )),
360 Box_::into_raw(f),
361 )
362 }
363 }
364
365 fn connect_property_long_press_duration_notify<F: Fn(&Self) + 'static>(
366 &self,
367 f: F,
368 ) -> SignalHandlerId {
369 unsafe extern "C" fn notify_long_press_duration_trampoline<P, F: Fn(&P) + 'static>(
370 this: *mut ffi::ClutterClickAction,
371 _param_spec: glib_sys::gpointer,
372 f: glib_sys::gpointer,
373 ) where
374 P: IsA<ClickAction>,
375 {
376 let f: &F = &*(f as *const F);
377 f(&ClickAction::from_glib_borrow(this).unsafe_cast_ref())
378 }
379 unsafe {
380 let f: Box_<F> = Box_::new(f);
381 connect_raw(
382 self.as_ptr() as *mut _,
383 b"notify::long-press-duration\0".as_ptr() as *const _,
384 Some(transmute::<_, unsafe extern "C" fn()>(
385 notify_long_press_duration_trampoline::<Self, F> as *const (),
386 )),
387 Box_::into_raw(f),
388 )
389 }
390 }
391
392 fn connect_property_long_press_threshold_notify<F: Fn(&Self) + 'static>(
393 &self,
394 f: F,
395 ) -> SignalHandlerId {
396 unsafe extern "C" fn notify_long_press_threshold_trampoline<P, F: Fn(&P) + 'static>(
397 this: *mut ffi::ClutterClickAction,
398 _param_spec: glib_sys::gpointer,
399 f: glib_sys::gpointer,
400 ) where
401 P: IsA<ClickAction>,
402 {
403 let f: &F = &*(f as *const F);
404 f(&ClickAction::from_glib_borrow(this).unsafe_cast_ref())
405 }
406 unsafe {
407 let f: Box_<F> = Box_::new(f);
408 connect_raw(
409 self.as_ptr() as *mut _,
410 b"notify::long-press-threshold\0".as_ptr() as *const _,
411 Some(transmute::<_, unsafe extern "C" fn()>(
412 notify_long_press_threshold_trampoline::<Self, F> as *const (),
413 )),
414 Box_::into_raw(f),
415 )
416 }
417 }
418
419 fn connect_property_pressed_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
420 unsafe extern "C" fn notify_pressed_trampoline<P, F: Fn(&P) + 'static>(
421 this: *mut ffi::ClutterClickAction,
422 _param_spec: glib_sys::gpointer,
423 f: glib_sys::gpointer,
424 ) where
425 P: IsA<ClickAction>,
426 {
427 let f: &F = &*(f as *const F);
428 f(&ClickAction::from_glib_borrow(this).unsafe_cast_ref())
429 }
430 unsafe {
431 let f: Box_<F> = Box_::new(f);
432 connect_raw(
433 self.as_ptr() as *mut _,
434 b"notify::pressed\0".as_ptr() as *const _,
435 Some(transmute::<_, unsafe extern "C" fn()>(
436 notify_pressed_trampoline::<Self, F> as *const (),
437 )),
438 Box_::into_raw(f),
439 )
440 }
441 }
442}
443
444impl fmt::Display for ClickAction {
445 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
446 write!(f, "ClickAction")
447 }
448}