Skip to content

Commit 09df14f

Browse files
gdk4-x11: create type aliases for XID/XWindow/XCursor
if the xlib feature is not used, instead of completely ignoring those functions that returns a XID (which is an alias of ulong) let's provide an alias ourselves in that case and hide it in case the xlib feature is enabled. This should help people using gdk4-x11 use more features without pulling the x11 crate that doesn't add any useful features as is other than wrapping pointers.
1 parent 845424a commit 09df14f

File tree

6 files changed

+39
-46
lines changed

6 files changed

+39
-46
lines changed

gdk4-x11/src/functions.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3-
#[cfg(any(feature = "xlib", feature = "dox"))]
4-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
53
use crate::X11Display;
6-
#[cfg(any(feature = "xlib", feature = "dox"))]
7-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
84
use glib::translate::*;
9-
#[cfg(any(feature = "xlib", feature = "dox"))]
10-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
11-
use x11::xlib;
125

6+
#[cfg(not(feature = "xlib"))]
7+
use crate::XAtom;
138
#[cfg(any(feature = "xlib", feature = "dox"))]
149
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
10+
use x11::xlib::Atom as XAtom;
11+
1512
#[doc(alias = "gdk_x11_get_xatom_by_name_for_display")]
16-
pub fn x11_get_xatom_by_name_for_display(display: &X11Display, atom_name: &str) -> xlib::Atom {
13+
pub fn x11_get_xatom_by_name_for_display(display: &X11Display, atom_name: &str) -> XAtom {
1714
skip_assert_initialized!();
1815
unsafe {
1916
ffi::gdk_x11_get_xatom_by_name_for_display(
@@ -23,13 +20,8 @@ pub fn x11_get_xatom_by_name_for_display(display: &X11Display, atom_name: &str)
2320
}
2421
}
2522

26-
#[cfg(any(feature = "xlib", feature = "dox"))]
27-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
2823
#[doc(alias = "gdk_x11_get_xatom_name_for_display")]
29-
pub fn x11_get_xatom_name_for_display(
30-
display: &X11Display,
31-
xatom: xlib::Atom,
32-
) -> Option<glib::GString> {
24+
pub fn x11_get_xatom_name_for_display(display: &X11Display, xatom: XAtom) -> Option<glib::GString> {
3325
skip_assert_initialized!();
3426
unsafe {
3527
from_glib_none(ffi::gdk_x11_get_xatom_name_for_display(

gdk4-x11/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,12 @@ mod x11_surface;
3232
pub use auto::functions::*;
3333
pub use auto::*;
3434
pub use functions::*;
35+
36+
#[cfg(not(feature = "xlib"))]
37+
pub type XID = libc::c_ulong;
38+
#[cfg(not(feature = "xlib"))]
39+
pub type XWindow = XID;
40+
#[cfg(not(feature = "xlib"))]
41+
pub type XCursor = XID;
42+
#[cfg(not(feature = "xlib"))]
43+
pub type XAtom = XID;

gdk4-x11/src/x11_display.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::X11Display;
44
#[cfg(any(feature = "xlib", feature = "dox"))]
55
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
6-
use glib::{signal::connect_raw, signal::SignalHandlerId, translate::*, ObjectType};
6+
use glib::{signal::connect_raw, signal::SignalHandlerId, ObjectType};
77
#[cfg(any(all(feature = "v4_4", feature = "egl"), feature = "dox"))]
88
#[cfg_attr(feature = "dox", doc(cfg(all(feature = "v4_4", feature = "egl"))))]
99
use khronos_egl as egl;
@@ -17,6 +17,13 @@ use std::mem::transmute;
1717
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
1818
use x11::xlib;
1919

20+
#[cfg(not(feature = "xlib"))]
21+
use crate::{XCursor, XWindow};
22+
use glib::translate::*;
23+
#[cfg(any(feature = "xlib", feature = "dox"))]
24+
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
25+
use x11::xlib::{Cursor as XCursor, Window as XWindow};
26+
2027
impl X11Display {
2128
#[cfg(any(all(feature = "v4_4", feature = "egl"), feature = "dox"))]
2229
#[cfg_attr(feature = "dox", doc(cfg(all(feature = "v4_4", feature = "egl"))))]
@@ -33,19 +40,15 @@ impl X11Display {
3340
}
3441
}
3542

36-
#[cfg(any(feature = "xlib", feature = "dox"))]
37-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
3843
#[doc(alias = "gdk_x11_display_get_xcursor")]
3944
#[doc(alias = "get_xcursor")]
40-
pub fn xcursor(&self, cursor: &gdk::Cursor) -> xlib::Cursor {
45+
pub fn xcursor(&self, cursor: &gdk::Cursor) -> XCursor {
4146
unsafe { ffi::gdk_x11_display_get_xcursor(self.to_glib_none().0, cursor.to_glib_none().0) }
4247
}
4348

44-
#[cfg(any(feature = "xlib", feature = "dox"))]
45-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
4649
#[doc(alias = "gdk_x11_display_get_xrootwindow")]
4750
#[doc(alias = "get_xrootwindow")]
48-
pub fn xrootwindow(&self) -> xlib::Window {
51+
pub fn xrootwindow(&self) -> XWindow {
4952
unsafe { ffi::gdk_x11_display_get_xrootwindow(self.to_glib_none().0) }
5053
}
5154

gdk4-x11/src/x11_monitor.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
use crate::X11Monitor;
4-
#[cfg(any(feature = "xlib", feature = "dox"))]
5-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
4+
#[cfg(not(feature = "xlib"))]
5+
use crate::XID;
66
use glib::translate::*;
77
#[cfg(any(feature = "xlib", feature = "dox"))]
88
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
9-
use x11::xlib;
9+
use x11::xlib::XID;
1010

1111
impl X11Monitor {
12-
#[cfg(any(feature = "xlib", feature = "dox"))]
13-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
1412
#[doc(alias = "gdk_x11_monitor_get_output")]
1513
#[doc(alias = "get_output")]
16-
pub fn output(&self) -> xlib::XID {
14+
pub fn output(&self) -> XID {
1715
unsafe { ffi::gdk_x11_monitor_get_output(self.to_glib_none().0) }
1816
}
1917
}

gdk4-x11/src/x11_screen.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
use crate::X11Screen;
4+
#[cfg(not(feature = "xlib"))]
5+
use crate::XID;
6+
use glib::translate::*;
47
#[cfg(any(feature = "xlib", feature = "dox"))]
58
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
6-
use glib::translate::ToGlibPtr;
7-
#[cfg(any(feature = "xlib", feature = "dox"))]
8-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
9-
use x11::xlib;
9+
use x11::xlib::{self, XID};
1010

1111
impl X11Screen {
1212
#[cfg(any(feature = "xlib", feature = "dox"))]
@@ -17,11 +17,9 @@ impl X11Screen {
1717
ffi::gdk_x11_screen_get_xscreen(self.to_glib_none().0) as *mut xlib::Screen
1818
}
1919

20-
#[cfg(any(feature = "xlib", feature = "dox"))]
21-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
2220
#[doc(alias = "gdk_x11_screen_get_monitor_output")]
2321
#[doc(alias = "get_monitor_output")]
24-
pub fn monitor_output(&self, monitor_num: i32) -> xlib::XID {
22+
pub fn monitor_output(&self, monitor_num: i32) -> XID {
2523
unsafe { ffi::gdk_x11_screen_get_monitor_output(self.to_glib_none().0, monitor_num) }
2624
}
2725
}

gdk4-x11/src/x11_surface.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
use crate::X11Surface;
4-
#[cfg(any(feature = "xlib", feature = "dox"))]
5-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
4+
#[cfg(not(feature = "xlib"))]
5+
use crate::XWindow;
66
use glib::translate::*;
77
#[cfg(any(feature = "xlib", feature = "dox"))]
88
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
9-
use x11::xlib;
9+
use x11::xlib::Window as XWindow;
1010

1111
impl X11Surface {
12-
#[cfg(any(feature = "xlib", feature = "dox"))]
13-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
1412
#[doc(alias = "gdk_x11_surface_get_xid")]
1513
#[doc(alias = "get_xid")]
16-
pub fn xid(&self) -> xlib::Window {
14+
pub fn xid(&self) -> XWindow {
1715
unsafe { ffi::gdk_x11_surface_get_xid(self.to_glib_none().0) }
1816
}
1917

20-
#[cfg(any(feature = "xlib", feature = "dox"))]
21-
#[cfg_attr(feature = "dox", doc(cfg(feature = "xlib")))]
2218
#[doc(alias = "gdk_x11_surface_lookup_for_display")]
23-
pub fn lookup_for_display(
24-
display: &crate::X11Display,
25-
window: xlib::Window,
26-
) -> Option<X11Surface> {
19+
pub fn lookup_for_display(display: &crate::X11Display, window: XWindow) -> Option<X11Surface> {
2720
skip_assert_initialized!();
2821
unsafe {
2922
from_glib_none(ffi::gdk_x11_surface_lookup_for_display(

0 commit comments

Comments
 (0)