gdk4_wayland/
wayland_toplevel.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::{ffi, WaylandToplevel};
4use glib::translate::*;
5use std::boxed::Box as Box_;
6
7impl WaylandToplevel {
8    #[doc(alias = "gdk_wayland_toplevel_export_handle")]
9    pub fn export_handle<P: Fn(&WaylandToplevel, Result<&str, glib::BoolError>) + 'static>(
10        &self,
11        callback: P,
12    ) -> bool {
13        let callback_data: Box_<P> = Box_::new(callback);
14        unsafe extern "C" fn callback_func<
15            P: Fn(&WaylandToplevel, Result<&str, glib::BoolError>) + 'static,
16        >(
17            toplevel: *mut ffi::GdkWaylandToplevel,
18            handle: *const libc::c_char,
19            user_data: glib::ffi::gpointer,
20        ) {
21            let toplevel = from_glib_borrow(toplevel);
22            let handle: Borrowed<Option<glib::GString>> = from_glib_borrow(handle);
23            let callback = &*(user_data as *mut P);
24            if let Some(handle) = handle.as_ref() {
25                (*callback)(&toplevel, Ok(handle.as_str()))
26            } else {
27                (*callback)(&toplevel, Err(glib::bool_error!("Failed to export a handle. The compositor probably doesn't implement the xdg-foreign protocol")))
28            }
29        }
30        let callback = Some(callback_func::<P> as _);
31        unsafe extern "C" fn destroy_func_func<
32            P: Fn(&WaylandToplevel, Result<&str, glib::BoolError>) + 'static,
33        >(
34            data: glib::ffi::gpointer,
35        ) {
36            let _callback = Box_::from_raw(data as *mut P);
37        }
38        let destroy_call3 = Some(destroy_func_func::<P> as _);
39        let super_callback0: Box_<P> = callback_data;
40        unsafe {
41            from_glib(ffi::gdk_wayland_toplevel_export_handle(
42                self.to_glib_none().0,
43                callback,
44                Box_::into_raw(super_callback0) as *mut _,
45                destroy_call3,
46            ))
47        }
48    }
49}