Skip to main content

gdk4/
drag_surface.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{boxed::Box as Box_, mem::transmute};
4
5use glib::{
6    signal::{SignalHandlerId, connect_raw},
7    translate::*,
8};
9
10use crate::{DragSurface, DragSurfaceSize, ffi, prelude::*};
11
12// rustdoc-stripper-ignore-next
13/// Trait containing manually implemented methods of
14/// [`DragSurface`](crate::DragSurface).
15pub 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            unsafe {
31                let f: &F = &*(f as *const F);
32                let mut size = DragSurfaceSize(std::ptr::NonNull::new_unchecked(size));
33                f(&from_glib_borrow(this), &mut size)
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 {}