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
12mod sealed {
13 pub trait Sealed {}
14 impl<T: super::IsA<super::DragSurface>> Sealed for T {}
15}
16
17pub trait DragSurfaceExtManual: sealed::Sealed + IsA<DragSurface> {
21 #[cfg(feature = "v4_12")]
22 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
23 #[doc(alias = "compute-size")]
24 fn connect_compute_size<F: Fn(&DragSurface, &mut DragSurfaceSize) + 'static>(
25 &self,
26 f: F,
27 ) -> SignalHandlerId {
28 unsafe extern "C" fn compute_size_trampoline<
29 F: Fn(&DragSurface, &mut DragSurfaceSize) + 'static,
30 >(
31 this: *mut ffi::GdkDragSurface,
32 size: *mut ffi::GdkDragSurfaceSize,
33 f: glib::ffi::gpointer,
34 ) {
35 let f: &F = &*(f as *const F);
36 f(
37 &from_glib_borrow(this),
38 &mut *(size as *mut DragSurfaceSize),
39 )
40 }
41 unsafe {
42 let f: Box_<F> = Box_::new(f);
43 connect_raw(
44 self.as_ptr() as *mut _,
45 b"compute-size\0".as_ptr() as *const _,
46 Some(transmute::<*const (), unsafe extern "C" fn()>(
47 compute_size_trampoline::<F> as *const (),
48 )),
49 Box_::into_raw(f),
50 )
51 }
52 }
53}
54
55impl<O: IsA<DragSurface>> DragSurfaceExtManual for O {}