Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- FAQ Section in README
- x11 crate now supports x11-dl API (library structures) for compatibility.

### Changed

Expand Down
1 change: 1 addition & 0 deletions src/xlib_xcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ x11_link! { Xlib_xcb, xlib_xcb, ["libX11-xcb.so.1", "libX11-xcb.so"], 2,
globals:
}

#[repr(C)]
pub enum XEventQueueOwner {
XlibOwnsEventQueue = 0,
XCBOwnsEventQueue = 1,
Expand Down
8 changes: 4 additions & 4 deletions x11-dl/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ impl DynamicLibrary {
}

impl Drop for DynamicLibrary {
fn drop (&mut self) {
unsafe {
libc::dlclose(self.handle as *mut _);
fn drop(&mut self) {
unsafe {
libc::dlclose(self.handle as *mut _);
}
}
}
}

unsafe impl Send for DynamicLibrary {}
Expand Down
9 changes: 8 additions & 1 deletion x11/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "x11"
version = "2.21.0"
version = "2.21.999"
authors = [
"daggerbot <[email protected]>",
"Erle Pereira <[email protected]>",
Expand Down Expand Up @@ -54,6 +54,13 @@ xtest = ["xtst"]
xtst = []
dox = []

# Enable static linking of X11 dependencies.
static = []

# Disable linking of X11 libraries. Useful to skip build errors in situations
# where this library might be pulled in, but not actually used.
skip-buildrs = []

[dependencies]
libc = "0.2"

Expand Down
6 changes: 6 additions & 0 deletions x11/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ fn main() {
if cfg!(feature = "dox") {
return;
}
if env::var_os("CARGO_FEATURE_SKIP_BUILDRS").is_some() {
return
}

let deps = [
("gl", "1", "glx"),
Expand All @@ -31,12 +34,15 @@ fn main() {
("xxf86vm", "1.1", "xf86vmode"),
];

let statik = env::var_os("CARGO_FEATURE_STATIC").is_some();

for &(dep, version, feature) in deps.iter() {
let var = format!("CARGO_FEATURE_{}", feature.to_uppercase().replace('-', "_"));
if env::var_os(var).is_none() {
continue;
}
pkg_config::Config::new()
.statik(statik)
.atleast_version(version)
.probe(dep)
.unwrap();
Expand Down
33 changes: 33 additions & 0 deletions x11/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! No-op library for API compatibility with dynamically loaded version. The compile-time version
//! will never throw an OpenError.

use std::error::Error;
use std::fmt::{Display, Formatter};

#[derive(Clone, Debug)]
pub struct OpenError;

impl Display for OpenError {
fn fmt(&self, _f: &mut Formatter) -> Result<(), ::std::fmt::Error> {
Ok(())
}
}

impl Error for OpenError {
fn description(&self) -> &str {
"unused"
}
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum OpenErrorKind {
Unused,
}

impl OpenErrorKind {
pub fn as_str(self) -> &'static str {
match self {
OpenErrorKind::Unused => "unused",
}
}
}
2 changes: 2 additions & 0 deletions x11/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

extern crate libc;

pub mod error;

#[macro_use]
mod link;
mod internal;
Expand Down
25 changes: 24 additions & 1 deletion x11/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,31 @@ macro_rules! x11_link {
$(pub fn $vfn_name ($($vparam_name : $vparam_type),+, ...) -> $vret_type;)*
}

extern {
extern "C" {
$(pub static $var_name : $var_type;)*
}

#[allow(unused)]
#[allow(clippy::manual_non_exhaustive)]
pub struct $struct_name {
_private: (),
$(pub $fn_name: unsafe extern "C" fn ($($param_type),*) -> $ret_type,)*
$(pub $vfn_name: unsafe extern "C" fn ($($vparam_type),+, ...) -> $vret_type,)*
$(pub $var_name: *mut $var_type,)*
}

unsafe impl Send for $struct_name {}
unsafe impl Sync for $struct_name {}

impl $struct_name {
pub fn open () -> Result<$struct_name, $crate::error::OpenError> {
Ok($struct_name {
_private: (),
$($fn_name: $fn_name,)*
$($vfn_name: $vfn_name,)*
$($var_name: unsafe { ::std::mem::transmute($var_name) },)*
})
}
}
}
}