gdk4/
drag_surface.rs
1use std::{boxed::Box as Box_, mem::transmute};
4
5use glib::{
6 signal::{connect_raw, SignalHandlerId},
7 translate::*,
8};
9
10use crate::{ffi, prelude::*, DragSurface, DragSurfaceSize};
11
12pub trait DragSurfaceExtManual: IsA<DragSurface> {
16 #[cfg(feature = "v4_12")]
17 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
18 #[doc(alias = "compute-size")]
19 fn connect_compute_size<F: Fn(&DragSurface, &mut DragSurfaceSize) + 'static>(
20 &self,
21 f: F,
22 ) -> SignalHandlerId {
23 unsafe extern "C" fn compute_size_trampoline<
24 F: Fn(&DragSurface, &mut DragSurfaceSize) + 'static,
25 >(
26 this: *mut ffi::GdkDragSurface,
27 size: *mut ffi::GdkDragSurfaceSize,
28 f: glib::ffi::gpointer,
29 ) {
30 let f: &F = &*(f as *const F);
31 f(
32 &from_glib_borrow(this),
33 &mut *(size as *mut DragSurfaceSize),
34 )
35 }
36 unsafe {
37 let f: Box_<F> = Box_::new(f);
38 connect_raw(
39 self.as_ptr() as *mut _,
40 c"compute-size".as_ptr() as *const _,
41 Some(transmute::<*const (), unsafe extern "C" fn()>(
42 compute_size_trampoline::<F> as *const (),
43 )),
44 Box_::into_raw(f),
45 )
46 }
47 }
48}
49
50impl<O: IsA<DragSurface>> DragSurfaceExtManual for O {}