-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safe bindings #83
Comments
OpenGL needs the exact pointers returned by the xlib available on the user's machine. |
I don't see what reason there could be for deprecating it. Though, As far as APIs go, I've purposefully been keeping things straightforward, so that anyone reading the code would understand how it maps to Xlib. Here's some code from winit for getting frame extents: let extents_atom = unsafe { self.get_atom_unchecked(b"_NET_FRAME_EXTENTS\0") };
if !hint_is_supported(extents_atom) {
return None;
}
let extents: Option<Vec<c_ulong>> = self.get_property(
window,
extents_atom,
ffi::XA_CARDINAL,
).ok(); (
There are still some design problems, i.e. One thing I've been thinking about is making more things more strongly typed, since while it's nice that it's statically verified that your return type is possible, it's not yet verified that it's correct. Since the vast majority of atoms people use have known meanings, it would be really sweet to be able to do something like this: let extents = self.get_property::<NetFrameExtents>::(window); Using a My API makes it obvious when a function is async, too. I've made a In terms of what belongs in a standalone crate, one thing that's unresolved is whether or not it should include some higher-level utilities. |
Safe bindings specifically for X11 would be a whole lot more work than this project currently covers, and it wouldn't even work for many people's purposes. Closing for now. |
I'd like to deprecate the
x11-dl
crate in favor of safe bindings (keepingx11
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:And...
I've played around with code that uses the low-level approach of providing a
Display
struct that speaks the X protocol alone. It usesXOpenDisplay
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 areglutin
andwinit
, so what do you think? Do you prefer high-level, low-level, or keepx11-dl
the way it is? I'm leaning toward low-level, as high-level would almost result in awinit
-like API but not cross-platform. If I get around to making this new crate, I can updateglutin
andwinit
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 inOption
. 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.The text was updated successfully, but these errors were encountered: