Skip to main content

spice_client_glib/
main_channel.rs

1use glib::object::ObjectType as ObjectType_;
2use glib::signal::connect_raw;
3use glib::signal::SignalHandlerId;
4use glib::translate::*;
5use std::boxed::Box as Box_;
6use std::mem::transmute;
7
8use crate::MainChannel;
9
10impl MainChannel {
11    pub fn connect_main_clipboard_selection<F: Fn(&MainChannel, u32, u32, &[u8]) + 'static>(
12        &self,
13        f: F,
14    ) -> SignalHandlerId {
15        unsafe extern "C" fn main_clipboard_selection_trampoline<
16            F: Fn(&MainChannel, u32, u32, &[u8]) + 'static,
17        >(
18            this: *mut ffi::SpiceMainChannel,
19            selection: libc::c_uint,
20            type_: libc::c_uint,
21            data: glib::ffi::gpointer,
22            size: libc::c_uint,
23            f: glib::ffi::gpointer,
24        ) {
25            let f: &F = &*(f as *const F);
26            f(
27                &from_glib_borrow(this),
28                selection,
29                type_,
30                &FromGlibContainerAsVec::from_glib_none_num_as_vec(data as *const u8, size as _),
31            )
32        }
33        unsafe {
34            let f: Box_<F> = Box_::new(f);
35            connect_raw(
36                self.as_ptr() as *mut _,
37                b"main-clipboard-selection\0".as_ptr() as *const _,
38                Some(transmute::<_, unsafe extern "C" fn()>(
39                    main_clipboard_selection_trampoline::<F> as *const (),
40                )),
41                Box_::into_raw(f),
42            )
43        }
44    }
45
46    pub fn connect_main_clipboard_selection_grab<F: Fn(&MainChannel, u32, &[u32]) + 'static>(
47        &self,
48        f: F,
49    ) -> SignalHandlerId {
50        unsafe extern "C" fn main_clipboard_selection_trampoline<
51            F: Fn(&MainChannel, u32, &[u32]) + 'static,
52        >(
53            this: *mut ffi::SpiceMainChannel,
54            selection: libc::c_uint,
55            types: glib::ffi::gpointer,
56            ntypes: libc::c_uint,
57            f: glib::ffi::gpointer,
58        ) {
59            let f: &F = &*(f as *const F);
60            f(
61                &from_glib_borrow(this),
62                selection,
63                &FromGlibContainerAsVec::from_glib_none_num_as_vec(
64                    types as *const u32,
65                    ntypes as _,
66                ),
67            )
68        }
69        unsafe {
70            let f: Box_<F> = Box_::new(f);
71            connect_raw(
72                self.as_ptr() as *mut _,
73                b"main-clipboard-selection-grab\0".as_ptr() as *const _,
74                Some(transmute::<_, unsafe extern "C" fn()>(
75                    main_clipboard_selection_trampoline::<F> as *const (),
76                )),
77                Box_::into_raw(f),
78            )
79        }
80    }
81}