1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 22:01:47 +03:00

fixup probing for SHM support

This commit is contained in:
Wez Furlong 2019-08-09 15:06:12 -07:00
parent 95cc66e9c0
commit 37541eef96
2 changed files with 35 additions and 9 deletions

View File

@ -269,10 +269,7 @@ impl BufferImage {
) -> BufferImage { ) -> BufferImage {
match ShmImage::new(conn, drawable, width, height) { match ShmImage::new(conn, drawable, width, height) {
Ok(shm) => BufferImage::Shared(shm), Ok(shm) => BufferImage::Shared(shm),
Err(err) => { Err(err) => BufferImage::Image(Image::new(width, height)),
eprintln!("X server doesn't support shm: {}", err);
BufferImage::Image(Image::new(width, height))
}
} }
} }
} }

View File

@ -103,6 +103,39 @@ fn window_id_from_event(event: &xcb::GenericEvent) -> Option<xcb::xproto::Window
} }
} }
/// Determine whether the server supports SHM.
/// We can't simply run this on the main connection that we establish
/// as lack of support is reported through the connection getting
/// closed on us! Instead we need to open a separate session to
/// make this check.
fn server_supports_shm() -> bool {
let display = unsafe { x11::xlib::XOpenDisplay(std::ptr::null()) };
if display.is_null() {
return false;
}
let screen_num = unsafe { x11::xlib::XDefaultScreen(display) };
let conn = unsafe { xcb::Connection::from_raw_conn(XGetXCBConnection(display)) };
unsafe { XSetEventQueueOwner(display, 1) };
// Take care here: xcb_shm_query_version can successfully return
// a nullptr, and a subsequent deref will segfault, so we need
// to check the ptr before accessing it!
match xcb::shm::query_version(&conn).get_reply() {
Ok(reply) => {
if let Err(err) = conn.has_error() {
eprintln!("While probing for X SHM support: {}", err);
return false;
}
let shm_available = !reply.ptr.is_null() && reply.shared_pixmaps();
shm_available
}
Err(err) => {
eprintln!("While probing for X SHM support: {}", err);
false
}
}
}
impl Connection { impl Connection {
pub fn get() -> Option<Arc<Self>> { pub fn get() -> Option<Arc<Self>> {
let mut res = None; let mut res = None;
@ -258,11 +291,7 @@ impl Connection {
let keysyms = unsafe { xcb_key_symbols_alloc(conn.get_raw_conn()) }; let keysyms = unsafe { xcb_key_symbols_alloc(conn.get_raw_conn()) };
// Take care here: xcb_shm_query_version can successfully return let shm_available = server_supports_shm();
// a nullptr, and a subsequent deref will segfault, so we need
// to check the ptr before accessing it!
let reply = xcb::shm::query_version(&conn).get_reply()?;
let shm_available = !reply.ptr.is_null() && reply.shared_pixmaps();
eprintln!("shm_available: {}", shm_available); eprintln!("shm_available: {}", shm_available);
let conn = Arc::new(Connection { let conn = Arc::new(Connection {