-
Notifications
You must be signed in to change notification settings - Fork 567
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
Port X11 backend from xcb to x11rb. #1025
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,14 @@ struct State { | |
|
||
impl Application { | ||
pub fn new() -> Result<Application, Error> { | ||
// If we want to support OpenGL, we will need to open a connection with Xlib support (see | ||
// https://xcb.freedesktop.org/opengl/ for background). There is some sample code for this | ||
// in the `rust-xcb` crate (see `connect_with_xlib_display`), although it may be missing | ||
// something: according to the link below, If you want to handle events through x11rb and | ||
// libxcb, you should call XSetEventQueueOwner(dpy, XCBOwnsEventQueue). Otherwise, libX11 | ||
// might randomly eat your events / move them to its own event queue. | ||
// | ||
// https://github.com/xi-editor/druid/pull/1025/files/76b923417183bd103f61e56b56a56474b7417cec#r442777892 | ||
let (conn, screen_num) = XCBConnection::connect(None)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't really investigated this stuff with either library, but is this an equivalent port? The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To my knowledge Cairo does not use OpenGL by default. There is an experimental feature for it but otherwise it uses the platform library (X11 on Linux). So it should be fine if there is no OpenGL available, unless we want to use it ourselves. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect that we will want OpenGL support eventually. If not for cairo, then for #891-related stuff. But it looks like it will need some work on the x11rb side. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you will want to use the
Congratulations, you now have a single X11 connection which you can access through all of libX11, libxcb and x11rb. API-wise, I do not see anything that could be added to x11rb. The two functions I mentioned above live in Edit: This is also what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the detailed information! I'd prefer not to block this PR on OpenGL support, so I've just dropped in a comment for now. |
||
let connection = Rc::new(conn); | ||
let window_id = Application::create_event_window(&connection, screen_num as i32)?; | ||
|
@@ -96,37 +104,31 @@ impl Application { | |
.ok_or_else(|| anyhow!("invalid screen num: {}", screen_num))?; | ||
|
||
// Create the actual window | ||
if let Some(err) = conn | ||
.create_window( | ||
// Window depth | ||
x11rb::COPY_FROM_PARENT.try_into().unwrap(), | ||
// The new window's ID | ||
id, | ||
// Parent window of this new window | ||
screen.root, | ||
// X-coordinate of the new window | ||
0, | ||
// Y-coordinate of the new window | ||
0, | ||
// Width of the new window | ||
1, | ||
// Height of the new window | ||
1, | ||
// Border width | ||
0, | ||
// Window class type | ||
WindowClass::InputOnly, | ||
// Visual ID | ||
x11rb::COPY_FROM_PARENT, | ||
// Window properties mask | ||
&CreateWindowAux::new().event_mask(EventMask::StructureNotify), | ||
)? | ||
.check()? | ||
{ | ||
// TODO: https://github.com/psychon/x11rb/pull/469 will make error handling easier with | ||
// the next x11rb release. | ||
return Err(x11rb::errors::ReplyError::X11Error(err).into()); | ||
} | ||
conn.create_window( | ||
// Window depth | ||
x11rb::COPY_FROM_PARENT.try_into().unwrap(), | ||
// The new window's ID | ||
id, | ||
// Parent window of this new window | ||
screen.root, | ||
// X-coordinate of the new window | ||
0, | ||
// Y-coordinate of the new window | ||
0, | ||
// Width of the new window | ||
1, | ||
// Height of the new window | ||
1, | ||
// Border width | ||
0, | ||
// Window class type | ||
WindowClass::InputOnly, | ||
// Visual ID | ||
x11rb::COPY_FROM_PARENT, | ||
// Window properties mask | ||
&CreateWindowAux::new().event_mask(EventMask::StructureNotify), | ||
)? | ||
.check()?; | ||
|
||
Ok(id) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link is broken for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed, and I'll merge when CI lets me. Definitely nice to be using a library that is both rusty and actively maintained to the point where the maintainer drops by and tells us what we should be doing better 😄