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                f(
33                    &from_glib_borrow(this),
34                    &mut *(size as *mut DragSurfaceSize),
35                )
36            }
37        }
38        unsafe {
39            let f: Box_<F> = Box_::new(f);
40            connect_raw(
41                self.as_ptr() as *mut _,
42                c"compute-size".as_ptr() as *const _,
43                Some(transmute::<*const (), unsafe extern "C" fn()>(
44                    compute_size_trampoline::<F> as *const (),
45                )),
46                Box_::into_raw(f),
47            )
48        }
49    }
50}
51
52impl<O: IsA<DragSurface>> DragSurfaceExtManual for O {}