gdk4/
drag_surface.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Take a look at the license at the top of the repository in the LICENSE file.

use std::{boxed::Box as Box_, mem::transmute};

use glib::{
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};

use crate::{ffi, prelude::*, DragSurface, DragSurfaceSize};

// rustdoc-stripper-ignore-next
/// Trait containing manually implemented methods of
/// [`DragSurface`](crate::DragSurface).
pub trait DragSurfaceExtManual: IsA<DragSurface> {
    #[cfg(feature = "v4_12")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
    #[doc(alias = "compute-size")]
    fn connect_compute_size<F: Fn(&DragSurface, &mut DragSurfaceSize) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn compute_size_trampoline<
            F: Fn(&DragSurface, &mut DragSurfaceSize) + 'static,
        >(
            this: *mut ffi::GdkDragSurface,
            size: *mut ffi::GdkDragSurfaceSize,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                &from_glib_borrow(this),
                &mut *(size as *mut DragSurfaceSize),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"compute-size".as_ptr() as *const _,
                Some(transmute::<*const (), unsafe extern "C" fn()>(
                    compute_size_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<DragSurface>> DragSurfaceExtManual for O {}