mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 05:42:03 +03:00
fixup probing for SHM support
This commit is contained in:
parent
95cc66e9c0
commit
37541eef96
@ -269,10 +269,7 @@ impl BufferImage {
|
||||
) -> BufferImage {
|
||||
match ShmImage::new(conn, drawable, width, height) {
|
||||
Ok(shm) => BufferImage::Shared(shm),
|
||||
Err(err) => {
|
||||
eprintln!("X server doesn't support shm: {}", err);
|
||||
BufferImage::Image(Image::new(width, height))
|
||||
}
|
||||
Err(err) => BufferImage::Image(Image::new(width, height)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
pub fn get() -> Option<Arc<Self>> {
|
||||
let mut res = None;
|
||||
@ -258,11 +291,7 @@ impl Connection {
|
||||
|
||||
let keysyms = unsafe { xcb_key_symbols_alloc(conn.get_raw_conn()) };
|
||||
|
||||
// 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!
|
||||
let reply = xcb::shm::query_version(&conn).get_reply()?;
|
||||
let shm_available = !reply.ptr.is_null() && reply.shared_pixmaps();
|
||||
let shm_available = server_supports_shm();
|
||||
eprintln!("shm_available: {}", shm_available);
|
||||
|
||||
let conn = Arc::new(Connection {
|
||||
|
Loading…
Reference in New Issue
Block a user