1#[cfg(feature = "xlib")]
4#[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
5use std::{boxed::Box as Box_, mem::transmute};
6
7#[cfg(feature = "xlib")]
8#[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
9use glib::signal::{SignalHandlerId, connect_raw};
10use glib::translate::*;
11#[cfg(all(feature = "v4_4", feature = "egl"))]
12#[cfg_attr(docsrs, doc(cfg(all(feature = "v4_4", feature = "egl"))))]
13use khronos_egl as egl;
14#[cfg(feature = "xlib")]
15#[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
16use x11::xlib;
17#[cfg(feature = "xlib")]
18#[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
19use x11::xlib::{Cursor as XCursor, Window as XWindow};
20
21use crate::{X11Display, ffi, prelude::*};
22#[cfg(not(feature = "xlib"))]
23use crate::{XCursor, XWindow};
24
25impl X11Display {
26 #[cfg(all(feature = "v4_4", feature = "egl"))]
37 #[cfg_attr(docsrs, doc(cfg(all(feature = "v4_4", feature = "egl"))))]
38 #[doc(alias = "gdk_x11_display_get_egl_display")]
39 #[doc(alias = "get_egl_display")]
40 pub fn egl_display(&self) -> Option<egl::Display> {
41 unsafe {
42 let ptr = ffi::gdk_x11_display_get_egl_display(self.to_glib_none().0);
43 if ptr.is_null() {
44 None
45 } else {
46 Some(egl::Display::from_ptr(ptr))
47 }
48 }
49 }
50
51 #[doc(alias = "gdk_x11_display_get_xcursor")]
68 #[doc(alias = "get_xcursor")]
69 pub fn xcursor(&self, cursor: &gdk::Cursor) -> XCursor {
70 unsafe { ffi::gdk_x11_display_get_xcursor(self.to_glib_none().0, cursor.to_glib_none().0) }
71 }
72
73 #[doc(alias = "gdk_x11_display_get_xrootwindow")]
82 #[doc(alias = "get_xrootwindow")]
83 pub fn xrootwindow(&self) -> XWindow {
84 unsafe { ffi::gdk_x11_display_get_xrootwindow(self.to_glib_none().0) }
85 }
86
87 #[cfg(feature = "xlib")]
96 #[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
97 #[doc(alias = "gdk_x11_display_get_xdisplay")]
98 #[doc(alias = "get_xdisplay")]
99 #[allow(clippy::missing_safety_doc)]
100 pub unsafe fn xdisplay(&self) -> *mut xlib::Display {
101 unsafe { ffi::gdk_x11_display_get_xdisplay(self.to_glib_none().0) as *mut xlib::Display }
102 }
103
104 #[cfg(feature = "xlib")]
113 #[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
114 #[doc(alias = "gdk_x11_display_get_xscreen")]
115 #[doc(alias = "get_xscreen")]
116 #[allow(clippy::missing_safety_doc)]
117 pub unsafe fn xscreen(&self) -> *mut xlib::Screen {
118 unsafe { ffi::gdk_x11_display_get_xscreen(self.to_glib_none().0) as *mut xlib::Screen }
119 }
120
121 #[cfg(feature = "xlib")]
144 #[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
145 #[doc(alias = "xevent")]
146 #[allow(clippy::missing_safety_doc)]
147 pub unsafe fn connect_xevent<F: Fn(&Self, *mut xlib::XEvent) -> glib::Propagation + 'static>(
148 &self,
149 f: F,
150 ) -> SignalHandlerId {
151 unsafe {
152 unsafe extern "C" fn xevent_trampoline<
153 F: Fn(&X11Display, *mut xlib::XEvent) -> glib::Propagation + 'static,
154 >(
155 this: *mut ffi::GdkX11Display,
156 xevent: glib::ffi::gpointer,
157 f: glib::ffi::gpointer,
158 ) -> glib::ffi::gboolean {
159 unsafe {
160 let f: &F = &*(f as *const F);
161 f(&from_glib_borrow(this), xevent as *mut xlib::XEvent).into_glib()
162 }
163 }
164 let f: Box_<F> = Box_::new(f);
165 connect_raw(
166 self.as_ptr() as *mut _,
167 c"xevent".as_ptr() as *const _,
168 Some(transmute::<*const (), unsafe extern "C" fn()>(
169 xevent_trampoline::<F> as *const (),
170 )),
171 Box_::into_raw(f),
172 )
173 }
174 }
175
176 #[doc(alias = "gdk_x11_display_set_program_class")]
188 pub fn set_program_class(&self, program_class: impl IntoGStr) {
189 assert_initialized_main_thread!();
190 unsafe {
191 program_class.run_with_gstr(|program_class| {
192 ffi::gdk_x11_display_set_program_class(
193 self.upcast_ref::<gdk::Display>().to_glib_none().0,
194 program_class.as_ptr(),
195 );
196 });
197 }
198 }
199}