rust-x-bindings / rust-xcb

Rust bindings and wrapper for XCB.
MIT License
165 stars 64 forks source link

Access xcb_visualtype_t #200

Closed vikigenius closed 2 years ago

vikigenius commented 2 years ago

Cairo XCBVisualType needs pub unsafe fn from_raw_none(ptr: *mut ffi::xcb_visualtype_t) -> XCBVisualType

Previously this library had the following as the VisualType definition

pub struct Visualtype {
    pub base: xcb_visualtype_t,
}

So I could just get the base and unsafe cast

unsafe {
    cairo::XCBVisualType::from_raw_none(
        visual_type.base as *mut xcb::ffi::xcb_visualtype_t as *mut cairo_sys::xcb_visualtype_t,
    )
}

But now the definition of VisualType is

#[derive(Copy, Clone)]
pub struct Visualtype {
    data: [u8; 24],
}

How do I get a cairo::XCBVisualType now ?

rtbo commented 2 years ago

The layout in the data field of Visualtype is compatible with the C layout, so you should be able to cast a pointer or reference to Visualtype to a pointer of cairo_sys::xcb_visualtype_t. Please let me know if that works.

vikigenius commented 2 years ago

Oh thanks a lot, that does seem to work, here is what I ended up with

unsafe {
    cairo::XCBVisualType::from_raw_none(
        visual_type as *mut xcb::x::Visualtype as *mut cairo_sys::xcb_visualtype_t,
    )
}