Skip to main content

gdkwayland/
wayland_window.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ffi;
4use gdk::Atom;
5use glib::translate::*;
6
7glib::wrapper! {
8    #[doc(alias = "GdkWaylandWindow")]
9    pub struct WaylandWindow(Object<ffi::GdkWaylandWindow>) @extends gdk::Window;
10
11    match fn {
12        type_ => || ffi::gdk_wayland_window_get_type(),
13    }
14}
15
16impl WaylandWindow {
17    #[doc(alias = "gdk_wayland_selection_add_targets")]
18    pub fn selection_add_targets(&self, selection: &Atom, targets: &[Atom]) {
19        unsafe {
20            ffi::gdk_wayland_selection_add_targets(
21                self.to_glib_none().0,
22                selection.to_glib_none().0,
23                targets.len() as _,
24                targets.to_glib_none().0,
25            )
26        }
27    }
28
29    #[doc(alias = "gdk_wayland_window_set_use_custom_surface")]
30    pub fn set_use_custom_surface(&self) {
31        unsafe { ffi::gdk_wayland_window_set_use_custom_surface(self.to_glib_none().0) }
32    }
33
34    #[doc(alias = "gdk_wayland_window_unexport_handle")]
35    pub fn unexport_handle(&self) {
36        unsafe { ffi::gdk_wayland_window_unexport_handle(self.to_glib_none().0) }
37    }
38
39    #[doc(alias = "gdk_wayland_window_export_handle")]
40    pub fn export_handle<P: Fn(&Self, &str) + 'static>(&self, callback: P) -> bool {
41        unsafe extern "C" fn callback_trampoline<P: Fn(&WaylandWindow, &str) + 'static>(
42            window: *mut ffi::GdkWaylandWindow,
43            handle: *const libc::c_char,
44            user_data: glib::ffi::gpointer,
45        ) {
46            unsafe {
47                let window = from_glib_borrow(window);
48                let handle: Borrowed<glib::GString> = from_glib_borrow(handle);
49                let callback = &*(user_data as *mut P);
50                (*callback)(&window, handle.as_str());
51            }
52        }
53        unsafe extern "C" fn destroy_notify<P: Fn(&WaylandWindow, &str) + 'static>(
54            data: glib::ffi::gpointer,
55        ) {
56            unsafe {
57                let _ = Box::from_raw(data as *mut P);
58            }
59        }
60        unsafe {
61            from_glib(ffi::gdk_wayland_window_export_handle(
62                self.to_glib_none().0,
63                Some(callback_trampoline::<P> as _),
64                Box::into_raw(Box::new(callback)) as *mut _,
65                Some(destroy_notify::<P> as _),
66            ))
67        }
68    }
69
70    #[doc(alias = "gdk_wayland_window_set_dbus_properties_libgtk_only")]
71    pub fn set_dbus_properties_libgtk_only(
72        &self,
73        application_id: &str,
74        app_menu_path: &str,
75        menubar_path: &str,
76        window_object_path: &str,
77        application_object_path: &str,
78        unique_bus_name: &str,
79    ) {
80        unsafe {
81            ffi::gdk_wayland_window_set_dbus_properties_libgtk_only(
82                self.to_glib_none().0,
83                application_id.to_glib_none().0,
84                app_menu_path.to_glib_none().0,
85                menubar_path.to_glib_none().0,
86                window_object_path.to_glib_none().0,
87                application_object_path.to_glib_none().0,
88                unique_bus_name.to_glib_none().0,
89            )
90        }
91    }
92
93    #[doc(alias = "gdk_wayland_window_set_transient_for_exported")]
94    pub fn set_transient_for_exported(&self, parent_handle: &str) -> bool {
95        unsafe {
96            from_glib(ffi::gdk_wayland_window_set_transient_for_exported(
97                self.to_glib_none().0,
98                parent_handle.to_glib_none().0,
99            ))
100        }
101    }
102
103    #[cfg(feature = "v3_24_22")]
104    #[cfg_attr(docsrs, doc(cfg(feature = "v3_24_22")))]
105    #[doc(alias = "gdk_wayland_window_set_application_id")]
106    pub fn set_application_id(&self, application_id: &str) -> bool {
107        unsafe {
108            from_glib(ffi::gdk_wayland_window_set_application_id(
109                self.to_glib_none().0,
110                application_id.to_glib_none().0,
111            ))
112        }
113    }
114
115    #[doc(alias = "gdk_wayland_window_announce_csd")]
116    pub fn announce_csd(&self) {
117        unsafe { ffi::gdk_wayland_window_announce_csd(self.to_glib_none().0) }
118    }
119
120    #[cfg(feature = "v3_24")]
121    #[cfg_attr(docsrs, doc(cfg(feature = "v3_24")))]
122    #[doc(alias = "gdk_wayland_window_announce_ssd")]
123    pub fn announce_ssd(&self) {
124        unsafe { ffi::gdk_wayland_window_announce_ssd(self.to_glib_none().0) }
125    }
126}