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::{connect_raw, SignalHandlerId};
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::{ffi, prelude::*, X11Display};
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")]
79 #[doc(alias = "get_xrootwindow")]
80 pub fn xrootwindow(&self) -> XWindow {
81 unsafe { ffi::gdk_x11_display_get_xrootwindow(self.to_glib_none().0) }
82 }
83
84 #[cfg(feature = "xlib")]
90 #[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
91 #[doc(alias = "gdk_x11_display_get_xdisplay")]
92 #[doc(alias = "get_xdisplay")]
93 #[allow(clippy::missing_safety_doc)]
94 pub unsafe fn xdisplay(&self) -> *mut xlib::Display {
95 ffi::gdk_x11_display_get_xdisplay(self.to_glib_none().0) as *mut xlib::Display
96 }
97
98 #[cfg(feature = "xlib")]
104 #[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
105 #[doc(alias = "gdk_x11_display_get_xscreen")]
106 #[doc(alias = "get_xscreen")]
107 #[allow(clippy::missing_safety_doc)]
108 pub unsafe fn xscreen(&self) -> *mut xlib::Screen {
109 ffi::gdk_x11_display_get_xscreen(self.to_glib_none().0) as *mut xlib::Screen
110 }
111
112 #[cfg(feature = "xlib")]
135 #[cfg_attr(docsrs, doc(cfg(feature = "xlib")))]
136 #[doc(alias = "xevent")]
137 #[allow(clippy::missing_safety_doc)]
138 pub unsafe fn connect_xevent<F: Fn(&Self, *mut xlib::XEvent) -> glib::Propagation + 'static>(
139 &self,
140 f: F,
141 ) -> SignalHandlerId {
142 unsafe extern "C" fn xevent_trampoline<
143 F: Fn(&X11Display, *mut xlib::XEvent) -> glib::Propagation + 'static,
144 >(
145 this: *mut ffi::GdkX11Display,
146 xevent: glib::ffi::gpointer,
147 f: glib::ffi::gpointer,
148 ) -> glib::ffi::gboolean {
149 let f: &F = &*(f as *const F);
150 f(&from_glib_borrow(this), xevent as *mut xlib::XEvent).into_glib()
151 }
152 let f: Box_<F> = Box_::new(f);
153 connect_raw(
154 self.as_ptr() as *mut _,
155 c"xevent".as_ptr() as *const _,
156 Some(transmute::<*const (), unsafe extern "C" fn()>(
157 xevent_trampoline::<F> as *const (),
158 )),
159 Box_::into_raw(f),
160 )
161 }
162
163 #[doc(alias = "gdk_x11_display_set_program_class")]
172 pub fn set_program_class(&self, program_class: impl IntoGStr) {
173 assert_initialized_main_thread!();
174 unsafe {
175 program_class.run_with_gstr(|program_class| {
176 ffi::gdk_x11_display_set_program_class(
177 self.upcast_ref::<gdk::Display>().to_glib_none().0,
178 program_class.as_ptr(),
179 );
180 });
181 }
182 }
183}