I'd like to deprecate the x11-dl
crate in favor of safe bindings (keeping x11
available where it's a better fit). I'm undecided on whether low- or high-level safe bindings would be better. By low-level, I mean a safe library that doesn't do much more than speak the X11 protocol (similar to XCB), while a high-level binding would use RAII structs to represent resources. For example:
// Low-level, safe binding
let display = x11::Display::open_default().unwrap();
let window: u32 = display.create_window(..........);
display.map_window(window);
.......... // main loop
display.unmap_window(window);
display.destroy_window(window);
And...
// High-level, safe binding
let display = x11::Display::open_default().unwrap();
let window: x11::Window = display.create_window(..........);
window.map();
.......... // main loop
window.unmap();
I've played around with code that uses the low-level approach of providing a Display
struct that speaks the X protocol alone. It uses XOpenDisplay
to connect to the display but otherwise uses XCB anywhere possible. The prime example of where XCB can't used afaik is when working with GLX contexts, so libX11 can't be eliminated entirely. The bindings would attempt to be neutral to Xlib and XCB but prefer the XCB way of doing things when there is a conflict.
@tomaka The major projects using x11-dl
that I'm aware of are glutin
and winit
, so what do you think? Do you prefer high-level, low-level, or keep x11-dl
the way it is? I'm leaning toward low-level, as high-level would almost result in a winit
-like API but not cross-platform. If I get around to making this new crate, I can update glutin
and winit
to utilize it. However, I'm mostly just brainstorming ideas and this would likely not be any time soon, as I'm busy with school these days.
@francesca64 (replying to your comment in #82)
EDIT: A third alternative that would keep x11-dl
mostly as it is while somewhat preventing problems like #81 would be to either return library structs successfully even with missing symbols returned as null, or to wrap functions in Option
. Both of these would be pretty cumbersome to work with and the bindings would still be unsafe, but this would take the least work to implement.